]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
Minor cleanup changes on the OP_StackDepth opcode. Added the
authordrh <drh@noemail.net>
Wed, 12 Dec 2007 22:24:12 +0000 (22:24 +0000)
committerdrh <drh@noemail.net>
Wed, 12 Dec 2007 22:24:12 +0000 (22:24 +0000)
sidedelete test for additional testing of ticket #2832. (CVS 4619)

FossilOrigin-Name: c0689409320de1532be0c0cae12b4b716f6bffb9

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

index 2ade6bd318172df434db2e6d7cc0adf1e58c08c3..5042d05f59d57c43cc7b729257e9a93879df1041 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C Remove\san\s(explain)\saccidentally\sleft\sin\stkt2832.test.\s(CVS\s4618)
-D 2007-12-12T18:05:21
+C Minor\scleanup\schanges\son\sthe\sOP_StackDepth\sopcode.\s\sAdded\sthe\nsidedelete\stest\sfor\sadditional\stesting\sof\sticket\s#2832.\s(CVS\s4619)
+D 2007-12-12T22:24:13
 F Makefile.arm-wince-mingw32ce-gcc ac5f7b2cef0cd850d6f755ba6ee4ab961b1fadf7
 F Makefile.in 0590398f62fc2c456ff4c45e9741f5a718b7e2ac
 F Makefile.linux-gcc d53183f4aa6a9192d249731c90dbdffbd2c68654
@@ -168,7 +168,7 @@ F src/update.c 57c07b63410cdd3d14888e33439aa1955a3514c1
 F src/utf.c ef4b7d83bae533b76c3e1bf635b113fdad86a736
 F src/util.c 05f31144bbd3f1a24f4139ae029c42545cb72624
 F src/vacuum.c 25ffbd766f25bca099ead1c1e11f5528c86102b8
-F src/vdbe.c 94d41ad149e29ffdbd000637e5b71c4f1a9d8ab5
+F src/vdbe.c a6f9fa3b97ffc2afc8625a4540784be0e59981ae
 F src/vdbe.h 79e09ff13b85457abe437d9814454534ebbc1fe3
 F src/vdbeInt.h 630145b9bfaa19190ab491f52658a7db550f2247
 F src/vdbeapi.c dd2c43317294e0a013e9f634ee4209a3ea459b43
@@ -424,6 +424,7 @@ F test/shared2.test 0ee9de8964d70e451936a48c41cb161d9134ccf4
 F test/shared3.test 01e3e124dbb3859788aabc7cfb82f7ea04421749
 F test/shared_err.test bfe49fbbf26746a3c05255b1dc7230744182b744
 F test/shortread1.test bb591ef20f0fd9ed26d0d12e80eee6d7ac8897a3
+F test/sidedelete.test 736ac1da08b3b1aa62df97fef2fcdb1b660111b9
 F test/soak.test 64f9b27fbcdec43335a88c546ce1983e6ba40d7b
 F test/softheap1.test 29cbdb847e63ffef3af5da1e3cd15f44ee11d770
 F test/sort.test 0e4456e729e5a92a625907c63dcdedfbe72c5dc5
@@ -599,7 +600,7 @@ F www/tclsqlite.tcl 8be95ee6dba05eabcd27a9d91331c803f2ce2130
 F www/vdbe.tcl 87a31ace769f20d3627a64fa1fade7fed47b90d0
 F www/version3.tcl 890248cf7b70e60c383b0e84d77d5132b3ead42b
 F www/whentouse.tcl fc46eae081251c3c181bd79c5faef8195d7991a5
-P 12c3029b1edcff4435177c709fb2584323f8c515
-R 87657e5a89279edad00b9a03956277a1
-U danielk1977
-Z 00e4dac0cc367b2776d1811fdffc90d0
+P 48947e2b75d39c5be0d08fe1c7b888d9065f9116
+R bb83372b6806afd80973cd2815dddbab
+U drh
+Z ed8f32215ce7ea227bff236ab22d0da6
index 2952462a69ae44a3a3ca6c6dffb3ccc1c4aafe69..f097a8031d53cf60de8e855de0dffeea20bb30dc 100644 (file)
@@ -1 +1 @@
-48947e2b75d39c5be0d08fe1c7b888d9065f9116
\ No newline at end of file
+c0689409320de1532be0c0cae12b4b716f6bffb9
\ No newline at end of file
index 88c21219a00362cdcd74340df2f271e6657edacc..e14c558fc0c3a988758e4dfe70ff971a60f469b0 100644 (file)
@@ -43,7 +43,7 @@
 ** in this file for details.  If in doubt, do not deviate from existing
 ** commenting and indentation practices when changing or adding code.
 **
-** $Id: vdbe.c,v 1.658 2007/12/12 12:25:22 drh Exp $
+** $Id: vdbe.c,v 1.659 2007/12/12 22:24:13 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -701,9 +701,10 @@ case OP_Halt: {            /* no-push */
 ** This opcode is used for internal consistency checking.
 */
 case OP_StackDepth: {       /* no-push */
+  int n = pTos - p->aStack + 1;
   if( pOp->p1<0 ){
-    pOp->p1 = pTos - p->aStack + 1;
-  }else if( pOp->p1!=pTos - p->aStack + 1 ){
+    pOp->p1 = n;
+  }else if( pOp->p1!=n ){
     p->pTos = pTos;
     p->rc = rc = SQLITE_INTERNAL;
     p->pc = pc;
diff --git a/test/sidedelete.test b/test/sidedelete.test
new file mode 100644 (file)
index 0000000..2ed2cb7
--- /dev/null
@@ -0,0 +1,91 @@
+# 2007 Dec 12
+#
+# 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 test cases for stressing database
+# changes that involve side effects that delete rows from
+# the table being changed.  Ticket #2832 shows that in
+# older versions of SQLite that behavior was implemented
+# incorrectly and resulted in corrupt database files.
+#
+# $Id: sidedelete.test,v 1.1 2007/12/12 22:24:13 drh Exp $
+#
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# The sequence table is created to store a sequence of integers
+# starting with 1.  This is used to reinitialize other tables
+# as part of other tests.
+#
+do_test sidedelete-1.1 {
+  execsql {
+    CREATE TABLE sequence(a INTEGER PRIMARY KEY);
+    INSERT INTO sequence VALUES(1);
+    INSERT INTO sequence VALUES(2);
+  }
+  for {set i 0} {$i<8} {incr i} {
+    execsql {
+      INSERT INTO sequence SELECT a+(SELECT max(a) FROM sequence) FROM sequence;
+    }
+  }
+  execsql {SELECT count(*) FROM sequence}
+} {512}
+
+# Make a series of changes using an UPDATE OR REPLACE and a
+# correlated subquery.  This would cause database corruption
+# prior to the fix for ticket #2832.
+#
+do_test sidedelete-2.0 {
+  execsql {
+    CREATE TABLE t1(a PRIMARY KEY, b);
+    CREATE TABLE chng(a PRIMARY KEY, b);
+    SELECT count(*) FROM t1 UNION ALL SELECT count(*) FROM chng;
+  }
+} {0 0}
+for {set i 2} {$i<=100} {incr i} {
+  set n [expr {($i+2)/2}]
+  do_test sidedelete-2.$i.1 {
+    execsql {
+      DELETE FROM t1;
+      INSERT INTO t1 SELECT a, a FROM sequence WHERE a<=$i;
+      DELETE FROM chng;
+      INSERT INTO chng SELECT a*2, a*2+1 FROM sequence WHERE a<=$i/2;
+      UPDATE OR REPLACE t1 SET a=(SELECT b FROM chng WHERE a=t1.a);
+      SELECT count(*), sum(a) FROM t1;
+    }
+  } [list $n [expr {$n*$n-1}]]
+  integrity_check sidedelete-2.$i.2
+}
+
+# This will cause stacks leaks but not database corruption prior
+# to the #2832 fix.
+#
+do_test sidedelete-3.0 {
+  execsql {
+     DROP TABLE t1;
+     CREATE TABLE t1(a PRIMARY KEY);
+     SELECT * FROM t1;
+  }
+} {}
+for {set i 1} {$i<=100} {incr i} {
+  set n [expr {($i+1)/2}]
+  do_test sidedelete-3.$i.1 {
+    execsql {
+      DELETE FROM t1;
+      INSERT INTO t1 SELECT a FROM sequence WHERE a<=$i;
+      UPDATE OR REPLACE t1 SET a=a+1;
+      SELECT count(*), sum(a) FROM t1;
+    }
+  } [list $n [expr {$n*($n+1)}]]
+  integrity_check sidedelete-3.$i.2
+}
+
+finish_test