From 5e2b5acd9a78c9fe4ad63c7ac58b1105b7cb1126 Mon Sep 17 00:00:00 2001 From: wqy Date: Thu, 1 Sep 2022 22:20:38 +0800 Subject: [PATCH] Add section [TITLE] --- api/_0_base_test.py | 1 - api/_1_title.py | 19 +++++++++++++++++++ api/_1_title_test.py | 12 ++++++++++++ 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 api/_1_title.py create mode 100644 api/_1_title_test.py 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