Browse Source

对add class的after_to做了新的验证

nandHyf 1 year ago
parent
commit
85dd18d7b3
2 changed files with 20 additions and 8 deletions
  1. 1 1
      Controller.py
  2. 19 7
      Stateful.py

+ 1 - 1
Controller.py

@@ -34,7 +34,7 @@ class Client():
     # 前端只检查输入数量正确, 内容正确统一代回后端检查
     def InputCheck(inputs):
         pass
-              
+
 
     def TransitCommand():
         # do while or for (1)

+ 19 - 7
Stateful.py

@@ -155,7 +155,7 @@ class OC():
         return res
 
 
-    def add(self, addType:str="board", addName:str="", after_to:str=""):
+    def add(self, addType:str="board", addName:str="none", after_to:str="none"):
         # Logic see also: /else/addBoardLogic.png
         if addType == "board":
             ie = IsExist("Board", addName)
@@ -174,11 +174,17 @@ class OC():
             if ie == True:
 
                 if after_to != "none":
-                    sqls = "SELECT usingBoard FROM Class WHERE name='{name}';".format(name=addName)
-                    # 'ub' == 'usingBoard'
-                    ub = Exec_one(self.dp, ub)
-                    ub = ub + after_to
-                    sqls = "UPDATE Class SET usingBoard='{usingBoard}' WHERE name='{name}';".format(usingBoard=ub, name=addName)
+                    res = IsExist("Board", after_to)
+                    
+                    if res == True:
+                        sqls = "SELECT usingBoard FROM Class WHERE name='{name}';".format(name=addName)
+                        # 'ub' == 'usingBoard'
+                        ub = Exec_one(self.dp, ub)
+                        ub = ub + after_to
+                        sqls = "UPDATE Class SET usingBoard='{usingBoard}' WHERE name='{name}';".format(usingBoard=ub, name=addName)
+
+                    elif res == False:
+                        print("err <Code>: syntax error")
                 
                 elif after_to == "none":
 
@@ -195,7 +201,13 @@ class OC():
             elif ie == False:
 
                 if after_to != "none":
-                   sqls = "INSERT INTO Class VALUES(null, '{name}', '{usingBoard}', 'alive');".format(name=addName, usingBoard=after_to)
+                    res = IsExist("Board", after_to)
+                    
+                    if res == True:
+                        sqls = "INSERT INTO Class VALUES(null, '{name}', '{usingBoard}', 'alive');".format(name=addName, usingBoard=after_to)
+
+                    elif res == False:
+                        print("err <Code>: syntax error")
                 
                 elif after_to == "none":