]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Fix a faulty assert() statement. Add comments to clarify the behavior of
authordrh <drh@noemail.net>
Thu, 21 Aug 2014 14:10:23 +0000 (14:10 +0000)
committerdrh <drh@noemail.net>
Thu, 21 Aug 2014 14:10:23 +0000 (14:10 +0000)
the sqlite3OpenTableAndIndices() routine in insert.c.  Add test cases to
verify that the assert() statement is not firing inappropriately.
Ticket [369d57fb8e5ccdff06f1].

FossilOrigin-Name: 7029b3404d3f5f698a496934f3a3f2972051b257

ext/rtree/rtreeF.test [new file with mode: 0644]
manifest
manifest.uuid
src/delete.c
src/insert.c

diff --git a/ext/rtree/rtreeF.test b/ext/rtree/rtreeF.test
new file mode 100644 (file)
index 0000000..c9620d3
--- /dev/null
@@ -0,0 +1,81 @@
+# 2014-08-21
+#
+# The author disclaims copyright to this source code.  In place of
+# a legal notice, here is a blessing:
+#
+#    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.
+#
+#***********************************************************************
+# This file contains tests for the r-tree module.
+#
+# This file contains test cases for the ticket
+# [369d57fb8e5ccdff06f197a37147a88f9de95cda] (2014-08-21)
+#
+#  The following SQL causes an assertion fault while running
+#  sqlite3_prepare() on the DELETE statement:
+#
+#     CREATE TABLE t1(x);
+#     CREATE TABLE t2(y);
+#     CREATE VIRTUAL TABLE t3 USING rtree(a,b,c);
+#     CREATE TRIGGER t2del AFTER DELETE ON t2 WHEN (SELECT 1 from t1) BEGIN 
+#       DELETE FROM t3 WHERE a=old.y; 
+#     END;
+#     DELETE FROM t2 WHERE y=1;
+# 
+
+if {![info exists testdir]} {
+  set testdir [file join [file dirname [info script]] .. .. test]
+} 
+source $testdir/tester.tcl
+ifcapable !rtree { finish_test ; return }
+
+do_execsql_test rtreeF-1.1 {
+  CREATE TABLE t1(x);
+  CREATE TABLE t2(y);
+  CREATE VIRTUAL TABLE t3 USING rtree(a,b,c);
+  CREATE TRIGGER t2dwl AFTER DELETE ON t2 WHEN (SELECT 1 from t1) BEGIN 
+    DELETE FROM t3 WHERE a=old.y; 
+  END;
+
+  INSERT INTO t1(x) VALUES(999);
+  INSERT INTO t2(y) VALUES(1),(2),(3),(4),(5);
+  INSERT INTO t3(a,b,c) VALUES(1,2,3),(2,3,4),(3,4,5),(4,5,6),(5,6,7);
+
+  SELECT a FROM t3 ORDER BY a;
+  SELECT '|';
+  SELECT y FROM t2 ORDER BY y;
+} {1 2 3 4 5 | 1 2 3 4 5}
+do_execsql_test rtreeF-1.2 {
+  DELETE FROM t2 WHERE y=3;
+
+  SELECT a FROM t3 ORDER BY a;
+  SELECT '|';
+  SELECT y FROM t2 ORDER BY y;
+} {1 2 4 5 | 1 2 4 5}
+do_execsql_test rtreeF-1.3 {
+  DELETE FROM t1;
+  DELETE FROM t2 WHERE y=5;
+
+  SELECT a FROM t3 ORDER BY a;
+  SELECT '|';
+  SELECT y FROM t2 ORDER BY y;
+} {1 2 4 5 | 1 2 4}
+do_execsql_test rtreeF-1.4 {
+  INSERT INTO t1 DEFAULT VALUES;
+  DELETE FROM t2 WHERE y=5;
+
+  SELECT a FROM t3 ORDER BY a;
+  SELECT '|';
+  SELECT y FROM t2 ORDER BY y;
+} {1 2 4 5 | 1 2 4}
+do_execsql_test rtreeF-1.5 {
+  DELETE FROM t2 WHERE y=2;
+
+  SELECT a FROM t3 ORDER BY a;
+  SELECT '|';
+  SELECT y FROM t2 ORDER BY y;
+} {1 4 5 | 1 4}
+
+finish_test
index 292e662207f443886d020d35f245c594eb58249d..1e5132fbcf26f4d07d5873c77e1a590a4070f4c4 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Increase\sthe\sversion\snumber\sto\s3.8.7
-D 2014-08-20T23:42:50.860
+C Fix\sa\sfaulty\sassert()\sstatement.\s\sAdd\scomments\sto\sclarify\sthe\sbehavior\sof\nthe\ssqlite3OpenTableAndIndices()\sroutine\sin\sinsert.c.\s\sAdd\stest\scases\sto\nverify\sthat\sthe\sassert()\sstatement\sis\snot\sfiring\sinappropriately.\nTicket\s[369d57fb8e5ccdff06f1].
+D 2014-08-21T14:10:23.770
 F Makefile.arm-wince-mingw32ce-gcc d6df77f1f48d690bd73162294bbba7f59507c72f
 F Makefile.in 5eb79e334a5de69c87740edd56af6527dd219308
 F Makefile.linux-gcc 91d710bdc4998cb015f39edf3cb314ec4f4d7e23
@@ -138,6 +138,7 @@ F ext/rtree/rtreeB.test c85f9ce78766c4e68b8b89fbf2979ee9cfa82b4e
 F ext/rtree/rtreeC.test df158dcc81f1a43ce7eef361af03c48ec91f1e06
 F ext/rtree/rtreeD.test 636630357638f5983701550b37f0f5867130d2ca
 F ext/rtree/rtreeE.test 388c1c8602c3ce55c15f03b509e9cf545fb7c41f
+F ext/rtree/rtreeF.test 66deb9fd1611c7ca2e374adba63debdc2dbb12b4
 F ext/rtree/rtree_perf.tcl 6c18c1f23cd48e0f948930c98dfdd37dfccb5195
 F ext/rtree/rtree_util.tcl 06aab2ed5b826545bf215fff90ecb9255a8647ea
 F ext/rtree/sqlite3rtree.h 83349d519fe5f518b3ea025d18dd1fe51b1684bd
@@ -175,7 +176,7 @@ F src/callback.c fcff28cf0df2403dd2f313bb8d1b8f31f6f3cd64
 F src/complete.c dc1d136c0feee03c2f7550bafc0d29075e36deac
 F src/ctime.c 0231df905e2c4abba4483ee18ffc05adc321df2a
 F src/date.c 593c744b2623971e45affd0bde347631bdfa4625
-F src/delete.c bcf8f72126cea80fc3d5bc5494cf19b3f8935aaf
+F src/delete.c 5adcd322c6b08fc25d215d780ca62cebce66304d
 F src/expr.c f749009cf4a8534efb5e0d5cd7c9fb1fb0f2836c
 F src/fault.c 160a0c015b6c2629d3899ed2daf63d75754a32bb
 F src/fkey.c 8545f3b36da47473e10800ea4fb0810fd4062514
@@ -184,7 +185,7 @@ F src/global.c 1e4bd956dc2f608f87d2a929abc4a20db65f30e4
 F src/hash.c d139319967164f139c8d1bb8a11b14db9c4ba3cd
 F src/hash.h 8890a25af81fb85a9ad7790d32eedab4b994da22
 F src/hwtime.h d32741c8f4df852c7d959236615444e2b1063b08
-F src/insert.c 991e4964e9295da3993e2c0f81c7faf642371848
+F src/insert.c d1a104e67b33314d4cc5c1356147446086ab9fc8
 F src/journal.c b4124532212b6952f42eb2c12fa3c25701d8ba8d
 F src/legacy.c febc2a9e7ad6c1a6191c7b5b9170b325d263f343
 F src/lempar.c cdf0a000315332fc9b50b62f3b5e22e080a0952b
@@ -1187,7 +1188,7 @@ F tool/vdbe_profile.tcl 67746953071a9f8f2f668b73fe899074e2c6d8c1
 F tool/warnings-clang.sh f6aa929dc20ef1f856af04a730772f59283631d4
 F tool/warnings.sh 0abfd78ceb09b7f7c27c688c8e3fe93268a13b32
 F tool/win/sqlite.vsix deb315d026cc8400325c5863eef847784a219a2f
-P bc985caa7816f1f873ad8e4467c5278399f315ce
-R 69e5d59c0ae1acccebd6955e02833316
+P 91594aae0725388765070c80039dfe1bf126392d
+R 25e887863ed8cfd2c8a241fac46385f1
 U drh
-Z 5338496858d2cbdf1a890a2630150d12
+Z ed55b6e966354470a11e6c95fe10b90c
index d619efb0e768d3864f39888ccc2fe14f0781aed6..944f894bbc10eab54f5f585e50020ece8985b477 100644 (file)
@@ -1 +1 @@
-91594aae0725388765070c80039dfe1bf126392d
\ No newline at end of file
+7029b3404d3f5f698a496934f3a3f2972051b257
\ No newline at end of file
index c74d8eab7d56fafaad805d881d2f0dd391435866..af83903c426816711d85e933f8c1c1a3cb4a9905 100644 (file)
@@ -466,10 +466,11 @@ void sqlite3DeleteFrom(
     ** triggers.
     */
     if( !isView ){
+      testcase( IsVirtual(pTab) );
       sqlite3OpenTableAndIndices(pParse, pTab, OP_OpenWrite, iTabCur, aToOpen,
                                  &iDataCur, &iIdxCur);
-      assert( pPk || iDataCur==iTabCur );
-      assert( pPk || iIdxCur==iDataCur+1 );
+      assert( pPk || IsVirtual(pTab) || iDataCur==iTabCur );
+      assert( pPk || IsVirtual(pTab) || iIdxCur==iDataCur+1 );
     }
   
     /* Set up a loop over the rowids/primary-keys that were found in the
@@ -477,7 +478,8 @@ void sqlite3DeleteFrom(
     */
     if( okOnePass ){
       /* Just one row.  Hence the top-of-loop is a no-op */
-      assert( nKey==nPk ); /* OP_Found will use an unpacked key */
+      assert( nKey==nPk );  /* OP_Found will use an unpacked key */
+      assert( !IsVirtual(pTab) );
       if( aToOpen[iDataCur-iTabCur] ){
         assert( pPk!=0 );
         sqlite3VdbeAddOp4Int(v, OP_NotFound, iDataCur, addrBypass, iKey, nKey);
index 5964b91ca4b2dce9d2bf6bef7bc3e7037c755ee7..3e6982d8367efde93fb624e3c3c5cbc2e1010529 100644 (file)
@@ -1612,6 +1612,9 @@ void sqlite3CompleteInsertion(
 ** For a WITHOUT ROWID table, *piDataCur will be somewhere in the range
 ** of *piIdxCurs, depending on where the PRIMARY KEY index appears on the
 ** pTab->pIndex list.
+**
+** If pTab is a virtual table, then this routine is a no-op and the
+** *piDataCur and *piIdxCur values are left uninitialized.
 */
 int sqlite3OpenTableAndIndices(
   Parse *pParse,   /* Parsing context */
@@ -1630,9 +1633,9 @@ int sqlite3OpenTableAndIndices(
 
   assert( op==OP_OpenRead || op==OP_OpenWrite );
   if( IsVirtual(pTab) ){
-    assert( aToOpen==0 );
-    *piDataCur = 0;
-    *piIdxCur = 1;
+    /* This routine is a no-op for virtual tables. Leave the output
+    ** variables *piDataCur and *piIdxCur uninitialized so that valgrind
+    ** can detect if they are used by mistake in the caller. */
     return 0;
   }
   iDb = sqlite3SchemaToIndex(pParse->db, pTab->pSchema);