NandHyf 1 год назад
Родитель
Сommit
f08852566d
4 измененных файлов с 68 добавлено и 7 удалено
  1. 13 2
      Stateful.py
  2. BIN
      dev.db
  3. 5 5
      dev_config.toml
  4. 50 0
      sqlite.py

+ 13 - 2
Stateful.py

@@ -65,19 +65,30 @@ def MatchTomlKeys(tomlName, keys, table=None) -> list:
 
 
 # Sqlite3
-def Exist_in_sqlite3():
-    pass
+def Exist_in_sqlite3(tableName, columnName=None, recordName=None):
+    if columnName == None:
+        s = "SELECT name FROM sqlite_master WHERE type='table' AND name='{tableName}';".format(tableName = tableName)
+
+    if columnName != None:
+        s = "SELECT * FROM {tableName} WHERE {columnName}={recordName}".format(tableName = tableName, columnName = columnName, recordName = recordName)
 
 
 def Operate_sqlite3(dbPath, match_commands):
     matchedSyntax = MatchTomlKeys("dev_config.toml", match_commands, "sqlite3")
 
+    # 需要检查的类型
+    # Board, 禁止重复
+    # Class, 重复就update一个引用关系
+    # Event, 同一个Board里面不允许重复, 不同Board里可以重复
+
     s = "".join(matchedSyntax).format(tableName = match_commands[1], objName = match_commands[2])
    
 
     con = sqlite3.connect(dbPath)
     cur = con.cursor()
     
+    # is_exist()
+
     res = cur.execute(s)
     res.fetchone()
     # if res = None:


+ 5 - 5
dev_config.toml

@@ -12,16 +12,16 @@ displayTime = "utc+8"
 "/" = "SELECT name FROM sqlite_master WHERE type='table';"
 select = "SELECT "
 create = "CREATE "
-add = "INSERT INTO "
+add = "INSERT INTO TABLE "
 edit = "UPDATE "
 delete = "UPDATE " # change stauts to "deleted"
 
 # app_command[1]
-board = "TABLE {tableName}({uid}, {objName}, {status})"
-class = "TABLE {tableName}({uid}, {objName}, {used_board}, {status})"
-event = "TABLE {tableName}({uid}, {objName}, {event_dscrp}, {event_creator}, {createdTime}, {class_created}, {ddlTime}, {alertTime}, {currentClass}, {status})"
+board = "TABLE "
+class = "TABLE "
+event = "TABLE "
 # "/" -> " " in Stateful
-stucked = "TABLE {tableName}({uid}, {event_uid}, {stucked_time}, {solved_time})"
+stucked = "TABLE "
 
 # app_command[3] && [4]
 "-d" = ""

+ 50 - 0
sqlite.py

@@ -0,0 +1,50 @@
+import sqlite3
+import Stateful
+
+deType = "sqlite3"
+dbPath = "dev.db"
+
+
+def is_exist(tablePath, name):
+    pass
+
+
+def Operate_sqlite3(dbPath, commands):
+    #                 0       1       2     3      4     5     6
+    # commands e.g.['add', 'board', 'KB4']
+    # 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
+
+
+    con = sqlite3.connect(dbPath)
+    cur = con.cursor()
+    res = cur.execute(sqls)
+    con.commit()
+    print("res: ", res.fetchone())
+
+
+    con.close()
+
+
+if __name__ == "__main__":
+    sy = "CREATE TABLE Board(board_uid, board_name, status)"
+    sy1 = "INSERT INTO Board VALUES('1', 'board1', 'live');"
+    sy2 = "DROP TABLE test;"
+    sy3 = "DROP TABLE Board"
+    sy4 = "CREATE TABLE Board(uid, name, status)"
+    sy5 = "INSERT INTO Board VALUES('1', 'KB1', 'live');"
+
+    sy6 = ['add', 'board', 'KB1']
+
+    while(1):
+        sy_i = input("sql: ")
+        Operate_sqlite3(dbPath, sy_i)