|
@@ -1,9 +1,9 @@
|
|
|
-import Alt, WithSqlite
|
|
|
-import tomlkit
|
|
|
+import Alt
|
|
|
+import tomlkit, sqlite3
|
|
|
|
|
|
# uid related
|
|
|
|
|
|
-# Toml Methods
|
|
|
+# ----- Toml Methods -----
|
|
|
def GetTomlDoc(tomlName):
|
|
|
try:
|
|
|
with open(tomlName, "rb") as t:
|
|
@@ -59,47 +59,51 @@ def MatchTomlKeys(tomlName, keys, table=None) -> list:
|
|
|
pass
|
|
|
|
|
|
return rl
|
|
|
+
|
|
|
|
|
|
+# ----- Sqlite -----
|
|
|
+def Exec_one(dbPath, commands):
|
|
|
+ con = sqlite3.connect(dbPath)
|
|
|
+ cur = con.cursor()
|
|
|
|
|
|
-# ----- Transit Command Handler -----
|
|
|
-def Handler(app_commands):
|
|
|
- dbType = app_commands[-1]
|
|
|
- dbPath = app_commands[-2]
|
|
|
- # [todo 3] 检查dbPath是否对应dbType, 否的话报错并exit()
|
|
|
-
|
|
|
- exec_commands = app_commands[0:-2]
|
|
|
+ cur.execute(commands)
|
|
|
+ con.commit()
|
|
|
+ re = cur.fetchall()
|
|
|
+ con.close()
|
|
|
|
|
|
- if dbType == "sqlite3":
|
|
|
- WithSqlite.Regular(dbPath, exec_commands)
|
|
|
+ return re
|
|
|
|
|
|
|
|
|
- elif dbType == "csv":
|
|
|
- pass
|
|
|
+def IsExist(exec_commands, returnBool=True):
|
|
|
+ tableName = str(exec_commands[1]).capitalize()
|
|
|
|
|
|
- elif dbType == "mongodb":
|
|
|
- pass
|
|
|
+ ItemName = str(exec_commands[2])
|
|
|
|
|
|
- elif dbType == "toml":
|
|
|
- pass
|
|
|
+ sqls = "SELECT name FROM {table} WHERE name='{name}'".format(table=tableName, name=ItemName)
|
|
|
+ ie = Exec_one(dbPath, sqls)
|
|
|
|
|
|
- elif dbType == "md":
|
|
|
- pass
|
|
|
+ if ie != [] and returnBool == False:
|
|
|
+ return ie
|
|
|
+
|
|
|
+ elif ie != [] and returnBool == True:
|
|
|
+ return True
|
|
|
|
|
|
+ elif ie == []:
|
|
|
+ return False
|
|
|
+
|
|
|
else:
|
|
|
- input("error 1: could not found correct Data Base")
|
|
|
- exit()
|
|
|
-
|
|
|
+ # Alt.Err(errCode)
|
|
|
+ print("err <Code>: unexpected error in existence check")
|
|
|
|
|
|
-# ----- Docker related -----
|
|
|
|
|
|
+class command():
|
|
|
+ pass
|
|
|
|
|
|
+class objBoard():
|
|
|
+ pass
|
|
|
|
|
|
-if __name__ == "__main__":
|
|
|
-
|
|
|
- a_c = ['/', 'test.db', 'sqlite3']
|
|
|
- a_c1 = ['add', 'board', 'testBoardName', 'test.db', 'sqlite3']
|
|
|
- a_c2 = ['edit', 'board', 't_boardName', 'to', 't_newBoardName', 'test.db', 'sqlite3']
|
|
|
- e_c = ['add', 'board']
|
|
|
+class objClass():
|
|
|
+ pass
|
|
|
|
|
|
- # Operate_sqlite3("test.db", a_c1)
|
|
|
- Handler(a_c2)
|
|
|
+class objEvent():
|
|
|
+ pass
|