Browse Source

忘记给另一个套exception了

nandHyf 11 months ago
parent
commit
235e881c3f
1 changed files with 9 additions and 5 deletions
  1. 9 5
      kbc_sqlite.py

+ 9 - 5
kbc_sqlite.py

@@ -93,13 +93,17 @@ oc = {
 # ----- Execute Methods -----
 def exec(dbPath:str="", sqls:str=""):
     if dbPath != "" and sqls != "":
-        con = sqlite3.connect(dbPath)
-        cur = con.cursor()
+        try:
+            con = sqlite3.connect(dbPath)
+            cur = con.cursor()
 
-        cur.executescript(sqls)
-        con.commit()
+            cur.executescript(sqls)
+            con.commit()
 
-        con.close()
+            con.close()
+            
+        except sqlite3.OperationalError:
+            print(sqlite3.OperationalError.__name__)
 
 
 def exec_fetchall(dbPath:str="", sqls:str="", fetchAll:bool=True):