ソースを参照

最后好像是oc['']的问题...

NandHyf 11 ヶ月 前
コミット
bb1aa401d3
2 ファイル変更47 行追加25 行削除
  1. 14 0
      dev.toml
  2. 33 25
      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()
+'''

+ 33 - 25
kbc_sqlite.py

@@ -71,6 +71,7 @@ class DB():
 
 
 # ----- Operating Cursor -----
+global oc
 oc = {
 "dt":str, # DBType
 "dp":str, # DBPath
@@ -91,38 +92,41 @@ oc = {
 
 
 # ----- Execute Methods -----
-def execute(dbPath):
-    def dec(origin_func):
-        pass
-        def new_exec():
-            con = sqlite3.connect(dbPath)
-            cur = con.cursor()
+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()
 
-            cur.execute(commands)
-            con.commit()
+    res = cur.fetchall()
 
-            # if fetchall == input, return 0?
-            if fetchall == True:
-                re = cur.fetchall()
-                return re
-            
-            cur.close()
-            con.close()    
+    if fetchAll == True:
+        return res
 
+    con.close()
 
-@execute(oc["dp"])
-def exec_one(sqls:str="", fetchall:bool=False):
-    return 
 
+def direct():
+    ss = input("sqls: ")
+    exec_one(ss)
 
-@execute(oc["dp"])
-def exec_many(sqls:dict={}, fetchall:bool=False):
-    pass
 
+def exec_many(dbPath:str=oc["dp"], sqls:dict={}, fetchAll:bool=True):
+    con = sqlite3.connect(dbPath)
+    cur = con.cursor()
+    res = {}
 
-@execute(oc["dp"])
-def direct():
-    pass
+    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):
@@ -148,4 +152,8 @@ def recordExist(dbPath:str, tableName:str, capitalize:bool=False, itemName:str="
 
 # ----- Master process -----
 def master():
-    pass
+    pass
+
+
+if __name__ == "__main__":
+    direct()