Browse Source

又是一天!

NandHyf 1 year ago
parent
commit
9f1c4b4d1a
2 changed files with 26 additions and 14 deletions
  1. 2 0
      init_gen.py
  2. 24 14
      sqlite.py

+ 2 - 0
init_gen.py

@@ -0,0 +1,2 @@
+# used to generate sqlite3 DB && Tables
+import sqlite3

+ 24 - 14
sqlite.py

@@ -5,7 +5,10 @@ deType = "sqlite3"
 dbPath = "dev.db"
 
 
-def is_exist(tablePath, name):
+def is_exist(tableName, columnName):
+    pass
+
+def Secondary_response():
     pass
 
 
@@ -15,22 +18,29 @@ def Operate_sqlite3(dbPath, commands):
     # commands e.g.['add', 'class', 'CL1', 'to', 'KB4']
     # commands e.g.['add', 'event', 'EV1', 'to', 'KB4', '/', 'CL2']
     # commands e.g.['add', 'event', 'EV2', 'to', 'KB4/CL3']
-    
-    matched = []
-    matched = Stateful.MatchTomlKeys(commands)
-    sqls = ""
-
-    # 1. exist check
-
-    # 2. exec command
 
+    v = "SELECT * FROM {tableName} WHERE name={name}".format(tableName=str(commands[1]).capitalize(), name="'"+commands[2]+"'")
+    
+    # sqls = ""
 
     con = sqlite3.connect(dbPath)
     cur = con.cursor()
-    res = cur.execute(sqls)
-    con.commit()
-    print("res: ", res.fetchone())
-
+    # 1. exist check
+    try:
+        res = cur.execute(v)
+        con.commit()
+        print("res: ", res.fetchone() is None)
+
+        # syntax right but not exist:
+        if res.fetchone() is None == True:
+            print("err <Code>: could not found, creat? y/n")
+            # Secondary_response()
+        # 2. exec command
+        matched = Stateful.MatchTomlKeys('dev_config.toml', commands, 'sqlite3')
+        print(matched)
+
+    except:
+        print("err <Code>: Syntax error")
 
     con.close()
 
@@ -46,5 +56,5 @@ if __name__ == "__main__":
     sy6 = ['add', 'board', 'KB1']
 
     while(1):
-        sy_i = input("sql: ")
+        sy_i = input("sql: ").split(" ")
         Operate_sqlite3(dbPath, sy_i)