diff --git a/web/core/db.py b/web/core/db.py index b7e979c9c..f58e87a23 100755 --- a/web/core/db.py +++ b/web/core/db.py @@ -42,10 +42,9 @@ class Sql(): __debug = False def __init__(self): - self.__DB_FILE = getPanelDir()+'/data/panel.db' + self.__DB_FILE = mw.getPanelDataDir()+'/data/panel.db' - def __getConn(self): - # 取数据库对象 + def __getConnBak(self): try: if self.__DB_CONN == None: self.__DB_CONN = sqlite3.connect(self.__DB_FILE) @@ -54,6 +53,19 @@ class Sql(): print(getTracebackInfo()) return "error: " + str(ex) + def __getConn(self): + # 取数据库对象 + if self.__DB_CONN is None: + db_dir = os.path.dirname(self.__DB_FILE) + if not os.path.exists(db_dir): + os.makedirs(db_dir, exist_ok=True) + try: + self.__DB_CONN = sqlite3.connect(self.__DB_FILE) + self.__DB_CONN.text_factory = str + except Exception as ex: + print(getTracebackInfo()) + raise + def changeTextFactoryToBytes(self): self.__DB_CONN.text_factory = bytes return True