|
@@ -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()
|