summaryrefslogtreecommitdiffstats
path: root/Lib/sqlite3
diff options
context:
space:
mode:
authorErlend E. Aasland <erlend@python.org>2023-08-28 22:25:35 (GMT)
committerGitHub <noreply@github.com>2023-08-28 22:25:35 (GMT)
commitb451e9020df6414e8c51e4e0acd41f855b8742cd (patch)
treebba772e78c769ffa9e599e7bc86f62b707165bfd /Lib/sqlite3
parent5531d03d99c980d29915923e6c93028b4af083b1 (diff)
downloadcpython-b451e9020df6414e8c51e4e0acd41f855b8742cd.zip
cpython-b451e9020df6414e8c51e4e0acd41f855b8742cd.tar.gz
cpython-b451e9020df6414e8c51e4e0acd41f855b8742cd.tar.bz2
[3.12] gh-64662: Fix virtual table support in sqlite3.Connection.iterdump (#108340) (#108563)
* [3.12] gh-64662: Add virtual table support to sqlite3.Connection.iterdump (#108340) (cherry picked from commit d0160c7c22c8dff0a61c49b5304244df6e36465e) Co-authored-by: Aviv Palivoda <palaviv@gmail.com> * The _quote_value helper is not part of 3.12; spell out the replacement * With quotes * Ok, let's use explicit quoting --------- Co-authored-by: Aviv Palivoda <palaviv@gmail.com>
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r--Lib/sqlite3/dump.py20
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/sqlite3/dump.py b/Lib/sqlite3/dump.py
index 07b9da1..1cf8759 100644
--- a/Lib/sqlite3/dump.py
+++ b/Lib/sqlite3/dump.py
@@ -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: