mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
gh-79009: sqlite3.iterdump now correctly handles tables with autoincrement (GH-9621)
Co-authored-by: Erlend E. Aasland <erlend.aasland@protonmail.com>
(cherry picked from commit affa9f22cf
)
Co-authored-by: itssme <itssme3000@gmail.com>
This commit is contained in:
parent
b99f398bfb
commit
5abe4cbe88
4 changed files with 62 additions and 1 deletions
|
@ -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;')
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue