Merge pull request #218 from hzh7/master

add except sqlite3.OperationalEror
This commit is contained in:
SiYuan 2023-12-23 18:03:59 +08:00 committed by GitHub
commit a21e2d657a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -14,19 +14,20 @@ def merge_MediaMSG_databases(source_paths, target_path):
db = sqlite3.connect(source_path)
db.text_factory = str
cursor = db.cursor()
sql = '''
SELECT Key,Reserved0,Buf,Reserved1,Reserved2 FROM Media;
'''
cursor.execute(sql)
result = cursor.fetchall()
# 附加源数据库
try:
sql = '''SELECT Key,Reserved0,Buf,Reserved1,Reserved2 FROM Media;'''
cursor.execute(sql)
result = cursor.fetchall()
target_cursor.executemany(
"INSERT INTO Media (Key,Reserved0,Buf,Reserved1,Reserved2)"
"VALUES(?,?,?,?,?)",
result)
except sqlite3.IntegrityError:
print("有重复key", "跳过")
except sqlite3.OperationalError:
print("no such table: Media", "跳过")
cursor.close()
db.close()
# 提交事务