mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Minor fixes
This commit is contained in:
parent
8ac82e6b47
commit
d05935ea2a
@ -94,21 +94,21 @@ def reinit_db_new(dbpath, callback=None, sql_dump=None):
|
|||||||
callback = lambda x, y: None
|
callback = lambda x, y: None
|
||||||
|
|
||||||
with closing(Connection(dbpath)) as conn:
|
with closing(Connection(dbpath)) as conn:
|
||||||
uv = conn.get('PRAGMA user_version;', all=False)
|
uv = int(conn.get('PRAGMA user_version;', all=False))
|
||||||
if sql_dump is None:
|
if sql_dump is None:
|
||||||
buf = StringIO()
|
buf = StringIO()
|
||||||
shell = apsw.Shell(db=conn, stdout=buf)
|
shell = apsw.Shell(db=conn, stdout=buf)
|
||||||
shell.process_command('.dump')
|
shell.process_command('.dump')
|
||||||
sql = buf.getvalue().encode('utf-8')
|
sql = buf.getvalue()
|
||||||
else:
|
else:
|
||||||
sql = open(sql_dump, 'rb').read()
|
sql = open(sql_dump, 'rb').read().decode('utf-8')
|
||||||
|
|
||||||
dest = dbpath + '.tmp'
|
dest = dbpath + '.tmp'
|
||||||
callback(1, True)
|
callback(1, True)
|
||||||
try:
|
try:
|
||||||
with closing(Connection(dest)) as conn:
|
with closing(Connection(dest)) as conn:
|
||||||
conn.execute(sql)
|
conn.execute(sql)
|
||||||
conn.execute('PRAGMA User_version=%d;'%int(uv))
|
conn.execute('PRAGMA user_version=%d;'%int(uv))
|
||||||
os.remove(dbpath)
|
os.remove(dbpath)
|
||||||
shutil.copyfile(dest, dbpath)
|
shutil.copyfile(dest, dbpath)
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user