From 5f8bbf448958e5ffdf15226f1bd44515ef81b136 Mon Sep 17 00:00:00 2001 From: cxl Date: Mon, 18 Dec 2023 16:10:15 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=9F=90=E4=BA=9B=E8=A1=A8?= =?UTF-8?q?=E6=89=BE=E4=B8=8D=E5=88=B0=E5=AF=BC=E8=87=B4=E6=89=93=E4=B8=8D?= =?UTF-8?q?=E5=BC=80=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/DataBase/merge.py | 21 +++++++++++++++++++++ app/DataBase/misc.py | 8 +++++++- 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/app/DataBase/merge.py b/app/DataBase/merge.py index 05d51ac..b5bb4f3 100644 --- a/app/DataBase/merge.py +++ b/app/DataBase/merge.py @@ -5,6 +5,9 @@ def merge_MediaMSG_databases(source_paths, target_path): # 创建目标数据库连接 target_conn = sqlite3.connect(target_path) target_cursor = target_conn.cursor() + + table_name = "Media" + try: # 开始事务 target_conn.execute("BEGIN;") @@ -14,11 +17,22 @@ def merge_MediaMSG_databases(source_paths, target_path): db = sqlite3.connect(source_path) db.text_factory = str cursor = db.cursor() + + # 检查Media表是否存在 + cursor.execute(f"SELECT name FROM sqlite_master WHERE type='table' AND name='{table_name}'") + result = cursor.fetchone() + if not result: + continue + sql = ''' SELECT Key,Reserved0,Buf,Reserved1,Reserved2 FROM Media; ''' cursor.execute(sql) result = cursor.fetchall() + + # 创建目标表 + target_cursor.execute(f"CREATE TABLE IF NOT EXISTS {table_name} (Key, Reserved0, Buf, Reserved1, Reserved2);") + # 附加源数据库 try: target_cursor.executemany( @@ -54,6 +68,13 @@ def merge_databases(source_paths, target_path): db = sqlite3.connect(source_path) db.text_factory = str cursor = db.cursor() + + # 检查MSG表是否存在 + cursor.execute(f"SELECT name FROM sqlite_master WHERE type='table' AND name='MSG'") + result = cursor.fetchone() + if not result: + continue + sql = ''' SELECT TalkerId,MsgsvrID,Type,SubType,IsSender,CreateTime,Sequence,StrTalker,StrContent,DisplayContent,BytesExtra,CompressContent FROM MSG; diff --git a/app/DataBase/misc.py b/app/DataBase/misc.py index c746247..48fc1f8 100644 --- a/app/DataBase/misc.py +++ b/app/DataBase/misc.py @@ -36,7 +36,13 @@ class Misc: self.DB = sqlite3.connect(db_path, check_same_thread=False) # '''创建游标''' self.cursor = self.DB.cursor() - self.open_flag = True + + # 检查Media表是否存在 + self.cursor.execute(f"SELECT name FROM sqlite_master WHERE type='table' AND name='smallHeadBuf'") + result = self.cursor.fetchone() + if result: + self.open_flag = True + if lock.locked(): lock.release()