diff options
author | Erlend E. Aasland <erlend@python.org> | 2023-08-27 22:18:32 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-08-27 22:18:32 (GMT) |
commit | d0160c7c22c8dff0a61c49b5304244df6e36465e (patch) | |
tree | 6604b133b8365249d7a768d133b86ee6c8bdf411 /Lib/sqlite3 | |
parent | fecb9faf0b2df6a219696502a34b918c5d2bfe9d (diff) | |
download | cpython-d0160c7c22c8dff0a61c49b5304244df6e36465e.zip cpython-d0160c7c22c8dff0a61c49b5304244df6e36465e.tar.gz cpython-d0160c7c22c8dff0a61c49b5304244df6e36465e.tar.bz2 |
gh-64662: Add virtual table support to sqlite3.Connection.iterdump (#108340)
Co-authored-by: Aviv Palivoda <palaviv@gmail.com>
Diffstat (limited to 'Lib/sqlite3')
-rw-r--r-- | Lib/sqlite3/dump.py | 20 |
1 files changed, 13 insertions, 7 deletions
diff --git a/Lib/sqlite3/dump.py b/Lib/sqlite3/dump.py index cf73cc3..ead3360 100644 --- a/Lib/sqlite3/dump.py +++ b/Lib/sqlite3/dump.py @@ -24,6 +24,7 @@ def _iterdump(connection): directly but instead called from the Connection method, iterdump(). """ + writeable_schema = False cu = connection.cursor() yield('BEGIN TRANSACTION;') @@ -50,13 +51,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( + _quote_value(table_name), + _quote_value(sql), + )) else: yield('{0};'.format(sql)) @@ -85,6 +88,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: |