瀏覽代碼

好耶! 初见雏形
甚至已经可以联动了

nandHyf 11 月之前
父節點
當前提交
600f1f6cdd
共有 3 個文件被更改,包括 42 次插入42 次删除
  1. 12 1
      kbc.py
  2. 3 1
      kbc_alt.py
  3. 27 40
      kbc_sqlite.py

+ 12 - 1
kbc.py

@@ -44,12 +44,23 @@ class kbc_controller():
             # Controller.InputCheck(app_commands)
 
 
+    def direct():
+        sqls = input("direct sqls(ONE SQL STATEMENT ONLY): ")
+        res = kbc_sqlite.exec_fetchall(kbc_sqlite.oc['dp'], sqls)
+        print("res: ", res)
+
+
     # [todo 4]
     def start():
-        global app_config
         app_config = kbc_controller.get_app_config()["app_config"]
 
+        kbc_sqlite.oc['dt'] = app_config['DBType']
+        kbc_sqlite.oc['dp'] = app_config['DBPath']
+
+        kbc_sqlite.oc['cp'] = ['home']
+
 
 if __name__ == "__main__":
     kbc_controller.start()
+    kbc_controller.direct()
     kbc_alt.pause()

+ 3 - 1
kbc_alt.py

@@ -6,11 +6,13 @@
 
 def pause():
     input("pausing, press any key to continue: ")
+    exit()
 
 
 def Err(errCode, lang='en'):
     errText = ""
-    input("err ", errCode, ": ",  errText)
+    print("err ", errCode, ": ",  errText)
+    pause()
     exit()
 
 

+ 27 - 40
kbc_sqlite.py

@@ -71,20 +71,19 @@ class DB():
 
 
 # ----- Operating Cursor -----
-global oc
 oc = {
-"dt":str, # DBType
-"dp":str, # DBPath
+    "dt":"", # DBType
+    "dp":"", # DBPath
 
-"cp":list, # CurrentPath
-"pp":list, # PreviousPath
+    "cp":[], # CurrentPath
+    "pp":[], # PreviousPath
 
-"next_move":str,
+    "next_move":"",
 
-"tp":list, # TargetPath
-"tp_in":list, # ~ after command parameter "in"(&& before command parameter "to")
-"tp_to":list, # ~ after command parameter "to"
-"tp_attr":str # ~ like "-name" in "edit -name oldName to newName"
+    "tp":[], # TargetPath
+    "tp_in":[], # ~ after command parameter "in"(&& before command parameter "to")
+    "tp_to":[], # ~ after command parameter "to"
+    "tp_attr":[] # ~ like "-name" in "edit -name oldName to newName"
 }
 # some thoughts:
 # class oc():
@@ -92,41 +91,29 @@ oc = {
 
 
 # ----- Execute Methods -----
-def exec_one(sqls:str="", dbPath:str="", fetchAll:bool=True):
-    dbPath = oc["dp"]
-    con = sqlite3.connect(dbPath)
-    cur = con.cursor()
-    cur.execute(sqls)
-    con.commit()
-
-    res = cur.fetchall()
-
-    if fetchAll == True:
-        return res
-
-    con.close()
+def exec(dbPath:str="", sqls:str=""):
+    if dbPath != "" and sqls != "":
+        con = sqlite3.connect(dbPath)
+        cur = con.cursor()
 
+        cur.executescript(sqls)
+        con.commit()
 
-def direct():
-    ss = input("sqls: ")
-    exec_one(ss)
+        con.close()
 
 
-def exec_many(dbPath:str=oc["dp"], sqls:dict={}, fetchAll:bool=True):
-    con = sqlite3.connect(dbPath)
-    cur = con.cursor()
-    res = {}
+def exec_fetchall(dbPath:str="", sqls:str="", fetchAll:bool=True):
+    if dbPath != "" and sqls != "":
+        con = sqlite3.connect(dbPath)
+        cur = con.cursor()
 
-    for sql in sqls:
-        cur.executemany(sqls)
+        cur.execute(sqls)
         con.commit()
-        res = cur.fetchall()
-        res.append()
 
-    if fetchAll == True:
-        return res
-    
-    con.close()
+        if fetchAll == True:
+            return cur.fetchall()
+
+        con.close()
 
 
 def recordExist(dbPath:str, tableName:str, capitalize:bool=False, itemName:str="", returnBool:bool=True):
@@ -134,7 +121,7 @@ def recordExist(dbPath:str, tableName:str, capitalize:bool=False, itemName:str="
         tableName = tableName.capitalize()
 
     sqls = "SELECT name FROM {table} WHERE name='{name}';".format(table=tableName, name=itemName)
-    ie = exec_one(sqls)
+    ie = exec(sqls)
 
     if ie != [] and returnBool == False:
         return ie
@@ -156,4 +143,4 @@ def master():
 
 
 if __name__ == "__main__":
-    direct()
+    pass