Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Clean up dump.py
- consolidate construction of sqlite_sequence
- use existing quoting style
  • Loading branch information
erlend-aasland authored Jun 19, 2022
commit 1abc7d05b7a605224611a09eaa74e50ef1cc38e1
18 changes: 10 additions & 8 deletions Lib/sqlite3/dump.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,13 @@ def _iterdump(connection):
schema_res = cu.execute(q)
sqlite_sequence = []
for table_name, type, sql in schema_res.fetchall():
if table_name == "sqlite_sequence":
sqlite_sequence = ["DELETE FROM \"sqlite_sequence\""]
rows = cu.execute("SELECT * FROM \"sqlite_sequence\";").fetchall()
sqlite_sequence.extend(["INSERT INTO \"sqlite_sequence\" VALUES('{0}',{1})"
.format(row[0], row[1]) for row in rows])
continue
if table_name == '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
]
elif table_name == 'sqlite_stat1':
yield('ANALYZE "sqlite_master";')
elif table_name.startswith('sqlite_'):
Expand Down Expand Up @@ -72,8 +73,9 @@ def _iterdump(connection):
for name, type, sql in schema_res.fetchall():
yield('{0};'.format(sql))

# Yield statements concerning the sqlite_sequence table at the end of the transaction: (bpo-34828)
# 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('{0};'.format(row))

yield('COMMIT;')