xref: /sqlite-3.40.0/test/conflict.test (revision b28af71a)
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*b28af71aSdanielk1977# $Id: conflict.test,v 1.22 2004/06/21 06:50:29 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}
386*b28af71aSdanielk1977
387*b28af71aSdanielk1977# Update for version 3: A SELECT statement no longer resets the change
388*b28af71aSdanielk1977# counter (Test result changes from 0 to 50).
389c8d30ac1Sdrhdo_test conflict-7.7.1 {
390c8d30ac1Sdrh  db changes
391*b28af71aSdanielk1977} {50}
392fe1a1773Sdrh
393feeb1394Sdrh# Make sure the row count is right for rows that are ignored on
394feeb1394Sdrh# an insert.
395feeb1394Sdrh#
396feeb1394Sdrhdo_test conflict-8.1 {
397feeb1394Sdrh  execsql {
398feeb1394Sdrh    DELETE FROM t1;
399feeb1394Sdrh    INSERT INTO t1 VALUES(1,2);
400feeb1394Sdrh  }
401feeb1394Sdrh  execsql {
402feeb1394Sdrh    INSERT OR IGNORE INTO t1 VALUES(2,3);
403feeb1394Sdrh  }
404feeb1394Sdrh} {1}
405c8d30ac1Sdrhdo_test conflict-8.1.1 {
406c8d30ac1Sdrh  db changes
407c8d30ac1Sdrh} {1}
408feeb1394Sdrhdo_test conflict-8.2 {
409feeb1394Sdrh  execsql {
410feeb1394Sdrh    INSERT OR IGNORE INTO t1 VALUES(2,4);
411feeb1394Sdrh  }
412feeb1394Sdrh} {0}
413c8d30ac1Sdrhdo_test conflict-8.2.1 {
414c8d30ac1Sdrh  db changes
415c8d30ac1Sdrh} {0}
416feeb1394Sdrhdo_test conflict-8.3 {
417feeb1394Sdrh  execsql {
418feeb1394Sdrh    INSERT OR REPLACE INTO t1 VALUES(2,4);
419feeb1394Sdrh  }
420feeb1394Sdrh} {1}
421c8d30ac1Sdrhdo_test conflict-8.3.1 {
422c8d30ac1Sdrh  db changes
423c8d30ac1Sdrh} {1}
424feeb1394Sdrhdo_test conflict-8.4 {
425feeb1394Sdrh  execsql {
426feeb1394Sdrh    INSERT OR IGNORE INTO t1 SELECT * FROM t1;
427feeb1394Sdrh  }
428feeb1394Sdrh} {0}
429c8d30ac1Sdrhdo_test conflict-8.4.1 {
430c8d30ac1Sdrh  db changes
431c8d30ac1Sdrh} {0}
432feeb1394Sdrhdo_test conflict-8.5 {
433feeb1394Sdrh  execsql {
434feeb1394Sdrh    INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1;
435feeb1394Sdrh  }
436feeb1394Sdrh} {2}
437c8d30ac1Sdrhdo_test conflict-8.5.1 {
438c8d30ac1Sdrh  db changes
439c8d30ac1Sdrh} {2}
440feeb1394Sdrhdo_test conflict-8.6 {
441feeb1394Sdrh  execsql {
442feeb1394Sdrh    INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1;
443feeb1394Sdrh  }
444feeb1394Sdrh} {3}
445c8d30ac1Sdrhdo_test conflict-8.6.1 {
446c8d30ac1Sdrh  db changes
447c8d30ac1Sdrh} {3}
448fe1a1773Sdrh
4493b167c75Sdrhintegrity_check conflict-8.99
4503b167c75Sdrh
4513b167c75Sdrhdo_test conflict-9.1 {
4523b167c75Sdrh  execsql {
4533b167c75Sdrh    PRAGMA count_changes=0;
4543b167c75Sdrh    CREATE TABLE t2(
4553b167c75Sdrh      a INTEGER UNIQUE ON CONFLICT IGNORE,
4563b167c75Sdrh      b INTEGER UNIQUE ON CONFLICT FAIL,
4573b167c75Sdrh      c INTEGER UNIQUE ON CONFLICT REPLACE,
4583b167c75Sdrh      d INTEGER UNIQUE ON CONFLICT ABORT,
4593b167c75Sdrh      e INTEGER UNIQUE ON CONFLICT ROLLBACK
4603b167c75Sdrh    );
4613b167c75Sdrh    CREATE TABLE t3(x);
4623b167c75Sdrh    INSERT INTO t3 VALUES(1);
4633b167c75Sdrh    SELECT * FROM t3;
4643b167c75Sdrh  }
4653b167c75Sdrh} {1}
4663b167c75Sdrhdo_test conflict-9.2 {
4673b167c75Sdrh  catchsql {
4683b167c75Sdrh    INSERT INTO t2 VALUES(1,1,1,1,1);
4693b167c75Sdrh    INSERT INTO t2 VALUES(2,2,2,2,2);
4703b167c75Sdrh    SELECT * FROM t2;
4713b167c75Sdrh  }
4723b167c75Sdrh} {0 {1 1 1 1 1 2 2 2 2 2}}
4733b167c75Sdrhdo_test conflict-9.3 {
4743b167c75Sdrh  catchsql {
4753b167c75Sdrh    INSERT INTO t2 VALUES(1,3,3,3,3);
4763b167c75Sdrh    SELECT * FROM t2;
4773b167c75Sdrh  }
4783b167c75Sdrh} {0 {1 1 1 1 1 2 2 2 2 2}}
4793b167c75Sdrhdo_test conflict-9.4 {
4803b167c75Sdrh  catchsql {
4813b167c75Sdrh    UPDATE t2 SET a=a+1 WHERE a=1;
4823b167c75Sdrh    SELECT * FROM t2;
4833b167c75Sdrh  }
4843b167c75Sdrh} {0 {1 1 1 1 1 2 2 2 2 2}}
4853b167c75Sdrhdo_test conflict-9.5 {
4863b167c75Sdrh  catchsql {
4873b167c75Sdrh    INSERT INTO t2 VALUES(3,1,3,3,3);
4883b167c75Sdrh    SELECT * FROM t2;
4893b167c75Sdrh  }
49037ed48edSdrh} {1 {column b is not unique}}
4913b167c75Sdrhdo_test conflict-9.6 {
4923b167c75Sdrh  catchsql {
4933b167c75Sdrh    UPDATE t2 SET b=b+1 WHERE b=1;
4943b167c75Sdrh    SELECT * FROM t2;
4953b167c75Sdrh  }
49637ed48edSdrh} {1 {column b is not unique}}
4973b167c75Sdrhdo_test conflict-9.7 {
4983b167c75Sdrh  catchsql {
4993b167c75Sdrh    BEGIN;
5003b167c75Sdrh    UPDATE t3 SET x=x+1;
5013b167c75Sdrh    INSERT INTO t2 VALUES(3,1,3,3,3);
5023b167c75Sdrh    SELECT * FROM t2;
5033b167c75Sdrh  }
50437ed48edSdrh} {1 {column b is not unique}}
5053b167c75Sdrhdo_test conflict-9.8 {
5063b167c75Sdrh  execsql {COMMIT}
5073b167c75Sdrh  execsql {SELECT * FROM t3}
5083b167c75Sdrh} {2}
509483750baSdrhdo_test conflict-9.9 {
5103b167c75Sdrh  catchsql {
5113b167c75Sdrh    BEGIN;
5123b167c75Sdrh    UPDATE t3 SET x=x+1;
5133b167c75Sdrh    UPDATE t2 SET b=b+1 WHERE b=1;
5143b167c75Sdrh    SELECT * FROM t2;
5153b167c75Sdrh  }
51637ed48edSdrh} {1 {column b is not unique}}
5173b167c75Sdrhdo_test conflict-9.10 {
5183b167c75Sdrh  execsql {COMMIT}
5193b167c75Sdrh  execsql {SELECT * FROM t3}
5203b167c75Sdrh} {3}
5213b167c75Sdrhdo_test conflict-9.11 {
5223b167c75Sdrh  catchsql {
5233b167c75Sdrh    INSERT INTO t2 VALUES(3,3,3,1,3);
5243b167c75Sdrh    SELECT * FROM t2;
5253b167c75Sdrh  }
52637ed48edSdrh} {1 {column d is not unique}}
5273b167c75Sdrhdo_test conflict-9.12 {
5283b167c75Sdrh  catchsql {
5293b167c75Sdrh    UPDATE t2 SET d=d+1 WHERE d=1;
5303b167c75Sdrh    SELECT * FROM t2;
5313b167c75Sdrh  }
53237ed48edSdrh} {1 {column d is not unique}}
5333b167c75Sdrhdo_test conflict-9.13 {
5343b167c75Sdrh  catchsql {
5353b167c75Sdrh    BEGIN;
5363b167c75Sdrh    UPDATE t3 SET x=x+1;
5373b167c75Sdrh    INSERT INTO t2 VALUES(3,3,3,1,3);
5383b167c75Sdrh    SELECT * FROM t2;
5393b167c75Sdrh  }
54037ed48edSdrh} {1 {column d is not unique}}
5413b167c75Sdrhdo_test conflict-9.14 {
5423b167c75Sdrh  execsql {COMMIT}
5433b167c75Sdrh  execsql {SELECT * FROM t3}
5443b167c75Sdrh} {4}
5453b167c75Sdrhdo_test conflict-9.15 {
5463b167c75Sdrh  catchsql {
5473b167c75Sdrh    BEGIN;
5483b167c75Sdrh    UPDATE t3 SET x=x+1;
5493b167c75Sdrh    UPDATE t2 SET d=d+1 WHERE d=1;
5503b167c75Sdrh    SELECT * FROM t2;
5513b167c75Sdrh  }
55237ed48edSdrh} {1 {column d is not unique}}
5533b167c75Sdrhdo_test conflict-9.16 {
5543b167c75Sdrh  execsql {COMMIT}
5553b167c75Sdrh  execsql {SELECT * FROM t3}
5563b167c75Sdrh} {5}
5573b167c75Sdrhdo_test conflict-9.17 {
5583b167c75Sdrh  catchsql {
5593b167c75Sdrh    INSERT INTO t2 VALUES(3,3,3,3,1);
5603b167c75Sdrh    SELECT * FROM t2;
5613b167c75Sdrh  }
56237ed48edSdrh} {1 {column e is not unique}}
5633b167c75Sdrhdo_test conflict-9.18 {
5643b167c75Sdrh  catchsql {
5653b167c75Sdrh    UPDATE t2 SET e=e+1 WHERE e=1;
5663b167c75Sdrh    SELECT * FROM t2;
5673b167c75Sdrh  }
56837ed48edSdrh} {1 {column e is not unique}}
5693b167c75Sdrhdo_test conflict-9.19 {
5703b167c75Sdrh  catchsql {
5713b167c75Sdrh    BEGIN;
5723b167c75Sdrh    UPDATE t3 SET x=x+1;
5733b167c75Sdrh    INSERT INTO t2 VALUES(3,3,3,3,1);
5743b167c75Sdrh    SELECT * FROM t2;
5753b167c75Sdrh  }
57637ed48edSdrh} {1 {column e is not unique}}
5773b167c75Sdrhdo_test conflict-9.20 {
5786b8b8749Sdrh  catch {execsql {COMMIT}}
5793b167c75Sdrh  execsql {SELECT * FROM t3}
5803b167c75Sdrh} {5}
5813b167c75Sdrhdo_test conflict-9.21 {
5823b167c75Sdrh  catchsql {
5833b167c75Sdrh    BEGIN;
5843b167c75Sdrh    UPDATE t3 SET x=x+1;
5853b167c75Sdrh    UPDATE t2 SET e=e+1 WHERE e=1;
5863b167c75Sdrh    SELECT * FROM t2;
5873b167c75Sdrh  }
58837ed48edSdrh} {1 {column e is not unique}}
5893b167c75Sdrhdo_test conflict-9.22 {
5906b8b8749Sdrh  catch {execsql {COMMIT}}
5913b167c75Sdrh  execsql {SELECT * FROM t3}
5923b167c75Sdrh} {5}
5933b167c75Sdrhdo_test conflict-9.23 {
5943b167c75Sdrh  catchsql {
5953b167c75Sdrh    INSERT INTO t2 VALUES(3,3,1,3,3);
5963b167c75Sdrh    SELECT * FROM t2;
5973b167c75Sdrh  }
5983b167c75Sdrh} {0 {2 2 2 2 2 3 3 1 3 3}}
5993b167c75Sdrhdo_test conflict-9.24 {
6003b167c75Sdrh  catchsql {
6013b167c75Sdrh    UPDATE t2 SET c=c-1 WHERE c=2;
6023b167c75Sdrh    SELECT * FROM t2;
6033b167c75Sdrh  }
6043b167c75Sdrh} {0 {2 2 1 2 2}}
6053b167c75Sdrhdo_test conflict-9.25 {
6063b167c75Sdrh  catchsql {
6073b167c75Sdrh    BEGIN;
6083b167c75Sdrh    UPDATE t3 SET x=x+1;
6093b167c75Sdrh    INSERT INTO t2 VALUES(3,3,1,3,3);
6103b167c75Sdrh    SELECT * FROM t2;
6113b167c75Sdrh  }
6123b167c75Sdrh} {0 {3 3 1 3 3}}
6133b167c75Sdrhdo_test conflict-9.26 {
6146b8b8749Sdrh  catch {execsql {COMMIT}}
6153b167c75Sdrh  execsql {SELECT * FROM t3}
6163b167c75Sdrh} {6}
617bb37fdc7Sdrh
618a996e477Sdrhdo_test conflict-10.1 {
619a996e477Sdrh  catchsql {
620a996e477Sdrh    DELETE FROM t1;
62133752f8aSdanielk1977    BEGIN;
62233752f8aSdanielk1977    INSERT OR ROLLBACK INTO t1 VALUES(1,2);
62333752f8aSdanielk1977    INSERT OR ROLLBACK INTO t1 VALUES(1,3);
624a996e477Sdrh    COMMIT;
625a996e477Sdrh  }
626a996e477Sdrh  execsql {SELECT * FROM t1}
627a996e477Sdrh} {}
628a996e477Sdrhdo_test conflict-10.2 {
629a996e477Sdrh  catchsql {
630a996e477Sdrh    CREATE TABLE t4(x);
631a996e477Sdrh    CREATE UNIQUE INDEX t4x ON t4(x);
63233752f8aSdanielk1977    BEGIN;
63333752f8aSdanielk1977    INSERT OR ROLLBACK INTO t4 VALUES(1);
63433752f8aSdanielk1977    INSERT OR ROLLBACK INTO t4 VALUES(1);
635a996e477Sdrh    COMMIT;
636a996e477Sdrh  }
637a996e477Sdrh  execsql {SELECT * FROM t4}
638a996e477Sdrh} {}
639a996e477Sdrh
640ed717fe3Sdrhintegrity_check conflict-99.0
641ed717fe3Sdrh
642bb37fdc7Sdrhfinish_test
643