NandHyf 1 year ago
parent
commit
733819b51c
7 changed files with 76 additions and 19 deletions
  1. 16 10
      Controller.py
  2. 5 4
      Stateful.py
  3. 0 0
      View.py
  4. BIN
      dev.db
  5. 8 5
      dev_config.toml
  6. 29 0
      direct.py
  7. 18 0
      try.txt

+ 16 - 10
Controller.py

@@ -7,9 +7,9 @@ class Client():
 
     def get_config():
         # [todo 4]
-        configs = ['DBType', 'DBPath', 'lang', 'listStyle', 'displayTime']
+        configs = ['DBType', 'DBPath', 'lang', 'listStyle', 'displayTimeZone']
         # rl == 'r'eturn 'l'ist
-        rl = Stateful.matchTomlKeys("config.toml", configs)
+        rl = Stateful.MatchTomlKeys("dev_config.toml", configs)
         
         global lang, listStyle, dbType, dbPath
         dbType = rl[0]
@@ -31,9 +31,10 @@ class Client():
     
 
     # [todo 0]
-    def SyntaxCheck():
+    # 前端只检查输入数量正确, 内容正确统一代回后端检查
+    def InputCheck(inputs):
         pass
-    
+              
 
     def TransitCommand():
         # do while or for (1)
@@ -42,11 +43,16 @@ class Client():
             # Input exception check
             
             # [todo 1]
-            # 直接在这check一下length
-            # Add DBType && Path
-            app_commands.append(dbPath)
-            app_commands.append(dbType)
-            Stateful.PackHandler(app_commands)
+            # Client.InputCheck(app_commands)
+            if len(app_commands) < 5:
+                # Add DBType && Path
+                app_commands.append(dbPath)
+                app_commands.append(dbType)
+                Stateful.PackHandler(app_commands)
+
+            elif len(app_commands) >= 5:
+                print(">5 error")
+                break
 
     # [todo 4]
     def start():
@@ -61,7 +67,7 @@ class Client():
         # ↑↑↑ test code here ↑↑↑
 
         # 2. Normalized Start Process
-        startState = Stateful.TransitHandler(['list', 'board', dbPath, dbType])
+        startState = Stateful.PackHandler(['/', dbPath, dbType])
         print(startState)
         Client.TransitCommand()
 

+ 5 - 4
Stateful.py

@@ -88,12 +88,13 @@ def Operate_sqlite3(dbPath, match_commands):
     cur = con.cursor()
     
     # is_exist()
-
-    res = cur.execute(s)
-    res.fetchone()
+    res = cur.execute(s).fetchall()
+    # ret = res.fetchall()
     # if res = None:
+    
 
     con.close()
+    return res
 
 
 # Markdown
@@ -111,7 +112,7 @@ def PackHandler(app_commands):
     dbPath = app_commands[-2]
 
     if dbType == "sqlite3":
-        Operate_sqlite3(dbPath, app_commands)
+        return Operate_sqlite3(dbPath, app_commands)
 
     elif dbType == "csv":
         pass

+ 0 - 0
View.py


BIN
dev.db


+ 8 - 5
dev_config.toml

@@ -1,6 +1,6 @@
 # ----- App Configuration -----
 DBType = "sqlite3"
-DBPath = "test.db"
+DBPath = "dev.db"
 
 lang = "en"
 listStyle = "tree"
@@ -20,7 +20,7 @@ DDL = ""
 
 [sqlite3]
 # app_command[0]
-"/" = "SELECT name FROM sqlite_master WHERE type='table';"
+"/" = "SELECT name FROM Board;"
 select = "SELECT "
 add = "INSERT INTO "
 edit = "UPDATE "
@@ -28,9 +28,12 @@ delete = "UPDATE " # change stauts to "deleted"
 wipe="DROP WHERE"
 
 # app_command[1]
-board = "({uid}, {name}, {status}).format(uid='', name='', status='live')"
-class = "({uid}, {name}, {usedBoard}, {status})"
-event = "({uid}, {name}, {dscrp}, {createdTime}, {belongBoard}, {classCreated}, {currentClas}, {status})"
+# board = "({uid}, {name}, {status}).format(uid='', name='', status='live')"
+current_board_id = 3
+# class = "({uid}, {name}, {usedBoard}, {status})"
+current_class_id = 0
+# event = "({uid}, {name}, {dscrp}, {createdTime}, {belongBoard}, {classCreated}, {currentClas}, {status})"
+current_event_id = 0
 
 # "/" -> " " in Stateful
 stucked = "Stucked "

+ 29 - 0
direct.py

@@ -0,0 +1,29 @@
+import sqlite3
+
+
+def Operate_sqlite3(dbPath, commands):
+
+    con = sqlite3.connect(dbPath)
+    cur = con.cursor()
+    # 1. exist check
+    try:
+        res = cur.execute(commands)
+        con.commit()
+        print("res.fetchone() is None: ", res.fetchone() is None)
+
+        # syntax right but not exist:
+        if res.fetchone() is None == True:
+            print("err <Code>: could not found, creat? y/n")
+
+
+    except:
+        print("err <Code>: Syntax error")
+
+    con.close()
+
+
+if __name__ == "__main__":
+    while(1):
+        # syi = input("sql: ").split()
+        sy_i = input("sql: ")
+        Operate_sqlite3("dev.db", sy_i)

+ 18 - 0
try.txt

@@ -0,0 +1,18 @@
+Command = ['add', 'board', '<boardName>']
+
+tablePath = Command[2].uper()
+
+is_exist(tablePath, name=None)
+
+if name
+SELECT * FROM {tablePath} WHERE name={name}
+
+
+add event EV1 to KB4/CL2
+add event EV1 to KB4 / CL2
+
+[dev.init]
+CREATE TABLE Board(id INTEGER PRIMARY KEY AUTOINCREMENT, name, status)
+CREATE TABLE Class(id INTEGER PRIMARY KEY AUTOINCREMENT, name, usingBoard, status)
+CREATE TABLE Event(id INTEGER PRIMARY KEY AUTOINCREMENT, name, dscrp, creator, createdTime, classCreated, classCurrent, status)
+CREATE TABLE Stucked(id INTEGER PRIMARY KEY AUTOINCREMENT, boardId, eventId, stuckedTime, solvedTime, status)