diff --git a/api/_0_base_test.py b/api/_0_base_test.py index c7181f4..0c79cfd 100644 --- a/api/_0_base_test.py +++ b/api/_0_base_test.py @@ -1,4 +1,3 @@ -from fileinput import close from _project import * from _0_base import * diff --git a/api/_1_title.py b/api/_1_title.py new file mode 100644 index 0000000..b6f2ab9 --- /dev/null +++ b/api/_1_title.py @@ -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 diff --git a/api/_1_title_test.py b/api/_1_title_test.py new file mode 100644 index 0000000..51c2011 --- /dev/null +++ b/api/_1_title_test.py @@ -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") \ No newline at end of file