nandHyf пре 11 месеци
родитељ
комит
0f8c4dd17e
3 измењених фајлова са 16 додато и 94 уклоњено
  1. 3 61
      dev.toml
  2. 1 2
      kbc.py
  3. 12 31
      kbc_sqlite.py

+ 3 - 61
dev.toml

@@ -13,20 +13,11 @@ Start_as_LLM_server = false
 
 
 # ----- DB Configuration -----
+# Not recommended to modify the following parameters unless you modify the program synchronously
 # Just a better reference for dev.db, no functional use(yet)
 # ↓ DB name("dev".db)
 #         ↓ Table name
 [dev.compact_main]
-c1_pk = "id INTEGER PRIMARY KEY ASC"
-c2 = "type"
-c3 = "name"
-c4 = "dscrp"
-#     .style = {position : [(x1,y1), (x2, y2), z], bgcolor, radius, border, }
-c5 = "creator"
-c6 = "createdTime"
-c7 = "relatedBoard"
-c8 = "relatedClass"
-c9 = "state"
 createSqls = '''
 CREATE TABLE "compact_main" (
  	"id"	INTEGER NOT NULL,
@@ -41,15 +32,10 @@ CREATE TABLE "compact_main" (
  	PRIMARY KEY("id" AUTOINCREMENT)
 );
 '''
+state.deleted = -10
+state.alive = 10
 
 [dev.log_action]
-c1_pk = "id INTEGER PRIMARY KEY ASC"
-c2 = "uid" # UNIQUE
-c3 = "commitTime"
-c4 = "type"
-c5 = "commitedAction"
-c6 = "operator"
-c7 = "status"
 createSqls = '''
 CREATE TABLE "log_action" (
  	"id"	INTEGER NOT NULL,
@@ -65,50 +51,6 @@ CREATE TABLE "log_action" (
 
 
 # ----- Some Notes -----
-[notes]
-compact_main.type = '''
-0 = Board
-1 = Class
-2 = Event
-'''
-
-compact_main.state = '''
--10 = deleted
-10 = alive
-'''
-
-log_action.status = '''
-
-'''
 
 
 # ----- used sqls -----
-# Set integer prime key: <columnName> INTEGER PRIMARY KEY ASC
-# INSERT INTO compact_main VALUES(null, 'class', 'CL1', 'dscrp', 'n.HE', datetime('now'), 'KB1, KB2', '', 'alive');
-
-# SELECT name FROM compact_main WHERE belongBoard like '%KB1%'
-# SELECT name, dscrp FROM compact_main WHERE dscrp like '%KB1%'
-# SELECT name, dscrp FROM compact_main WHERE dscrp like '%_%KB1%'
-
-# INSERT INTO compact_main VALUES(null, 'class', 'CL2', '_usingBoard:KB1, KB2', 'n.HE', datetime('now'), '', '', 'alive');
-# UPDATE main SET relatedBoard='KB1, KB2' WHERE type='class' AND name='CL2'
-# SELECT name FROM main WHERE type='class' AND relatedBoard like '%KB2%'
-
-# delete class 3 combo:
-# 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()
-'''

+ 1 - 2
kbc.py

@@ -46,7 +46,7 @@ class kbc_controller():
 
     def direct():
         sqls = input("direct sqls(ONE SQL STATEMENT ONLY): ")
-        res = kbc_sqlite.exec_fetchall(kbc_sqlite.oc['dp'], sqls)
+        res = kbc_sqlite.exec(kbc_sqlite.oc['dp'], sqls, True)
         print("res: ", res)
 
 
@@ -64,5 +64,4 @@ class kbc_controller():
 
 if __name__ == "__main__":
     kbc_controller.start()
-    kbc_controller.direct()
     kbc_alt.pause()

+ 12 - 31
kbc_sqlite.py

@@ -3,7 +3,7 @@ import kbc_alt
 
 # ----- Record_main(DB record as a class) -----
 class RM():
-    def __init__(self, type:str="", name:str="", dscrp:str="", creator:str="", createdTime:str="datetime('now')", relatedBoard:str="", relatedClass:str="", state:int=-10) -> None:
+    def __init__(self, type:str="", name:str="", dscrp:str="", creator:str="", createdTime:str="datetime('now')", relatedBoard:str="", relatedClass:str="", statement:int=-10) -> None:
         self.id = "null"
         self.type = type
         self.name = name
@@ -12,39 +12,35 @@ class RM():
         self.createdTime = createdTime
         self.relatedBoard = relatedBoard
         self.relatedClass = relatedClass
-        self.state = state
+        self.statement = statement
 
 
     def select(self, selectColumn:str="name"):
-        return "SELECT {sc} FROM compact_main WHERE type='{s.type}' AND name='{s.name}' AND realatedBoard='{s.relatedBoard}' AND relatedClass='{s.relatedClass}' AND state={s.state};".format(sc=selectColumn, s=self)
+        return "SELECT {sc} FROM compact_main WHERE type={s.type} AND name='{s.name}' AND realatedBoard='{s.relatedBoard}' AND relatedClass='{s.relatedClass}' AND state{s.statement};".format(sc=selectColumn, s=self)
     
 
     def add(self):
-        return "INSERT INTO compact_main VALUES({a.id}, '{a.type}', '{a.name}', '{a.dscrp}', '{a.creator}', '{a.createdTime}', '{a.relatedBoard}', '{a.relatedClass}', {a.state});".format(a=self)
+        return "INSERT INTO compact_main VALUES({a.id}, {a.type}, '{a.name}', '{a.dscrp}', '{a.creator}', '{a.createdTime}', '{a.relatedBoard}', '{a.relatedClass}', {a.statement});".format(a=self)
 
 
-    def delete(self): # 1. withstate:int=10? 2. withStatement >= or > or <?
-        return "UPDATE compact_main SET state=-10 WHERE type='{d.type}' AND name='{d.name}' AND relatedBoard='{d.relatedBoard}' AND relatedClass='{d.relatedClass}' AND state={d.state};".format(d=self)
+    def delete(self): 
+        return "UPDATE compact_main SET state=-10 WHERE type={d.type} AND name='{d.name}' AND relatedBoard='{d.relatedBoard}' AND relatedClass='{d.relatedClass}' AND state{d.statement};".format(d=self)
 
 
     def edit(self, editColumn:str="", editValue:str=""):
-        return "UPDATE compact_main SET {ec}='{ev}' WHERE type='{e.type}' AND name='{e.name}' AND relatedBoard='{e.relatedBoard}' AND relatedClass='{e.relatedClass}' AND state={e.state};".format(ec=editColumn, ev=editValue, e=self)
+        return "UPDATE compact_main SET {ec}='{ev}' WHERE type={e.type} AND name='{e.name}' AND relatedBoard='{e.relatedBoard}' AND relatedClass='{e.relatedClass}' AND state{e.statement};".format(ec=editColumn, ev=editValue, e=self)
     
 
-    def edit_state(self, editValue:int=-10):
-        return "UPDATE compact_main SET state={ev} WHERE type='{e.type}' AND name='{e.name}' AND relatedBoard='{e.relatedBoard}' AND relatedClass='{e.relatedClass}' AND state={e.state};".format(ev=editValue, e=self)
-
-
     def move(self, moveColumn:str="", moveValue:str=""):
-        return "UPDATE compact_main SET {mc}='{mv}' WHERE type='{m.type}' AND name='{m.name}' AND relatedBoard='{m.relatedBoard}' AND relatedClass='{m.relatedClass}' AND state={m.state};".format(mc=moveColumn, mv=moveValue, m=self)
+        return "UPDATE compact_main SET {mc}='{mv}' WHERE type={m.type} AND name='{m.name}' AND relatedBoard='{m.relatedBoard}' AND relatedClass='{m.relatedClass}' AND state{m.statement};".format(mc=moveColumn, mv=moveValue, m=self)
 
 
     def back(self, selectColumn:str="name"):
-        return "SELECT {sc} FROM compact_main WHERE type='{s.type}' AND name='{s.name}' AND realatedBoard='{s.relatedBoard}' AND relatedClass='{s.relatedClass}' AND state={s.state};".format(sc=selectColumn, s=self)
+        return "SELECT {sc} FROM compact_main WHERE type={s.type} AND name='{s.name}' AND realatedBoard='{s.relatedBoard}' AND relatedClass='{s.relatedClass}' AND state{s.statement};".format(sc=selectColumn, s=self)
 
 
     def export(self, selectColumn:str="name"):
-        return "SELECT {sc} FROM compact_main WHERE type='{s.type}' AND name='{s.name}' AND realatedBoard='{s.relatedBoard}' AND relatedClass='{s.relatedClass}' AND state={s.state};".format(sc=selectColumn, s=self)
+        return "SELECT {sc} FROM compact_main WHERE type={s.type} AND name='{s.name}' AND realatedBoard='{s.relatedBoard}' AND relatedClass='{s.relatedClass}' AND state{s.statement};".format(sc=selectColumn, s=self)
     
 
     def get_style():
@@ -78,7 +74,7 @@ oc = {
     "cp":[], # CurrentPath
     "pp":[], # PreviousPath
 
-    "next_move":"",
+    "steps":[],
 
     "tp":[], # TargetPath
     "tp_in":[], # ~ after command parameter "in"(&& before command parameter "to")
@@ -91,22 +87,7 @@ oc = {
 
 
 # ----- Execute Methods -----
-def exec(dbPath:str="", sqls:str=""):
-    if dbPath != "" and sqls != "":
-        try:
-            con = sqlite3.connect(dbPath)
-            cur = con.cursor()
-
-            cur.executescript(sqls)
-            con.commit()
-
-            con.close()
-            
-        except sqlite3.OperationalError:
-            print(sqlite3.OperationalError.__name__)
-
-
-def exec_fetchall(dbPath:str="", sqls:str="", fetchAll:bool=True):
+def exec(dbPath:str="", sqls:str="", fetchAll:bool=False):
     if dbPath != "" and sqls != "":
         try:
             con = sqlite3.connect(dbPath)