[3.11] gh-64662: Fix virtual table support in sqlite3.Connection.iterdump (#108340) (#108564)

(cherry picked from commit d0160c7c22)

Co-authored-by: Aviv Palivoda <palaviv@gmail.com>
This commit is contained in:
Erlend E. Aasland 2023-08-28 15:09:33 +02:00 committed by GitHub
parent 6f6171b33b
commit 33eee4340e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 35 additions and 7 deletions

View file

@ -16,6 +16,7 @@ def _iterdump(connection):
directly but instead called from the Connection method, iterdump().
"""
writeable_schema = False
cu = connection.cursor()
yield('BEGIN TRANSACTION;')
@ -42,13 +43,15 @@ def _iterdump(connection):
yield('ANALYZE "sqlite_master";')
elif table_name.startswith('sqlite_'):
continue
# NOTE: Virtual table support not implemented
#elif sql.startswith('CREATE VIRTUAL TABLE'):
# qtable = table_name.replace("'", "''")
# yield("INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"\
# "VALUES('table','{0}','{0}',0,'{1}');".format(
# qtable,
# sql.replace("''")))
elif sql.startswith('CREATE VIRTUAL TABLE'):
if not writeable_schema:
writeable_schema = True
yield('PRAGMA writable_schema=ON;')
yield("INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)"
"VALUES('table','{0}','{0}',0,'{1}');".format(
table_name.replace("'", "''"),
sql.replace("'", "''"),
))
else:
yield('{0};'.format(sql))
@ -74,6 +77,9 @@ def _iterdump(connection):
for name, type, sql in schema_res.fetchall():
yield('{0};'.format(sql))
if writeable_schema:
yield('PRAGMA writable_schema=OFF;')
# gh-79009: Yield statements concerning the sqlite_sequence table at the
# end of the transaction.
for row in sqlite_sequence: