summaryrefslogtreecommitdiffstats
path: root/Lib/sqlite3/dump.py
diff options
context:
space:
mode:
authoritssme <itssme3000@gmail.com>2022-06-19 22:59:24 (GMT)
committerGitHub <noreply@github.com>2022-06-19 22:59:24 (GMT)
commitaffa9f22cfd1e83a5fb413e5ce2feef9ea1a49ac (patch)
treea29ea21468987f87d8dd79f25b59d501df62e10f /Lib/sqlite3/dump.py
parent8e0897814109765a9e463676413fff016875217b (diff)
downloadcpython-affa9f22cfd1e83a5fb413e5ce2feef9ea1a49ac.zip
cpython-affa9f22cfd1e83a5fb413e5ce2feef9ea1a49ac.tar.gz
cpython-affa9f22cfd1e83a5fb413e5ce2feef9ea1a49ac.tar.bz2
gh-79009: sqlite3.iterdump now correctly handles tables with autoincrement (#9621)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
Diffstat (limited to 'Lib/sqlite3/dump.py')
-rw-r--r--Lib/sqlite3/dump.py14
1 files changed, 13 insertions, 1 deletions
diff --git a/Lib/sqlite3/dump.py b/Lib/sqlite3/dump.py
index de9c368..07b9da1 100644
--- a/Lib/sqlite3/dump.py
+++ b/Lib/sqlite3/dump.py
@@ -28,9 +28,16 @@ def _iterdump(connection):
ORDER BY "name"
"""
schema_res = cu.execute(q)
+ sqlite_sequence = []
for table_name, type, sql in schema_res.fetchall():
if table_name == 'sqlite_sequence':
- yield('DELETE FROM "sqlite_sequence";')
+ rows = cu.execute('SELECT * FROM "sqlite_sequence";').fetchall()
+ sqlite_sequence = ['DELETE FROM "sqlite_sequence"']
+ sqlite_sequence += [
+ f'INSERT INTO "sqlite_sequence" VALUES(\'{row[0]}\',{row[1]})'
+ for row in rows
+ ]
+ continue
elif table_name == 'sqlite_stat1':
yield('ANALYZE "sqlite_master";')
elif table_name.startswith('sqlite_'):
@@ -67,4 +74,9 @@ def _iterdump(connection):
for name, type, sql in schema_res.fetchall():
yield('{0};'.format(sql))
+ # gh-79009: Yield statements concerning the sqlite_sequence table at the
+ # end of the transaction.
+ for row in sqlite_sequence:
+ yield('{0};'.format(row))
+
yield('COMMIT;')