]> git.ipfire.org Git - thirdparty/sqlite.git/commitdiff
More bug fixes in the ON CONFLICT enhancement. (CVS 357)
authordrh <drh@noemail.net>
Wed, 30 Jan 2002 00:54:55 +0000 (00:54 +0000)
committerdrh <drh@noemail.net>
Wed, 30 Jan 2002 00:54:55 +0000 (00:54 +0000)
FossilOrigin-Name: 8229b5f6a348a56432a4a609ee125520c5831973

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

index ea170d3457a1a21958e20eb7534df8dee6317b12..ac2cd5c71f8deef402a0d09d3f505f9a0db39dbd 100644 (file)
--- a/manifest
+++ b/manifest
@@ -1,5 +1,5 @@
-C The\snew\sON\sCONFLICT\slogic\sis\sin\sand\spasses\sthe\slegacy\stests.\s\sBut\sthe\nnew\scapabilities\shave\snot\sbeen\stested\sand\sare\slikely\sbroken.\s(CVS\s356)
-D 2002-01-29T23:07:02
+C More\sbug\sfixes\sin\sthe\sON\sCONFLICT\senhancement.\s(CVS\s357)
+D 2002-01-30T00:54:56
 F Makefile.in 9fa4277413bf1d9cf91365f07d4108d7d87ed2af
 F Makefile.template 3e26a3b9e7aee1b811deaf673e8d8973bdb3f22d
 F README a4c0ba11354ef6ba0776b400d057c59da47a4cc0
@@ -26,7 +26,7 @@ F src/delete.c 4cdb6d2e94e2eb1b1aa79eefafd4669d43c249d6
 F src/expr.c 4cae8bf44d5732182e5e8c25b4552c05ea55593e
 F src/hash.c 8f7c740ef2eaaa8decfa8751f2be30680b123e46
 F src/hash.h a5f5b3ce2d086a172c5879b0b06a27a82eac9fac
-F src/insert.c 35c3e17bf5f8ef3a9cdd95f7cfdbf3d94cd598c2
+F src/insert.c b942f99e4f4c0464f51ad171b6edbc1439fac893
 F src/main.c 0205771a6c31a9858ff131fc1e797b589afb76bf
 F src/md5.c 52f677bfc590e09f71d07d7e327bd59da738d07c
 F src/os.c c615faa4d23e742e0650e0751a6ad2a18438ad53
@@ -49,7 +49,7 @@ F src/test3.c d6775f95fd91f5b3cf0e2382a28e5aaeb68f745b
 F src/tokenize.c 1199b96a82d5c41509b5e24fc9faa1852b7f3135
 F src/update.c 5ffd4bbd380f1fa99da184f28416e6dcf8b5508e
 F src/util.c 8f8973dd55a6ec63be9632fc5de86965c99d6327
-F src/vdbe.c abd60d37361eaaa3b94d016cd2a9f31bd8d57620
+F src/vdbe.c 893fa634870a5ea67c30ba61b7881b537f5c2723
 F src/vdbe.h 5b1bd518126fc5a30e6ea13fe11de931b32c4b59
 F src/where.c 2dda39367f193194e4c7d2e0dcab31527d9d8aba
 F test/all.test 2a51e5395ac7c2c539689b123b9782a05e3837fe
@@ -57,6 +57,7 @@ F test/bigrow.test 8ab252dba108f12ad64e337b0f2ff31a807ac578
 F test/btree.test 6ab4dc5f595905a276ef588fad3c9236dc07a47b
 F test/btree2.test 08e9485619265cbaf5d11bd71f357cdc26bb87e0
 F test/btree3.test 9caa9e22491dd8cd8aa36d7ac3b48b089817c895
+F test/conflict.test b1115520b32fe682dfd161754ed634352ab476af
 F test/copy.test 768e6f1701a07d08090e1ca7f7dcce0a7a72b43e
 F test/delete.test c904a62129fe102b314a96111a8417f10249e4d8
 F test/expr.test c8a495050dcec3f9e68538c3ef466726933302c1
@@ -119,7 +120,7 @@ F www/speed.tcl 83457b2bf6bb430900bd48ca3dd98264d9a916a5
 F www/sqlite.tcl 8b5884354cb615049aed83039f8dfe1552a44279
 F www/tclsqlite.tcl 829b393d1ab187fd7a5e978631b3429318885c49
 F www/vdbe.tcl 2013852c27a02a091d39a766bc87cff329f21218
-P e00a9ff8f99dd58f7cb19a6195fac21f4c8b4af9
-R 1ca39242f5cf0f094b73bd233e3fcc93
+P ac8a4189e2a0c41161ee359db25de94435420368
+R d0474e87b43c8e56cdd7c7f610ed8044
 U drh
-Z 0835a3278f559e60402c3a41f932d0d4
+Z 06e7e93dabc09d9be0f533183ed3ad0f
index ba959099f7fdffaabf5191c3e98f1d54843d5f68..f02b51f4c7bfac28eb8cd82c78c555880c69438f 100644 (file)
@@ -1 +1 @@
-ac8a4189e2a0c41161ee359db25de94435420368
\ No newline at end of file
+8229b5f6a348a56432a4a609ee125520c5831973
\ No newline at end of file
index 1a01fafd95d33b92ab1d6fc852f9593d76df40e6..e14b1c454c7d64c257bf43b57c10576a8bec8558 100644 (file)
@@ -12,7 +12,7 @@
 ** This file contains C code routines that are called by the parser
 ** to handle INSERT statements in SQLite.
 **
-** $Id: insert.c,v 1.35 2002/01/29 23:07:02 drh Exp $
+** $Id: insert.c,v 1.36 2002/01/30 00:54:56 drh Exp $
 */
 #include "sqliteInt.h"
 
@@ -482,7 +482,7 @@ void sqliteGenerateConstraintChecks(
     if( overrideError!=OE_Default ){
       onError = overrideError;
     }
-    sqliteVdbeAddOp(v, OP_Dup, extra+nCol+2, 1);
+    sqliteVdbeAddOp(v, OP_Dup, extra+nCol+1+recnoChng, 1);
     jumpInst = sqliteVdbeAddOp(v, OP_IsUnique, base+iCur+1, 0);
     switch( onError ){
       case OE_Abort: {
@@ -496,7 +496,6 @@ void sqliteGenerateConstraintChecks(
         break;
       }
       case OE_Replace: {
-        sqliteVdbeAddOp(v, OP_MoveTo, base, 0);
         sqliteGenerateRowDelete(v, pTab, base);
         if( isUpdate ){
           sqliteVdbeAddOp(v, OP_Dup, nCol+extra+recnoChng, 1);
index 40b5e5d02ca753ca10d4f98110252ee9c9120758..a9a8380df93dd70706304c3afe4774f023ad6a3b 100644 (file)
@@ -30,7 +30,7 @@
 ** But other routines are also provided to help in building up
 ** a program instruction by instruction.
 **
-** $Id: vdbe.c,v 1.110 2002/01/29 23:07:02 drh Exp $
+** $Id: vdbe.c,v 1.111 2002/01/30 00:54:56 drh Exp $
 */
 #include "sqliteInt.h"
 #include <ctype.h>
@@ -1211,6 +1211,7 @@ case OP_String: {
 ** P1 elements are popped off of the top of stack and discarded.
 */
 case OP_Pop: {
+  assert( p->tos+1>=pOp->p1 );
   PopStack(p, pOp->p1);
   break;
 }
diff --git a/test/conflict.test b/test/conflict.test
new file mode 100644 (file)
index 0000000..d6cc2d3
--- /dev/null
@@ -0,0 +1,148 @@
+# 2002 January 29
+#
+# 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 implements regression tests for SQLite library.
+#
+# This file implements tests for the conflict resolution extension
+# to SQLite.
+#
+# $Id: conflict.test,v 1.1 2002/01/30 00:54:57 drh Exp $
+
+set testdir [file dirname $argv0]
+source $testdir/tester.tcl
+
+# Create a table with three fields, two of which must be
+# UNIQUE.
+#
+do_test conflict-1.1 {
+  execsql {
+    CREATE TABLE t1(a, b, c, UNIQUE(a,b));
+    INSERT INTO t1 VALUES(1,2,3);
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {3}
+do_test conflict-1.2 {
+  catchsql {
+    INSERT INTO t1 VALUES(1,2,4);
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {1 {constraint failed}}
+do_test conflict-1.3 {
+  catchsql {
+    INSERT ON CONFLICT IGNORE INTO t1 VALUES(1,2,4);
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {0 3}
+do_test conflict-1.4 {
+  catchsql {
+    INSERT ON CONFLICT REPLACE INTO t1 VALUES(1,2,4);
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {0 4}
+do_test conflict-1.5 {
+  catchsql {
+    INSERT ON CONFLICT ABORT INTO t1 VALUES(1,2,5);
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {1 {constraint failed}}
+do_test conflict-1.6 {
+  catchsql {
+    INSERT IGNORE INTO t1 VALUES(1,2,5);
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {0 4}
+do_test conflict-1.7 {
+  catchsql {
+    INSERT REPLACE INTO t1 VALUES(1,2,5);
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {0 5}
+do_test conflict-1.8 {
+  catchsql {
+    INSERT ON CONFLICT ABORT INTO t1 VALUES(1,2,6);
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {1 {constraint failed}}
+
+do_test conflict-1.9 {
+  execsql {
+    BEGIN;
+    CREATE TABLE t2(a,b,c);
+    INSERT INTO t2 VALUES(1,2,11);
+    INSERT INTO t2 VALUES(1,2,12);
+    INSERT INTO t2 VALUES(1,2,13);
+    INSERT INTO t2 VALUES(1,2,14);
+    INSERT INTO t2 VALUES(1,3,21);
+    INSERT INTO t2 VALUES(1,3,22);
+    INSERT INTO t2 VALUES(1,3,23);
+    INSERT INTO t2 VALUES(1,3,24);
+    COMMIT;
+    SELECT count(*) FROM t2;
+  }
+} 8
+do_test conflict-1.10 {
+  catchsql {
+    INSERT IGNORE INTO t1 SELECT a,b,c FROM t2 ORDER BY c;
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {0 {5 21}}
+do_test conflict-1.11 {
+  catchsql {
+    INSERT REPLACE INTO t1 SELECT a,b,c FROM t2 ORDER BY c;
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {0 {14 24}}
+
+###### Fix me!
+do_test conflict-1.12 {
+  catchsql {
+    INSERT REPLACE INTO t1 SELECT a,b,c FROM t2 ORDER BY c DESC;
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {0 {14 24}}
+
+do_test conflict-1.13 {
+  execsql {
+    BEGIN;
+    DELETE FROM t1;
+    INSERT INTO t1 VALUES(1,2,3);
+    INSERT INTO t1 VALUES(1,3,4);
+    INSERT INTO t1 VALUES(2,3,5);
+    COMMIT;
+    SELECT * FROM t1 ORDER BY c;
+  }
+} {1 2 3 1 3 4 2 3 5}
+do_test conflict-1.14 {
+  catchsql {
+    UPDATE ON CONFLICT ABORT t1 SET b=3 WHERE b=2;
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {1 {constraint failed}};
+do_test conflict-1.15 {
+  catchsql {
+    UPDATE t1 SET b=3 WHERE b=2;
+    SELECT c FROM t1 ORDER BY c;
+  }
+} {1 {constraint failed}};
+do_test conflict-1.16 {
+  catchsql {
+    UPDATE ON CONFLICT IGNORE t1 SET b=3 WHERE b=2;
+    SELECT * FROM t1 ORDER BY c;
+  }
+} {0 {1 2 3 1 3 4 2 3 5}}
+do_test conflict-1.17 {
+  catchsql {
+    UPDATE ON CONFLICT REPLACE t1 SET b=3 WHERE b=2;
+    SELECT * FROM t1 ORDER BY c;
+  }
+} {0 {1 3 3 2 3 5}}
+
+
+finish_test