Add section [TITLE]

This commit is contained in:
wqy
2022-09-01 22:20:38 +08:00
parent c42d705232
commit 5e2b5acd9a
3 changed files with 31 additions and 1 deletions

View File

@@ -1,4 +1,3 @@
from fileinput import close
from _project import *
from _0_base import *

19
api/_1_title.py Normal file
View File

@@ -0,0 +1,19 @@
from _connection import _conn_dict as conn
def have_title(name: str) -> bool:
with conn[name].cursor() as cur:
cur.execute(f"SELECT * FROM TITLE")
return cur.rowcount > 0
def set_title(name: str, value: str) -> None:
if have_title(name):
with conn[name].cursor() as cur:
cur.execute(f"UPDATE TITLE SET Value = {value}")
else:
with conn[name].cursor() as cur:
cur.execute(f"INSERT INTO TITLE (Value) VALUES ('{value}')")
def unset_title(name: str) -> None:
with conn[name].cursor() as cur:
cur.execute(f"TRUNCATE TITLE")
return cur.rowcount > 0

12
api/_1_title_test.py Normal file
View File

@@ -0,0 +1,12 @@
from _project import *
from _1_title import *
open_project("net")
print(have_title("net"))
set_title("net", "xxx")
print(have_title("net"))
unset_title("net")
print(have_title("net"))
close_project("net")