]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a problem causing the sqlite_master entry corresponding to a virtual table
authordan <dan@noemail.net>
Fri, 28 Dec 2018 17:45:08 +0000 (17:45 +0000)
committerdan <dan@noemail.net>
Fri, 28 Dec 2018 17:45:08 +0000 (17:45 +0000)
to be removed by a DROP TABLE even if the call to the vtabs xDestroy() method
failed.

FossilOrigin-Name: 0140f6dbfbea93eadcd7f727d84064a0c0d1f0806dbe3e5ef1017da603157e3b

manifest
manifest.uuid
src/build.c
src/vdbe.c
src/vdbeaux.c
test/vtabdrop.test [new file with mode: 0644]

index cf79450a19c6a58f2a1552b64a641d40091f18e9..b2229ed6a3d67647d9251e70b38717651c45db33 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Avoid\san\sundefined\sleft-shift\soperation\sin\sfts5\scaused\sby\smalformed\sutf-8\ntext.
-D 2018-12-28T14:33:55.680
+C Fix\sa\sproblem\scausing\sthe\ssqlite_master\sentry\scorresponding\sto\sa\svirtual\stable\nto\sbe\sremoved\sby\sa\sDROP\sTABLE\seven\sif\sthe\scall\sto\sthe\svtabs\sxDestroy()\smethod\nfailed.
+D 2018-12-28T17:45:08.487
 F .fossil-settings/empty-dirs dbb81e8fc0401ac46a1491ab34a7f2c7c0452f2f06b54ebb845d024ca8283ef1
 F .fossil-settings/ignore-glob 35175cdfcf539b2318cb04a9901442804be81cd677d8b889fcc9149c21f239ea
 F Makefile.in d8b254f8bb81bab43c340d70d17dc3babab40fcc8a348c8255881f780a45fee6
@@ -454,7 +454,7 @@ F src/btmutex.c 8acc2f464ee76324bf13310df5692a262b801808984c1b79defb2503bbafadb6
 F src/btree.c 4429a1615440f0253d470b59f955fe84787fd6f709ae114c0a12d132ae725599
 F src/btree.h febb2e817be499570b7a2e32a9bbb4b607a9234f6b84bb9ae84916d4806e96f2
 F src/btreeInt.h 620ab4c7235f43572cf3ac2ac8723cbdf68073be4d29da24897c7b77dda5fd96
-F src/build.c cb86906fcc9150514024d74befa6905bce2323f51518cc5973e4be6a5b00fd16
+F src/build.c 5ca38181e826bcc35e0176c31a691d897ed0cc708fc935fd51e8023705cdcf1a
 F src/callback.c 25dda5e1c2334a367b94a64077b1d06b2553369f616261ca6783c48bcb6bda73
 F src/complete.c a3634ab1e687055cd002e11b8f43eb75c17da23e
 F src/ctime.c 109e58d00f62e8e71ee1eb5944ac18b90171c928ab2e082e058056e1137cc20b
@@ -581,11 +581,11 @@ F src/upsert.c 0dd81b40206841814d46942a7337786932475f085716042d0cb2fc7791bf8ca4
 F src/utf.c 810fbfebe12359f10bc2a011520a6e10879ab2a163bcb26c74768eab82ea62a5
 F src/util.c d9eb0a6c4aae1b00a7369eadd7ca0bbe946cb4c953b6751aa20d357c2f482157
 F src/vacuum.c 3ffe64ecfc94b7528c5d7bdb1c3a19d72fec63f2aa846e3b90f8de5dbbddf5aa
-F src/vdbe.c 1f8e6c71c68631b5c4aaa82b84b262577bd29ca3a14871ed308785ee97ef919d
+F src/vdbe.c 8869a60f4b910c0f6d4ae0f0e23b7a835cae7ed67aa0ce2053d1bbe3e9facc53
 F src/vdbe.h 8990d668a89890a33326b0a29b992c4014b72f3b6cdcd9ee0e190593c247f9b0
 F src/vdbeInt.h 73f5051923f3f29779bfc374c0c68e23b8e5e3792def2e33e51b427edb890abd
 F src/vdbeapi.c 57a2d794a8833f269b878dbc24e955369bdb379af6c4e93ebc5ce1a20fa3daf4
-F src/vdbeaux.c ed00c59d24e2ffef24bddca98640195b14b196f1610eaf580c6ad7cfb73712c0
+F src/vdbeaux.c 0d7b40bc340e831efa8629e8af4bccfe2bdf694aebbb0e4fc6eb554c6f557d26
 F src/vdbeblob.c f5c70f973ea3a9e915d1693278a5f890dc78594300cf4d54e64f2b0917c94191
 F src/vdbemem.c 7b3305bc4a5139f4536ac9b5f61da0f915e49d2e3fdfa87dfdfa9d7aba8bc1e9
 F src/vdbesort.c 90aad5a92608f2dd771c96749beabdb562c9d881131a860a7a5bccf66dc3be7f
@@ -1600,6 +1600,7 @@ F test/vtabJ.test d7b73675708cf63cfcb9d443bb451fc01a028347275b7311e51f9fdf3ca675
 F test/vtab_alter.test 736e66fb5ec7b4fee58229aa3ada2f27ec58bc58c00edae4836890c3784c6783
 F test/vtab_err.test dcc8b7b9cb67522b3fe7a272c73856829dae4ab7fdb30399aea1b6981bda2b65
 F test/vtab_shared.test 5253bff2355a9a3f014c15337da7e177ab0ef8ad
+F test/vtabdrop.test 65d4cf6722972e5499bdaf0c0d70ee3b8133944a4e4bc31862563f32a7edca12
 F test/wal.test cdf0ca6cc0447520d19ef1c83287824ebeb3e82d75af856511ba96841a79fc9b
 F test/wal2.test 155b9efa999bdb38ce1cd729b9a4fcdbffd6b88be27f039bad1d2929d287d918
 F test/wal3.test 2a93004bc0fb2b5c29888964024695bade278ab2
@@ -1794,7 +1795,7 @@ F vsixtest/vsixtest.tcl 6a9a6ab600c25a91a7acc6293828957a386a8a93
 F vsixtest/vsixtest.vcxproj.data 2ed517e100c66dc455b492e1a33350c1b20fbcdc
 F vsixtest/vsixtest.vcxproj.filters 37e51ffedcdb064aad6ff33b6148725226cd608e
 F vsixtest/vsixtest_TemporaryKey.pfx e5b1b036facdb453873e7084e1cae9102ccc67a0
-P a385298df264dbfa6765f63ad8708f74bc8e8a1404239c1049890b39a1bda888
-R 43f56d77c2f0708ff05858147f994e17
+P c3a3a11194586bef80a9d7ca54caae8af30d4e7b464b8bb3d257ba2d2ec4791f
+R c04ce0309200569468b4078d3a3ecf05
 U dan
-Z 557d451f10610db7db7f94619bf74d73
+Z cdcafa722e03713af43caf30559f9961
index 1839ca789f8b1f1d51d8a482f669376b1da30f3d..cf15d7d49acc6f986ed260196c786f6b63cda0d4 100644 (file)
@@ -1 +1 @@
-c3a3a11194586bef80a9d7ca54caae8af30d4e7b464b8bb3d257ba2d2ec4791f
\ No newline at end of file
+0140f6dbfbea93eadcd7f727d84064a0c0d1f0806dbe3e5ef1017da603157e3b
\ No newline at end of file
index e60c1e0b1137937268bb2469fd762ca744f886b5..ab90e12d2499f3e4361367e8a2681b587428298a 100644 (file)
@@ -2638,6 +2638,7 @@ void sqlite3CodeDropTable(Parse *pParse, Table *pTab, int iDb, int isView){
   */
   if( IsVirtual(pTab) ){
     sqlite3VdbeAddOp4(v, OP_VDestroy, iDb, 0, 0, pTab->zName, 0);
+    sqlite3MayAbort(pParse);
   }
   sqlite3VdbeAddOp4(v, OP_DropTable, iDb, 0, 0, pTab->zName, 0);
   sqlite3ChangeCookie(pParse, iDb);
index 590964713c5da90d57835cd79058eba59bbf44d7..26382bcd4dbcddfa2ed09af71ed223eb03c80e1a 100644 (file)
@@ -6849,6 +6849,7 @@ case OP_VDestroy: {
   db->nVDestroy++;
   rc = sqlite3VtabCallDestroy(db, pOp->p1, pOp->p4.z);
   db->nVDestroy--;
+  assert( p->errorAction==OE_Abort && p->usesStmtJournal );
   if( rc ) goto abort_due_to_error;
   break;
 }
index 8d4cf601818356081cb851a11952bb131e6e6a74..dd78c3d31a84206f410c72779f0fbd2e174e7595 100644 (file)
@@ -603,6 +603,7 @@ int sqlite3VdbeAssertMayAbort(Vdbe *v, int mayAbort){
   while( (pOp = opIterNext(&sIter))!=0 ){
     int opcode = pOp->opcode;
     if( opcode==OP_Destroy || opcode==OP_VUpdate || opcode==OP_VRename 
+     || opcode==OP_VDestroy
      || ((opcode==OP_Halt || opcode==OP_HaltIfNull) 
       && ((pOp->p1&0xff)==SQLITE_CONSTRAINT && pOp->p2==OE_Abort))
     ){
diff --git a/test/vtabdrop.test b/test/vtabdrop.test
new file mode 100644 (file)
index 0000000..1f9309e
--- /dev/null
@@ -0,0 +1,127 @@
+# 2018 December 28
+#
+#    May you do good and not evil.
+#    May you find forgiveness for yourself and forgive others.
+#    May you share freely, never taking more than you give.
+#
+#***********************************************************************
+#
+# The tests in this file test edge cases surrounding DROP TABLE on 
+# virtual tables.
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+ifcapable !vtab { finish_test ; return }
+source $testdir/fts3_common.tcl
+source $testdir/malloc_common.tcl
+
+set testprefix vtabdrop
+
+#-------------------------------------------------------------------------
+# Test that if a DROP TABLE is executed against an rtree table, but the
+# xDestroy() call fails, the rtree table is not dropped, the sqlite_master
+# table is not modified and the internal schema remains intact.
+# 
+ifcapable rtree {
+  do_execsql_test 1.0 {
+    CREATE VIRTUAL TABLE rt USING rtree(id, x1, x2);
+    CREATE TABLE t1(x, y);
+    INSERT INTO t1 VALUES(1, 2);
+  }
+  
+  do_test 1.1 {
+    execsql {
+      BEGIN;
+        INSERT INTO t1 VALUES(3, 4);
+    }
+    db eval { SELECT * FROM t1 } {
+      catchsql { DROP TABLE rt }
+    }
+    execsql COMMIT
+  } {}
+  
+  do_execsql_test 1.2 {
+    SELECT name FROM sqlite_master ORDER BY 1;
+    SELECT * FROM t1;
+    SELECT * FROM rt;
+  } {rt rt_node rt_parent rt_rowid t1 1 2 3 4}
+  
+  db close
+  sqlite3 db test.db
+  
+  do_execsql_test 1.3 {
+    SELECT name FROM sqlite_master ORDER BY 1;
+  } {rt rt_node rt_parent rt_rowid t1}
+}
+
+#-------------------------------------------------------------------------
+# Same as tests 1.*, except with fts5 instead of rtree.
+# 
+ifcapable fts5 {
+  reset_db
+  do_execsql_test 2.0 {
+    CREATE VIRTUAL TABLE ft USING fts5(x);
+    CREATE TABLE t1(x, y);
+    INSERT INTO t1 VALUES(1, 2);
+  }
+  
+  do_test 2.1 {
+    execsql {
+      BEGIN;
+        INSERT INTO t1 VALUES(3, 4);
+    }
+    db eval { SELECT * FROM t1 } {
+      catchsql { DROP TABLE ft }
+    }
+    execsql COMMIT
+  } {}
+  
+  do_execsql_test 2.2 {
+    SELECT name FROM sqlite_master ORDER BY 1;
+  } {ft ft_config ft_content ft_data ft_docsize ft_idx t1}
+  
+  db close
+  sqlite3 db test.db
+  
+  do_execsql_test 2.3 {
+    SELECT name FROM sqlite_master ORDER BY 1;
+  } {ft ft_config ft_content ft_data ft_docsize ft_idx t1}
+}
+
+#-------------------------------------------------------------------------
+# Same as tests 1.*, except with fts3 instead of rtree.
+# 
+ifcapable fts3 {
+  reset_db
+  do_execsql_test 2.0 {
+    CREATE VIRTUAL TABLE ft USING fts3(x);
+    CREATE TABLE t1(x, y);
+    INSERT INTO t1 VALUES(1, 2);
+  }
+  
+  do_test 2.1 {
+    execsql {
+      BEGIN;
+        INSERT INTO t1 VALUES(3, 4);
+    }
+    db eval { SELECT * FROM t1 } {
+      catchsql { DROP TABLE ft }
+    }
+    execsql COMMIT
+  } {}
+  
+  do_execsql_test 2.2 {
+    SELECT name FROM sqlite_master ORDER BY 1;
+  } {ft ft_content ft_segdir ft_segments sqlite_autoindex_ft_segdir_1 t1}
+  
+  db close
+  sqlite3 db test.db
+  
+  do_execsql_test 2.3 {
+    SELECT name FROM sqlite_master ORDER BY 1;
+  } {ft ft_content ft_segdir ft_segments sqlite_autoindex_ft_segdir_1 t1}
+}
+
+finish_test