diff -r 43b1b3c883ff Lib/sqlite3/dump.py --- a/Lib/sqlite3/dump.py Sat Oct 08 16:15:38 2016 +0300 +++ b/Lib/sqlite3/dump.py Mon Oct 10 20:59:00 2016 +0300 @@ -16,6 +16,8 @@ directly but instead called from the Connection method, iterdump(). """ + writeable_schema = False + cu = connection.cursor() yield('BEGIN TRANSACTION;') @@ -35,13 +37,15 @@ 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;') + 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("'", "''"))) else: yield('{0};'.format(sql)) @@ -67,4 +71,7 @@ for name, type, sql in schema_res.fetchall(): yield('{0};'.format(sql)) + if writeable_schema: + yield('PRAGMA writable_schema=OFF;') + yield('COMMIT;') diff -r 43b1b3c883ff Lib/sqlite3/test/dump.py --- a/Lib/sqlite3/test/dump.py Sat Oct 08 16:15:38 2016 +0300 +++ b/Lib/sqlite3/test/dump.py Mon Oct 10 20:59:00 2016 +0300 @@ -70,6 +70,26 @@ got = list(self.cx.iterdump()) self.assertEqual(expected, got) + def CheckVirtualTables(self): + # issue #20463 + expected = [ + "BEGIN TRANSACTION;", + "PRAGMA writable_schema=ON;", + "INSERT INTO sqlite_master(type,name,tbl_name,rootpage,sql)VALUES" \ + "('table','test','test',0,'CREATE VIRTUAL TABLE test using fts4(example)');", + "CREATE TABLE 'test_content'(docid INTEGER PRIMARY KEY, 'c0example');", + "CREATE TABLE 'test_docsize'(docid INTEGER PRIMARY KEY, size BLOB);", + "CREATE TABLE 'test_segdir'(level INTEGER,idx INTEGER,start_block INTEGER," \ + "leaves_end_block INTEGER,end_block INTEGER,root BLOB,PRIMARY KEY(level, idx));", + "CREATE TABLE 'test_segments'(blockid INTEGER PRIMARY KEY, block BLOB);", + "CREATE TABLE 'test_stat'(id INTEGER PRIMARY KEY, value BLOB);", + "PRAGMA writable_schema=OFF;", + "COMMIT;" + ] + self.cu.execute('create virtual table test using fts4(example);') + got = list(self.cx.iterdump()) + self.assertEqual(expected, got) + def suite(): return unittest.TestSuite(unittest.makeSuite(DumpTests, "Check"))