1bb37fdc7Sdrh# 2002 January 29 2bb37fdc7Sdrh# 3bb37fdc7Sdrh# The author disclaims copyright to this source code. In place of 4bb37fdc7Sdrh# a legal notice, here is a blessing: 5bb37fdc7Sdrh# 6bb37fdc7Sdrh# May you do good and not evil. 7bb37fdc7Sdrh# May you find forgiveness for yourself and forgive others. 8bb37fdc7Sdrh# May you share freely, never taking more than you give. 9bb37fdc7Sdrh# 10bb37fdc7Sdrh#*********************************************************************** 11bb37fdc7Sdrh# This file implements regression tests for SQLite library. 12bb37fdc7Sdrh# 13bb37fdc7Sdrh# This file implements tests for the conflict resolution extension 14bb37fdc7Sdrh# to SQLite. 15bb37fdc7Sdrh# 16*33752f8aSdanielk1977# $Id: conflict.test,v 1.21 2004/05/31 08:55:34 danielk1977 Exp $ 17bb37fdc7Sdrh 18bb37fdc7Sdrhset testdir [file dirname $argv0] 19bb37fdc7Sdrhsource $testdir/tester.tcl 20bb37fdc7Sdrh 210d65dc0eSdrh# Create tables for the first group of tests. 22bb37fdc7Sdrh# 230d65dc0eSdrhdo_test conflict-1.0 { 24bb37fdc7Sdrh execsql { 25bb37fdc7Sdrh CREATE TABLE t1(a, b, c, UNIQUE(a,b)); 260d65dc0eSdrh CREATE TABLE t2(x); 27bb37fdc7Sdrh SELECT c FROM t1 ORDER BY c; 28bb37fdc7Sdrh } 290d65dc0eSdrh} {} 30bb37fdc7Sdrh 310d65dc0eSdrh# Six columns of configuration data as follows: 320d65dc0eSdrh# 330d65dc0eSdrh# i The reference number of the test 340d65dc0eSdrh# conf The conflict resolution algorithm on the BEGIN statement 350d65dc0eSdrh# cmd An INSERT or REPLACE command to execute against table t1 360d65dc0eSdrh# t0 True if there is an error from $cmd 370d65dc0eSdrh# t1 Content of "c" column of t1 assuming no error in $cmd 380d65dc0eSdrh# t2 Content of "x" column of t2 390d65dc0eSdrh# 400d65dc0eSdrhforeach {i conf cmd t0 t1 t2} { 410d65dc0eSdrh 1 {} INSERT 1 {} 1 420d65dc0eSdrh 2 {} {INSERT OR IGNORE} 0 3 1 430d65dc0eSdrh 3 {} {INSERT OR REPLACE} 0 4 1 440d65dc0eSdrh 4 {} REPLACE 0 4 1 450d65dc0eSdrh 5 {} {INSERT OR FAIL} 1 {} 1 460d65dc0eSdrh 6 {} {INSERT OR ABORT} 1 {} 1 470d65dc0eSdrh 7 {} {INSERT OR ROLLBACK} 1 {} {} 480d65dc0eSdrh} { 491d850a72Sdanielk1977 if { $conf=={} } { 501d850a72Sdanielk1977 510d65dc0eSdrh do_test conflict-1.$i { 520d65dc0eSdrh if {$conf!=""} {set conf "ON CONFLICT $conf"} 530d65dc0eSdrh set r0 [catch {execsql [subst { 54bb37fdc7Sdrh DELETE FROM t1; 550d65dc0eSdrh DELETE FROM t2; 56bb37fdc7Sdrh INSERT INTO t1 VALUES(1,2,3); 570d65dc0eSdrh BEGIN $conf; 580d65dc0eSdrh INSERT INTO t2 VALUES(1); 590d65dc0eSdrh $cmd INTO t1 VALUES(1,2,4); 600d65dc0eSdrh }]} r1] 616b8b8749Sdrh catch {execsql {COMMIT}} 620d65dc0eSdrh if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} 630d65dc0eSdrh set r2 [execsql {SELECT x FROM t2}] 640d65dc0eSdrh list $r0 $r1 $r2 650d65dc0eSdrh } [list $t0 $t1 $t2] 661d850a72Sdanielk1977 671d850a72Sdanielk1977 } 68bb37fdc7Sdrh} 69bb37fdc7Sdrh 700d65dc0eSdrh# Create tables for the first group of tests. 710d65dc0eSdrh# 720d65dc0eSdrhdo_test conflict-2.0 { 73ef6764a1Sdrh execsql { 74ef6764a1Sdrh DROP TABLE t1; 75ef6764a1Sdrh DROP TABLE t2; 760d65dc0eSdrh CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b)); 770d65dc0eSdrh CREATE TABLE t2(x); 78ef6764a1Sdrh SELECT c FROM t1 ORDER BY c; 79ef6764a1Sdrh } 800d65dc0eSdrh} {} 81ef6764a1Sdrh 820d65dc0eSdrh# Six columns of configuration data as follows: 830d65dc0eSdrh# 840d65dc0eSdrh# i The reference number of the test 850d65dc0eSdrh# conf The conflict resolution algorithm on the BEGIN statement 860d65dc0eSdrh# cmd An INSERT or REPLACE command to execute against table t1 870d65dc0eSdrh# t0 True if there is an error from $cmd 880d65dc0eSdrh# t1 Content of "c" column of t1 assuming no error in $cmd 890d65dc0eSdrh# t2 Content of "x" column of t2 900d65dc0eSdrh# 910d65dc0eSdrhforeach {i conf cmd t0 t1 t2} { 920d65dc0eSdrh 1 {} INSERT 1 {} 1 930d65dc0eSdrh 2 {} {INSERT OR IGNORE} 0 3 1 940d65dc0eSdrh 3 {} {INSERT OR REPLACE} 0 4 1 950d65dc0eSdrh 4 {} REPLACE 0 4 1 960d65dc0eSdrh 5 {} {INSERT OR FAIL} 1 {} 1 970d65dc0eSdrh 6 {} {INSERT OR ABORT} 1 {} 1 980d65dc0eSdrh 7 {} {INSERT OR ROLLBACK} 1 {} {} 990d65dc0eSdrh} { 1000d65dc0eSdrh do_test conflict-2.$i { 1010d65dc0eSdrh if {$conf!=""} {set conf "ON CONFLICT $conf"} 1020d65dc0eSdrh set r0 [catch {execsql [subst { 103ef6764a1Sdrh DELETE FROM t1; 1040d65dc0eSdrh DELETE FROM t2; 105ef6764a1Sdrh INSERT INTO t1 VALUES(1,2,3); 1060d65dc0eSdrh BEGIN $conf; 1070d65dc0eSdrh INSERT INTO t2 VALUES(1); 1080d65dc0eSdrh $cmd INTO t1 VALUES(1,2,4); 1090d65dc0eSdrh }]} r1] 1106b8b8749Sdrh catch {execsql {COMMIT}} 1110d65dc0eSdrh if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} 1120d65dc0eSdrh set r2 [execsql {SELECT x FROM t2}] 1130d65dc0eSdrh list $r0 $r1 $r2 1140d65dc0eSdrh } [list $t0 $t1 $t2] 115ef6764a1Sdrh} 1160d65dc0eSdrh 1170d65dc0eSdrh# Create tables for the first group of tests. 1180d65dc0eSdrh# 1190d65dc0eSdrhdo_test conflict-3.0 { 1200d65dc0eSdrh execsql { 1210d65dc0eSdrh DROP TABLE t1; 1220d65dc0eSdrh DROP TABLE t2; 123e0194f2bSdrh CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b)); 1240d65dc0eSdrh CREATE TABLE t2(x); 125ef6764a1Sdrh SELECT c FROM t1 ORDER BY c; 126ef6764a1Sdrh } 1270d65dc0eSdrh} {} 1280d65dc0eSdrh 1290d65dc0eSdrh# Six columns of configuration data as follows: 1300d65dc0eSdrh# 1310d65dc0eSdrh# i The reference number of the test 1320d65dc0eSdrh# conf The conflict resolution algorithm on the BEGIN statement 1330d65dc0eSdrh# cmd An INSERT or REPLACE command to execute against table t1 1340d65dc0eSdrh# t0 True if there is an error from $cmd 1350d65dc0eSdrh# t1 Content of "c" column of t1 assuming no error in $cmd 1360d65dc0eSdrh# t2 Content of "x" column of t2 1370d65dc0eSdrh# 1380d65dc0eSdrhforeach {i conf cmd t0 t1 t2} { 1390d65dc0eSdrh 1 {} INSERT 1 {} 1 1400d65dc0eSdrh 2 {} {INSERT OR IGNORE} 0 3 1 1410d65dc0eSdrh 3 {} {INSERT OR REPLACE} 0 4 1 1420d65dc0eSdrh 4 {} REPLACE 0 4 1 1430d65dc0eSdrh 5 {} {INSERT OR FAIL} 1 {} 1 1440d65dc0eSdrh 6 {} {INSERT OR ABORT} 1 {} 1 1450d65dc0eSdrh 7 {} {INSERT OR ROLLBACK} 1 {} {} 1460d65dc0eSdrh} { 1470d65dc0eSdrh do_test conflict-3.$i { 1480d65dc0eSdrh if {$conf!=""} {set conf "ON CONFLICT $conf"} 1490d65dc0eSdrh set r0 [catch {execsql [subst { 1500d65dc0eSdrh DELETE FROM t1; 1510d65dc0eSdrh DELETE FROM t2; 1520d65dc0eSdrh INSERT INTO t1 VALUES(1,2,3); 1530d65dc0eSdrh BEGIN $conf; 1540d65dc0eSdrh INSERT INTO t2 VALUES(1); 1550d65dc0eSdrh $cmd INTO t1 VALUES(1,2,4); 1560d65dc0eSdrh }]} r1] 1576b8b8749Sdrh catch {execsql {COMMIT}} 1580d65dc0eSdrh if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} 1590d65dc0eSdrh set r2 [execsql {SELECT x FROM t2}] 1600d65dc0eSdrh list $r0 $r1 $r2 1610d65dc0eSdrh } [list $t0 $t1 $t2] 162ef6764a1Sdrh} 1630d65dc0eSdrh 1640d65dc0eSdrhdo_test conflict-4.0 { 1650d65dc0eSdrh execsql { 1660d65dc0eSdrh DROP TABLE t2; 1670d65dc0eSdrh CREATE TABLE t2(x); 1680d65dc0eSdrh SELECT x FROM t2; 169ef6764a1Sdrh } 1700d65dc0eSdrh} {} 1710d65dc0eSdrh 1720d65dc0eSdrh# Six columns of configuration data as follows: 1730d65dc0eSdrh# 1740d65dc0eSdrh# i The reference number of the test 1750d65dc0eSdrh# conf1 The conflict resolution algorithm on the UNIQUE constraint 1760d65dc0eSdrh# conf2 The conflict resolution algorithm on the BEGIN statement 1770d65dc0eSdrh# cmd An INSERT or REPLACE command to execute against table t1 1780d65dc0eSdrh# t0 True if there is an error from $cmd 1790d65dc0eSdrh# t1 Content of "c" column of t1 assuming no error in $cmd 1800d65dc0eSdrh# t2 Content of "x" column of t2 1810d65dc0eSdrh# 1820d65dc0eSdrhforeach {i conf1 conf2 cmd t0 t1 t2} { 1830d65dc0eSdrh 1 {} {} INSERT 1 {} 1 1840d65dc0eSdrh 2 REPLACE {} INSERT 0 4 1 1850d65dc0eSdrh 3 IGNORE {} INSERT 0 3 1 1860d65dc0eSdrh 4 FAIL {} INSERT 1 {} 1 1870d65dc0eSdrh 5 ABORT {} INSERT 1 {} 1 1880d65dc0eSdrh 6 ROLLBACK {} INSERT 1 {} {} 1890d65dc0eSdrh 7 REPLACE {} {INSERT OR IGNORE} 0 3 1 1900d65dc0eSdrh 8 IGNORE {} {INSERT OR REPLACE} 0 4 1 1910d65dc0eSdrh 9 FAIL {} {INSERT OR IGNORE} 0 3 1 1920d65dc0eSdrh 10 ABORT {} {INSERT OR REPLACE} 0 4 1 1930d65dc0eSdrh 11 ROLLBACK {} {INSERT OR IGNORE } 0 3 1 1940d65dc0eSdrh} { 1950d65dc0eSdrh do_test conflict-4.$i { 1960d65dc0eSdrh if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} 1970d65dc0eSdrh if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"} 1980d65dc0eSdrh set r0 [catch {execsql [subst { 1990d65dc0eSdrh DROP TABLE t1; 2000d65dc0eSdrh CREATE TABLE t1(a,b,c,UNIQUE(a,b) $conf1); 2010d65dc0eSdrh DELETE FROM t2; 2020d65dc0eSdrh INSERT INTO t1 VALUES(1,2,3); 2030d65dc0eSdrh BEGIN $conf2; 2040d65dc0eSdrh INSERT INTO t2 VALUES(1); 2050d65dc0eSdrh $cmd INTO t1 VALUES(1,2,4); 2060d65dc0eSdrh }]} r1] 2076b8b8749Sdrh catch {execsql {COMMIT}} 2080d65dc0eSdrh if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]} 2090d65dc0eSdrh set r2 [execsql {SELECT x FROM t2}] 2100d65dc0eSdrh list $r0 $r1 $r2 2110d65dc0eSdrh } [list $t0 $t1 $t2] 212ef6764a1Sdrh} 2130d65dc0eSdrh 2140d65dc0eSdrhdo_test conflict-5.0 { 2150d65dc0eSdrh execsql { 2160d65dc0eSdrh DROP TABLE t2; 2170d65dc0eSdrh CREATE TABLE t2(x); 2180d65dc0eSdrh SELECT x FROM t2; 2190d65dc0eSdrh } 2200d65dc0eSdrh} {} 2210d65dc0eSdrh 2220d65dc0eSdrh# Six columns of configuration data as follows: 2230d65dc0eSdrh# 2240d65dc0eSdrh# i The reference number of the test 2250d65dc0eSdrh# conf1 The conflict resolution algorithm on the NOT NULL constraint 2260d65dc0eSdrh# conf2 The conflict resolution algorithm on the BEGIN statement 2270d65dc0eSdrh# cmd An INSERT or REPLACE command to execute against table t1 2280d65dc0eSdrh# t0 True if there is an error from $cmd 2290d65dc0eSdrh# t1 Content of "c" column of t1 assuming no error in $cmd 2300d65dc0eSdrh# t2 Content of "x" column of t2 2310d65dc0eSdrh# 2320d65dc0eSdrhforeach {i conf1 conf2 cmd t0 t1 t2} { 2330d65dc0eSdrh 1 {} {} INSERT 1 {} 1 2340d65dc0eSdrh 2 REPLACE {} INSERT 0 5 1 2350d65dc0eSdrh 3 IGNORE {} INSERT 0 {} 1 2360d65dc0eSdrh 4 FAIL {} INSERT 1 {} 1 2370d65dc0eSdrh 5 ABORT {} INSERT 1 {} 1 2380d65dc0eSdrh 6 ROLLBACK {} INSERT 1 {} {} 2390d65dc0eSdrh 7 REPLACE {} {INSERT OR IGNORE} 0 {} 1 2400d65dc0eSdrh 8 IGNORE {} {INSERT OR REPLACE} 0 5 1 2410d65dc0eSdrh 9 FAIL {} {INSERT OR IGNORE} 0 {} 1 2420d65dc0eSdrh 10 ABORT {} {INSERT OR REPLACE} 0 5 1 2430d65dc0eSdrh 11 ROLLBACK {} {INSERT OR IGNORE} 0 {} 1 2440d65dc0eSdrh 12 {} {} {INSERT OR IGNORE} 0 {} 1 2450d65dc0eSdrh 13 {} {} {INSERT OR REPLACE} 0 5 1 2460d65dc0eSdrh 14 {} {} {INSERT OR FAIL} 1 {} 1 2470d65dc0eSdrh 15 {} {} {INSERT OR ABORT} 1 {} 1 2480d65dc0eSdrh 16 {} {} {INSERT OR ROLLBACK} 1 {} {} 2490d65dc0eSdrh} { 250483750baSdrh if {$t0} {set t1 {t1.c may not be NULL}} 2510d65dc0eSdrh do_test conflict-5.$i { 2520d65dc0eSdrh if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} 2530d65dc0eSdrh if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"} 2540d65dc0eSdrh set r0 [catch {execsql [subst { 2550d65dc0eSdrh DROP TABLE t1; 2560d65dc0eSdrh CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5); 2570d65dc0eSdrh DELETE FROM t2; 2580d65dc0eSdrh BEGIN $conf2; 2590d65dc0eSdrh INSERT INTO t2 VALUES(1); 2600d65dc0eSdrh $cmd INTO t1 VALUES(1,2,NULL); 2610d65dc0eSdrh }]} r1] 2626b8b8749Sdrh catch {execsql {COMMIT}} 2630d65dc0eSdrh if {!$r0} {set r1 [execsql {SELECT c FROM t1}]} 2640d65dc0eSdrh set r2 [execsql {SELECT x FROM t2}] 2650d65dc0eSdrh list $r0 $r1 $r2 2660d65dc0eSdrh } [list $t0 $t1 $t2] 2670d65dc0eSdrh} 2680d65dc0eSdrh 2690d65dc0eSdrhdo_test conflict-6.0 { 2700d65dc0eSdrh execsql { 2710d65dc0eSdrh DROP TABLE t2; 2720d65dc0eSdrh CREATE TABLE t2(a,b,c); 2730d65dc0eSdrh INSERT INTO t2 VALUES(1,2,1); 2740d65dc0eSdrh INSERT INTO t2 VALUES(2,3,2); 2750d65dc0eSdrh INSERT INTO t2 VALUES(3,4,1); 2760d65dc0eSdrh INSERT INTO t2 VALUES(4,5,4); 2770d65dc0eSdrh SELECT c FROM t2 ORDER BY b; 2780d65dc0eSdrh CREATE TABLE t3(x); 2790d65dc0eSdrh INSERT INTO t3 VALUES(1); 2800d65dc0eSdrh } 2810d65dc0eSdrh} {1 2 1 4} 2820d65dc0eSdrh 2830d65dc0eSdrh# Six columns of configuration data as follows: 2840d65dc0eSdrh# 2850d65dc0eSdrh# i The reference number of the test 2860d65dc0eSdrh# conf1 The conflict resolution algorithm on the UNIQUE constraint 2870d65dc0eSdrh# conf2 The conflict resolution algorithm on the BEGIN statement 2880d65dc0eSdrh# cmd An UPDATE command to execute against table t1 2890d65dc0eSdrh# t0 True if there is an error from $cmd 2900d65dc0eSdrh# t1 Content of "b" column of t1 assuming no error in $cmd 2910d65dc0eSdrh# t2 Content of "x" column of t3 2920d65dc0eSdrh# 2930d65dc0eSdrhforeach {i conf1 conf2 cmd t0 t1 t2} { 2940d65dc0eSdrh 1 {} {} UPDATE 1 {6 7 8 9} 1 2950d65dc0eSdrh 2 REPLACE {} UPDATE 0 {7 6 9} 1 2960d65dc0eSdrh 3 IGNORE {} UPDATE 0 {6 7 3 9} 1 2970d65dc0eSdrh 4 FAIL {} UPDATE 1 {6 7 3 4} 1 2980d65dc0eSdrh 5 ABORT {} UPDATE 1 {1 2 3 4} 1 2990d65dc0eSdrh 6 ROLLBACK {} UPDATE 1 {1 2 3 4} 0 3000d65dc0eSdrh 7 REPLACE {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 3010d65dc0eSdrh 8 IGNORE {} {UPDATE OR REPLACE} 0 {7 6 9} 1 3020d65dc0eSdrh 9 FAIL {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 3030d65dc0eSdrh 10 ABORT {} {UPDATE OR REPLACE} 0 {7 6 9} 1 3040d65dc0eSdrh 11 ROLLBACK {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 3050d65dc0eSdrh 12 {} {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 3060d65dc0eSdrh 13 {} {} {UPDATE OR REPLACE} 0 {7 6 9} 1 3070d65dc0eSdrh 14 {} {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 3080d65dc0eSdrh 15 {} {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 3090d65dc0eSdrh 16 {} {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 3100d65dc0eSdrh} { 31137ed48edSdrh if {$t0} {set t1 {column a is not unique}} 3120d65dc0eSdrh do_test conflict-6.$i { 3130d65dc0eSdrh if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"} 3140d65dc0eSdrh if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"} 3150d65dc0eSdrh set r0 [catch {execsql [subst { 3160d65dc0eSdrh DROP TABLE t1; 3170d65dc0eSdrh CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1); 3180d65dc0eSdrh INSERT INTO t1 SELECT * FROM t2; 3190d65dc0eSdrh UPDATE t3 SET x=0; 3200d65dc0eSdrh BEGIN $conf2; 3210d65dc0eSdrh $cmd t3 SET x=1; 3221dd397f0Sdrh $cmd t1 SET b=b*2; 3230d65dc0eSdrh $cmd t1 SET a=c+5; 3240d65dc0eSdrh }]} r1] 3256b8b8749Sdrh catch {execsql {COMMIT}} 3260d65dc0eSdrh if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]} 3270d65dc0eSdrh set r2 [execsql {SELECT x FROM t3}] 3280d65dc0eSdrh list $r0 $r1 $r2 3290d65dc0eSdrh } [list $t0 $t1 $t2] 3300d65dc0eSdrh} 331ef6764a1Sdrh 332fe1a1773Sdrh# Test to make sure a lot of IGNOREs don't cause a stack overflow 333fe1a1773Sdrh# 334fe1a1773Sdrhdo_test conflict-7.1 { 335fe1a1773Sdrh execsql { 336fe1a1773Sdrh DROP TABLE t1; 337fe1a1773Sdrh DROP TABLE t2; 338fe1a1773Sdrh DROP TABLE t3; 339fe1a1773Sdrh CREATE TABLE t1(a unique, b); 340fe1a1773Sdrh } 341fe1a1773Sdrh for {set i 1} {$i<=50} {incr i} { 342fe1a1773Sdrh execsql "INSERT into t1 values($i,[expr {$i+1}]);" 343fe1a1773Sdrh } 344fe1a1773Sdrh execsql { 345fe1a1773Sdrh SELECT count(*), min(a), max(b) FROM t1; 346fe1a1773Sdrh } 347fe1a1773Sdrh} {50 1 51} 348fe1a1773Sdrhdo_test conflict-7.2 { 349fe1a1773Sdrh execsql { 350fe1a1773Sdrh PRAGMA count_changes=on; 351fe1a1773Sdrh UPDATE OR IGNORE t1 SET a=1000; 352fe1a1773Sdrh } 353fe1a1773Sdrh} {1} 354c8d30ac1Sdrhdo_test conflict-7.2.1 { 355c8d30ac1Sdrh db changes 356c8d30ac1Sdrh} {1} 357fe1a1773Sdrhdo_test conflict-7.3 { 358fe1a1773Sdrh execsql { 359fe1a1773Sdrh SELECT b FROM t1 WHERE a=1000; 360fe1a1773Sdrh } 361fe1a1773Sdrh} {2} 362fe1a1773Sdrhdo_test conflict-7.4 { 363fe1a1773Sdrh execsql { 364fe1a1773Sdrh SELECT count(*) FROM t1; 365fe1a1773Sdrh } 366fe1a1773Sdrh} {50} 367fe1a1773Sdrhdo_test conflict-7.5 { 368fe1a1773Sdrh execsql { 369fe1a1773Sdrh PRAGMA count_changes=on; 370fe1a1773Sdrh UPDATE OR REPLACE t1 SET a=1001; 371fe1a1773Sdrh } 372fe1a1773Sdrh} {50} 373c8d30ac1Sdrhdo_test conflict-7.5.1 { 374c8d30ac1Sdrh db changes 375c8d30ac1Sdrh} {50} 376fe1a1773Sdrhdo_test conflict-7.6 { 377fe1a1773Sdrh execsql { 378fe1a1773Sdrh SELECT b FROM t1 WHERE a=1001; 379fe1a1773Sdrh } 380fe1a1773Sdrh} {51} 381fe1a1773Sdrhdo_test conflict-7.7 { 382fe1a1773Sdrh execsql { 383fe1a1773Sdrh SELECT count(*) FROM t1; 384fe1a1773Sdrh } 385fe1a1773Sdrh} {1} 386c8d30ac1Sdrhdo_test conflict-7.7.1 { 387c8d30ac1Sdrh db changes 388c8d30ac1Sdrh} {0} 389fe1a1773Sdrh 390feeb1394Sdrh# Make sure the row count is right for rows that are ignored on 391feeb1394Sdrh# an insert. 392feeb1394Sdrh# 393feeb1394Sdrhdo_test conflict-8.1 { 394feeb1394Sdrh execsql { 395feeb1394Sdrh DELETE FROM t1; 396feeb1394Sdrh INSERT INTO t1 VALUES(1,2); 397feeb1394Sdrh } 398feeb1394Sdrh execsql { 399feeb1394Sdrh INSERT OR IGNORE INTO t1 VALUES(2,3); 400feeb1394Sdrh } 401feeb1394Sdrh} {1} 402c8d30ac1Sdrhdo_test conflict-8.1.1 { 403c8d30ac1Sdrh db changes 404c8d30ac1Sdrh} {1} 405feeb1394Sdrhdo_test conflict-8.2 { 406feeb1394Sdrh execsql { 407feeb1394Sdrh INSERT OR IGNORE INTO t1 VALUES(2,4); 408feeb1394Sdrh } 409feeb1394Sdrh} {0} 410c8d30ac1Sdrhdo_test conflict-8.2.1 { 411c8d30ac1Sdrh db changes 412c8d30ac1Sdrh} {0} 413feeb1394Sdrhdo_test conflict-8.3 { 414feeb1394Sdrh execsql { 415feeb1394Sdrh INSERT OR REPLACE INTO t1 VALUES(2,4); 416feeb1394Sdrh } 417feeb1394Sdrh} {1} 418c8d30ac1Sdrhdo_test conflict-8.3.1 { 419c8d30ac1Sdrh db changes 420c8d30ac1Sdrh} {1} 421feeb1394Sdrhdo_test conflict-8.4 { 422feeb1394Sdrh execsql { 423feeb1394Sdrh INSERT OR IGNORE INTO t1 SELECT * FROM t1; 424feeb1394Sdrh } 425feeb1394Sdrh} {0} 426c8d30ac1Sdrhdo_test conflict-8.4.1 { 427c8d30ac1Sdrh db changes 428c8d30ac1Sdrh} {0} 429feeb1394Sdrhdo_test conflict-8.5 { 430feeb1394Sdrh execsql { 431feeb1394Sdrh INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1; 432feeb1394Sdrh } 433feeb1394Sdrh} {2} 434c8d30ac1Sdrhdo_test conflict-8.5.1 { 435c8d30ac1Sdrh db changes 436c8d30ac1Sdrh} {2} 437feeb1394Sdrhdo_test conflict-8.6 { 438feeb1394Sdrh execsql { 439feeb1394Sdrh INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1; 440feeb1394Sdrh } 441feeb1394Sdrh} {3} 442c8d30ac1Sdrhdo_test conflict-8.6.1 { 443c8d30ac1Sdrh db changes 444c8d30ac1Sdrh} {3} 445fe1a1773Sdrh 4463b167c75Sdrhintegrity_check conflict-8.99 4473b167c75Sdrh 4483b167c75Sdrhdo_test conflict-9.1 { 4493b167c75Sdrh execsql { 4503b167c75Sdrh PRAGMA count_changes=0; 4513b167c75Sdrh CREATE TABLE t2( 4523b167c75Sdrh a INTEGER UNIQUE ON CONFLICT IGNORE, 4533b167c75Sdrh b INTEGER UNIQUE ON CONFLICT FAIL, 4543b167c75Sdrh c INTEGER UNIQUE ON CONFLICT REPLACE, 4553b167c75Sdrh d INTEGER UNIQUE ON CONFLICT ABORT, 4563b167c75Sdrh e INTEGER UNIQUE ON CONFLICT ROLLBACK 4573b167c75Sdrh ); 4583b167c75Sdrh CREATE TABLE t3(x); 4593b167c75Sdrh INSERT INTO t3 VALUES(1); 4603b167c75Sdrh SELECT * FROM t3; 4613b167c75Sdrh } 4623b167c75Sdrh} {1} 4633b167c75Sdrhdo_test conflict-9.2 { 4643b167c75Sdrh catchsql { 4653b167c75Sdrh INSERT INTO t2 VALUES(1,1,1,1,1); 4663b167c75Sdrh INSERT INTO t2 VALUES(2,2,2,2,2); 4673b167c75Sdrh SELECT * FROM t2; 4683b167c75Sdrh } 4693b167c75Sdrh} {0 {1 1 1 1 1 2 2 2 2 2}} 4703b167c75Sdrhdo_test conflict-9.3 { 4713b167c75Sdrh catchsql { 4723b167c75Sdrh INSERT INTO t2 VALUES(1,3,3,3,3); 4733b167c75Sdrh SELECT * FROM t2; 4743b167c75Sdrh } 4753b167c75Sdrh} {0 {1 1 1 1 1 2 2 2 2 2}} 4763b167c75Sdrhdo_test conflict-9.4 { 4773b167c75Sdrh catchsql { 4783b167c75Sdrh UPDATE t2 SET a=a+1 WHERE a=1; 4793b167c75Sdrh SELECT * FROM t2; 4803b167c75Sdrh } 4813b167c75Sdrh} {0 {1 1 1 1 1 2 2 2 2 2}} 4823b167c75Sdrhdo_test conflict-9.5 { 4833b167c75Sdrh catchsql { 4843b167c75Sdrh INSERT INTO t2 VALUES(3,1,3,3,3); 4853b167c75Sdrh SELECT * FROM t2; 4863b167c75Sdrh } 48737ed48edSdrh} {1 {column b is not unique}} 4883b167c75Sdrhdo_test conflict-9.6 { 4893b167c75Sdrh catchsql { 4903b167c75Sdrh UPDATE t2 SET b=b+1 WHERE b=1; 4913b167c75Sdrh SELECT * FROM t2; 4923b167c75Sdrh } 49337ed48edSdrh} {1 {column b is not unique}} 4943b167c75Sdrhdo_test conflict-9.7 { 4953b167c75Sdrh catchsql { 4963b167c75Sdrh BEGIN; 4973b167c75Sdrh UPDATE t3 SET x=x+1; 4983b167c75Sdrh INSERT INTO t2 VALUES(3,1,3,3,3); 4993b167c75Sdrh SELECT * FROM t2; 5003b167c75Sdrh } 50137ed48edSdrh} {1 {column b is not unique}} 5023b167c75Sdrhdo_test conflict-9.8 { 5033b167c75Sdrh execsql {COMMIT} 5043b167c75Sdrh execsql {SELECT * FROM t3} 5053b167c75Sdrh} {2} 506483750baSdrhdo_test conflict-9.9 { 5073b167c75Sdrh catchsql { 5083b167c75Sdrh BEGIN; 5093b167c75Sdrh UPDATE t3 SET x=x+1; 5103b167c75Sdrh UPDATE t2 SET b=b+1 WHERE b=1; 5113b167c75Sdrh SELECT * FROM t2; 5123b167c75Sdrh } 51337ed48edSdrh} {1 {column b is not unique}} 5143b167c75Sdrhdo_test conflict-9.10 { 5153b167c75Sdrh execsql {COMMIT} 5163b167c75Sdrh execsql {SELECT * FROM t3} 5173b167c75Sdrh} {3} 5183b167c75Sdrhdo_test conflict-9.11 { 5193b167c75Sdrh catchsql { 5203b167c75Sdrh INSERT INTO t2 VALUES(3,3,3,1,3); 5213b167c75Sdrh SELECT * FROM t2; 5223b167c75Sdrh } 52337ed48edSdrh} {1 {column d is not unique}} 5243b167c75Sdrhdo_test conflict-9.12 { 5253b167c75Sdrh catchsql { 5263b167c75Sdrh UPDATE t2 SET d=d+1 WHERE d=1; 5273b167c75Sdrh SELECT * FROM t2; 5283b167c75Sdrh } 52937ed48edSdrh} {1 {column d is not unique}} 5303b167c75Sdrhdo_test conflict-9.13 { 5313b167c75Sdrh catchsql { 5323b167c75Sdrh BEGIN; 5333b167c75Sdrh UPDATE t3 SET x=x+1; 5343b167c75Sdrh INSERT INTO t2 VALUES(3,3,3,1,3); 5353b167c75Sdrh SELECT * FROM t2; 5363b167c75Sdrh } 53737ed48edSdrh} {1 {column d is not unique}} 5383b167c75Sdrhdo_test conflict-9.14 { 5393b167c75Sdrh execsql {COMMIT} 5403b167c75Sdrh execsql {SELECT * FROM t3} 5413b167c75Sdrh} {4} 5423b167c75Sdrhdo_test conflict-9.15 { 5433b167c75Sdrh catchsql { 5443b167c75Sdrh BEGIN; 5453b167c75Sdrh UPDATE t3 SET x=x+1; 5463b167c75Sdrh UPDATE t2 SET d=d+1 WHERE d=1; 5473b167c75Sdrh SELECT * FROM t2; 5483b167c75Sdrh } 54937ed48edSdrh} {1 {column d is not unique}} 5503b167c75Sdrhdo_test conflict-9.16 { 5513b167c75Sdrh execsql {COMMIT} 5523b167c75Sdrh execsql {SELECT * FROM t3} 5533b167c75Sdrh} {5} 5543b167c75Sdrhdo_test conflict-9.17 { 5553b167c75Sdrh catchsql { 5563b167c75Sdrh INSERT INTO t2 VALUES(3,3,3,3,1); 5573b167c75Sdrh SELECT * FROM t2; 5583b167c75Sdrh } 55937ed48edSdrh} {1 {column e is not unique}} 5603b167c75Sdrhdo_test conflict-9.18 { 5613b167c75Sdrh catchsql { 5623b167c75Sdrh UPDATE t2 SET e=e+1 WHERE e=1; 5633b167c75Sdrh SELECT * FROM t2; 5643b167c75Sdrh } 56537ed48edSdrh} {1 {column e is not unique}} 5663b167c75Sdrhdo_test conflict-9.19 { 5673b167c75Sdrh catchsql { 5683b167c75Sdrh BEGIN; 5693b167c75Sdrh UPDATE t3 SET x=x+1; 5703b167c75Sdrh INSERT INTO t2 VALUES(3,3,3,3,1); 5713b167c75Sdrh SELECT * FROM t2; 5723b167c75Sdrh } 57337ed48edSdrh} {1 {column e is not unique}} 5743b167c75Sdrhdo_test conflict-9.20 { 5756b8b8749Sdrh catch {execsql {COMMIT}} 5763b167c75Sdrh execsql {SELECT * FROM t3} 5773b167c75Sdrh} {5} 5783b167c75Sdrhdo_test conflict-9.21 { 5793b167c75Sdrh catchsql { 5803b167c75Sdrh BEGIN; 5813b167c75Sdrh UPDATE t3 SET x=x+1; 5823b167c75Sdrh UPDATE t2 SET e=e+1 WHERE e=1; 5833b167c75Sdrh SELECT * FROM t2; 5843b167c75Sdrh } 58537ed48edSdrh} {1 {column e is not unique}} 5863b167c75Sdrhdo_test conflict-9.22 { 5876b8b8749Sdrh catch {execsql {COMMIT}} 5883b167c75Sdrh execsql {SELECT * FROM t3} 5893b167c75Sdrh} {5} 5903b167c75Sdrhdo_test conflict-9.23 { 5913b167c75Sdrh catchsql { 5923b167c75Sdrh INSERT INTO t2 VALUES(3,3,1,3,3); 5933b167c75Sdrh SELECT * FROM t2; 5943b167c75Sdrh } 5953b167c75Sdrh} {0 {2 2 2 2 2 3 3 1 3 3}} 5963b167c75Sdrhdo_test conflict-9.24 { 5973b167c75Sdrh catchsql { 5983b167c75Sdrh UPDATE t2 SET c=c-1 WHERE c=2; 5993b167c75Sdrh SELECT * FROM t2; 6003b167c75Sdrh } 6013b167c75Sdrh} {0 {2 2 1 2 2}} 6023b167c75Sdrhdo_test conflict-9.25 { 6033b167c75Sdrh catchsql { 6043b167c75Sdrh BEGIN; 6053b167c75Sdrh UPDATE t3 SET x=x+1; 6063b167c75Sdrh INSERT INTO t2 VALUES(3,3,1,3,3); 6073b167c75Sdrh SELECT * FROM t2; 6083b167c75Sdrh } 6093b167c75Sdrh} {0 {3 3 1 3 3}} 6103b167c75Sdrhdo_test conflict-9.26 { 6116b8b8749Sdrh catch {execsql {COMMIT}} 6123b167c75Sdrh execsql {SELECT * FROM t3} 6133b167c75Sdrh} {6} 614bb37fdc7Sdrh 615a996e477Sdrhdo_test conflict-10.1 { 616a996e477Sdrh catchsql { 617a996e477Sdrh DELETE FROM t1; 618*33752f8aSdanielk1977 BEGIN; 619*33752f8aSdanielk1977 INSERT OR ROLLBACK INTO t1 VALUES(1,2); 620*33752f8aSdanielk1977 INSERT OR ROLLBACK INTO t1 VALUES(1,3); 621a996e477Sdrh COMMIT; 622a996e477Sdrh } 623a996e477Sdrh execsql {SELECT * FROM t1} 624a996e477Sdrh} {} 625a996e477Sdrhdo_test conflict-10.2 { 626a996e477Sdrh catchsql { 627a996e477Sdrh CREATE TABLE t4(x); 628a996e477Sdrh CREATE UNIQUE INDEX t4x ON t4(x); 629*33752f8aSdanielk1977 BEGIN; 630*33752f8aSdanielk1977 INSERT OR ROLLBACK INTO t4 VALUES(1); 631*33752f8aSdanielk1977 INSERT OR ROLLBACK INTO t4 VALUES(1); 632a996e477Sdrh COMMIT; 633a996e477Sdrh } 634a996e477Sdrh execsql {SELECT * FROM t4} 635a996e477Sdrh} {} 636a996e477Sdrh 637ed717fe3Sdrhintegrity_check conflict-99.0 638ed717fe3Sdrh 639bb37fdc7Sdrhfinish_test 640