2 Komitmen 7e6f2bf979 ... bb1aa401d3

Pembuat SHA1 Pesan Tanggal
  NandHyf bb1aa401d3 最后好像是oc['']的问题... 11 bulan lalu
  NandHyf 91be9b8c8b 谁来教教我怎么写装饰器啊啊啊啊啊 11 bulan lalu
4 mengubah file dengan 61 tambahan dan 44 penghapusan
  1. 14 0
      dev.toml
  2. 8 15
      kbc.py
  3. 5 0
      kbc_alt.py
  4. 34 29
      kbc_sqlite.py

+ 14 - 0
dev.toml

@@ -98,3 +98,17 @@ log_action.status = '''
 # UPDATE compact_main SET relatedBoard = replace(relatedBoard, 'KB2, ', '')  WHERE type='class' AND relatedBoard like '%KB2, %';
 # UPDATE compact_main SET relatedBoard = replace(relatedBoard, ', KB2', '')  WHERE type='class' AND relatedBoard like '%, KB2%';
 # UPDATE compact_main SET relatedBoard = replace(relatedBoard, 'KB2', '')  WHERE type='class' AND relatedBoard like '%KB2%';
+a ='''
+sqls = str(func)
+con = sqlite3.connect(dbPath)
+cur = con.cursor()
+cur.execute(sqls)
+con.commit()
+
+res = cur.fetchall()
+
+if fetchAll == True:
+    return res
+
+con.close()
+'''

+ 8 - 15
kbc.py

@@ -9,11 +9,9 @@ import datetime
 class kbc_controller():
     def get_app_config(returnDict:bool=True):
         tomls = kbc_toml.MatchTomlTable("dev.toml", "app_config", "dict")
-        global app_config
-        app_config = tomls["app_config"]
 
         if returnDict == True:
-            return app_config
+            return tomls
         
 
     def get_help():
@@ -24,12 +22,11 @@ class kbc_controller():
 
 
     # [todo 4]
-    def display_in_timezone():
+    def display_in_timezone(timezone:int=0):
         pass
     
 
     # [todo 2]
-    # 前端只检查输入数量正确, 内容正确统一代回后端检查
     def validCheck():
         pass
 
@@ -39,9 +36,8 @@ class kbc_controller():
 
 
     def transitCommand():
-        # do while or for (1)
-        while(1):
-            app_commands = input(currentPath + "/: ", ).split(" ")
+        while(True):
+            pass
             # Input exception check
             
             # [todo 1]
@@ -50,13 +46,10 @@ class kbc_controller():
 
     # [todo 4]
     def start():
-        pass
-
-        # 2. Valid DB
-        # startState = Stateful.Translator(['/', app_config["dbPath"], app_config["dbType"]])
-        # print(startState)
-        # kbc_controller.TransitCommand()
+        global app_config
+        app_config = kbc_controller.get_app_config()["app_config"]
 
 
 if __name__ == "__main__":
-    kbc_controller.start()   
+    kbc_controller.start()
+    kbc_alt.pause()

+ 5 - 0
kbc_alt.py

@@ -3,6 +3,11 @@
 # err 1: correct DB not found
 # -----
 
+
+def pause():
+    input("pausing, press any key to continue: ")
+
+
 def Err(errCode, lang='en'):
     errText = ""
     input("err ", errCode, ": ",  errText)

+ 34 - 29
kbc_sqlite.py

@@ -70,11 +70,8 @@ class DB():
         pass
 
 
-def direct():
-    pass
-
-
 # ----- Operating Cursor -----
+global oc
 oc = {
 "dt":str, # DBType
 "dp":str, # DBPath
@@ -91,49 +88,53 @@ oc = {
 }
 # some thoughts:
 # class oc():
-#   def get_oc(), def move_oc()
+#   def read_oc(), def move_oc()
 
 
 # ----- Execute Methods -----
-def execute(dbPath):
-    def dec(origin_func):
-        pass
-
+def exec_one(sqls:str="", dbPath:str="", fetchAll:bool=True):
+    dbPath = oc["dp"]
     con = sqlite3.connect(dbPath)
     cur = con.cursor()
-
-    cur.execute(commands)
+    cur.execute(sqls)
     con.commit()
 
-    # if fetchall == input, return 0?
-    if fetchall == True:
-        re = cur.fetchall()
-        return re
-    
-    cur.close()
+    res = cur.fetchall()
+
+    if fetchAll == True:
+        return res
+
     con.close()
-    def dec():
-        pass
 
 
-@execute(oc["dp"])
-def exec_one(dbPath:str, commands:list, fetchall:bool=False):
-    pass
+def direct():
+    ss = input("sqls: ")
+    exec_one(ss)
 
 
-@execute(oc["dp"])
-def exec_many():
-    pass
+def exec_many(dbPath:str=oc["dp"], sqls:dict={}, fetchAll:bool=True):
+    con = sqlite3.connect(dbPath)
+    cur = con.cursor()
+    res = {}
+
+    for sql in sqls:
+        cur.executemany(sqls)
+        con.commit()
+        res = cur.fetchall()
+        res.append()
+
+    if fetchAll == True:
+        return res
+    
+    con.close()
 
 
 def recordExist(dbPath:str, tableName:str, capitalize:bool=False, itemName:str="", returnBool:bool=True):
-    # [todo 4] 这里面.capitalize()后面需要根据config.toml里面的内容判断
-    # 可能也不用, 因为KBCLEV的表名和本身并无关系
     if capitalize == True:
         tableName = tableName.capitalize()
 
     sqls = "SELECT name FROM {table} WHERE name='{name}';".format(table=tableName, name=itemName)
-    ie = exec_one(dbPath, sqls)
+    ie = exec_one(sqls)
 
     if ie != [] and returnBool == False:
         return ie
@@ -151,4 +152,8 @@ def recordExist(dbPath:str, tableName:str, capitalize:bool=False, itemName:str="
 
 # ----- Master process -----
 def master():
-    pass
+    pass
+
+
+if __name__ == "__main__":
+    direct()