Add section [TITLE]
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
from fileinput import close
|
|
||||||
from _project import *
|
from _project import *
|
||||||
from _0_base import *
|
from _0_base import *
|
||||||
|
|
||||||
|
|||||||
19
api/_1_title.py
Normal file
19
api/_1_title.py
Normal 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
12
api/_1_title_test.py
Normal 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")
|
||||||
Reference in New Issue
Block a user