Skip to content

Commit

Permalink
Clean up dump.py
Browse files Browse the repository at this point in the history
- consolidate construction of sqlite_sequence
- use existing quoting style
  • Loading branch information
erlend-aasland authored Jun 19, 2022
1 parent 64f4101 commit 1abc7d0
Showing 1 changed file with 10 additions and 8 deletions.
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;')

0 comments on commit 1abc7d0

Please sign in to comment.