xref: /sqlite-3.40.0/test/conflict.test (revision 0d65dc0e)
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*0d65dc0eSdrh# $Id: conflict.test,v 1.5 2002/02/03 00:56:11 drh Exp $
17bb37fdc7Sdrh
18bb37fdc7Sdrhset testdir [file dirname $argv0]
19bb37fdc7Sdrhsource $testdir/tester.tcl
20bb37fdc7Sdrh
21*0d65dc0eSdrh# Create tables for the first group of tests.
22bb37fdc7Sdrh#
23*0d65dc0eSdrhdo_test conflict-1.0 {
24bb37fdc7Sdrh  execsql {
25bb37fdc7Sdrh    CREATE TABLE t1(a, b, c, UNIQUE(a,b));
26*0d65dc0eSdrh    CREATE TABLE t2(x);
27bb37fdc7Sdrh    SELECT c FROM t1 ORDER BY c;
28bb37fdc7Sdrh  }
29*0d65dc0eSdrh} {}
30bb37fdc7Sdrh
31*0d65dc0eSdrh# Six columns of configuration data as follows:
32*0d65dc0eSdrh#
33*0d65dc0eSdrh#   i      The reference number of the test
34*0d65dc0eSdrh#   conf   The conflict resolution algorithm on the BEGIN statement
35*0d65dc0eSdrh#   cmd    An INSERT or REPLACE command to execute against table t1
36*0d65dc0eSdrh#   t0     True if there is an error from $cmd
37*0d65dc0eSdrh#   t1     Content of "c" column of t1 assuming no error in $cmd
38*0d65dc0eSdrh#   t2     Content of "x" column of t2
39*0d65dc0eSdrh#
40*0d65dc0eSdrhforeach {i conf cmd t0 t1 t2} {
41*0d65dc0eSdrh  1 {}       INSERT                  1 {}  1
42*0d65dc0eSdrh  2 {}       {INSERT OR IGNORE}      0 3   1
43*0d65dc0eSdrh  3 {}       {INSERT OR REPLACE}     0 4   1
44*0d65dc0eSdrh  4 {}       REPLACE                 0 4   1
45*0d65dc0eSdrh  5 {}       {INSERT OR FAIL}        1 {}  1
46*0d65dc0eSdrh  6 {}       {INSERT OR ABORT}       1 {}  1
47*0d65dc0eSdrh  7 {}       {INSERT OR ROLLBACK}    1 {}  {}
48*0d65dc0eSdrh  8 IGNORE   INSERT                  0 3   1
49*0d65dc0eSdrh  9 IGNORE   {INSERT OR IGNORE}      0 3   1
50*0d65dc0eSdrh 10 IGNORE   {INSERT OR REPLACE}     0 4   1
51*0d65dc0eSdrh 11 IGNORE   REPLACE                 0 4   1
52*0d65dc0eSdrh 12 IGNORE   {INSERT OR FAIL}        1 {}  1
53*0d65dc0eSdrh 13 IGNORE   {INSERT OR ABORT}       1 {}  1
54*0d65dc0eSdrh 14 IGNORE   {INSERT OR ROLLBACK}    1 {}  {}
55*0d65dc0eSdrh 15 REPLACE  INSERT                  0 4   1
56*0d65dc0eSdrh 16 FAIL     INSERT                  1 {}  1
57*0d65dc0eSdrh 17 ABORT    INSERT                  1 {}  1
58*0d65dc0eSdrh 18 ROLLBACK INSERT                  1 {}  {}
59*0d65dc0eSdrh} {
60*0d65dc0eSdrh  do_test conflict-1.$i {
61*0d65dc0eSdrh    if {$conf!=""} {set conf "ON CONFLICT $conf"}
62*0d65dc0eSdrh    set r0 [catch {execsql [subst {
63bb37fdc7Sdrh      DELETE FROM t1;
64*0d65dc0eSdrh      DELETE FROM t2;
65bb37fdc7Sdrh      INSERT INTO t1 VALUES(1,2,3);
66*0d65dc0eSdrh      BEGIN $conf;
67*0d65dc0eSdrh      INSERT INTO t2 VALUES(1);
68*0d65dc0eSdrh      $cmd INTO t1 VALUES(1,2,4);
69*0d65dc0eSdrh    }]} r1]
70*0d65dc0eSdrh    execsql {COMMIT}
71*0d65dc0eSdrh    if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
72*0d65dc0eSdrh    set r2 [execsql {SELECT x FROM t2}]
73*0d65dc0eSdrh    list $r0 $r1 $r2
74*0d65dc0eSdrh  } [list $t0 $t1 $t2]
75bb37fdc7Sdrh}
76bb37fdc7Sdrh
77*0d65dc0eSdrh# Create tables for the first group of tests.
78*0d65dc0eSdrh#
79*0d65dc0eSdrhdo_test conflict-2.0 {
80ef6764a1Sdrh  execsql {
81ef6764a1Sdrh    DROP TABLE t1;
82ef6764a1Sdrh    DROP TABLE t2;
83*0d65dc0eSdrh    CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b));
84*0d65dc0eSdrh    CREATE TABLE t2(x);
85ef6764a1Sdrh    SELECT c FROM t1 ORDER BY c;
86ef6764a1Sdrh  }
87*0d65dc0eSdrh} {}
88ef6764a1Sdrh
89*0d65dc0eSdrh# Six columns of configuration data as follows:
90*0d65dc0eSdrh#
91*0d65dc0eSdrh#   i      The reference number of the test
92*0d65dc0eSdrh#   conf   The conflict resolution algorithm on the BEGIN statement
93*0d65dc0eSdrh#   cmd    An INSERT or REPLACE command to execute against table t1
94*0d65dc0eSdrh#   t0     True if there is an error from $cmd
95*0d65dc0eSdrh#   t1     Content of "c" column of t1 assuming no error in $cmd
96*0d65dc0eSdrh#   t2     Content of "x" column of t2
97*0d65dc0eSdrh#
98*0d65dc0eSdrhforeach {i conf cmd t0 t1 t2} {
99*0d65dc0eSdrh  1 {}       INSERT                  1 {}  1
100*0d65dc0eSdrh  2 {}       {INSERT OR IGNORE}      0 3   1
101*0d65dc0eSdrh  3 {}       {INSERT OR REPLACE}     0 4   1
102*0d65dc0eSdrh  4 {}       REPLACE                 0 4   1
103*0d65dc0eSdrh  5 {}       {INSERT OR FAIL}        1 {}  1
104*0d65dc0eSdrh  6 {}       {INSERT OR ABORT}       1 {}  1
105*0d65dc0eSdrh  7 {}       {INSERT OR ROLLBACK}    1 {}  {}
106*0d65dc0eSdrh  8 IGNORE   INSERT                  0 3   1
107*0d65dc0eSdrh  9 IGNORE   {INSERT OR IGNORE}      0 3   1
108*0d65dc0eSdrh 10 IGNORE   {INSERT OR REPLACE}     0 4   1
109*0d65dc0eSdrh 11 IGNORE   REPLACE                 0 4   1
110*0d65dc0eSdrh 12 IGNORE   {INSERT OR FAIL}        1 {}  1
111*0d65dc0eSdrh 13 IGNORE   {INSERT OR ABORT}       1 {}  1
112*0d65dc0eSdrh 14 IGNORE   {INSERT OR ROLLBACK}    1 {}  {}
113*0d65dc0eSdrh 15 REPLACE  INSERT                  0 4   1
114*0d65dc0eSdrh 16 FAIL     INSERT                  1 {}  1
115*0d65dc0eSdrh 17 ABORT    INSERT                  1 {}  1
116*0d65dc0eSdrh 18 ROLLBACK INSERT                  1 {}  {}
117*0d65dc0eSdrh} {
118*0d65dc0eSdrh  do_test conflict-2.$i {
119*0d65dc0eSdrh    if {$conf!=""} {set conf "ON CONFLICT $conf"}
120*0d65dc0eSdrh    set r0 [catch {execsql [subst {
121ef6764a1Sdrh      DELETE FROM t1;
122*0d65dc0eSdrh      DELETE FROM t2;
123ef6764a1Sdrh      INSERT INTO t1 VALUES(1,2,3);
124*0d65dc0eSdrh      BEGIN $conf;
125*0d65dc0eSdrh      INSERT INTO t2 VALUES(1);
126*0d65dc0eSdrh      $cmd INTO t1 VALUES(1,2,4);
127*0d65dc0eSdrh    }]} r1]
128*0d65dc0eSdrh    execsql {COMMIT}
129*0d65dc0eSdrh    if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
130*0d65dc0eSdrh    set r2 [execsql {SELECT x FROM t2}]
131*0d65dc0eSdrh    list $r0 $r1 $r2
132*0d65dc0eSdrh  } [list $t0 $t1 $t2]
133ef6764a1Sdrh}
134*0d65dc0eSdrh
135*0d65dc0eSdrh# Create tables for the first group of tests.
136*0d65dc0eSdrh#
137*0d65dc0eSdrhdo_test conflict-3.0 {
138*0d65dc0eSdrh  execsql {
139*0d65dc0eSdrh    DROP TABLE t1;
140*0d65dc0eSdrh    DROP TABLE t2;
141*0d65dc0eSdrh    CREATE TABLE t1(a, b, c INTEGER PRIMARY KEY, UNIQUE(a,b));
142*0d65dc0eSdrh    CREATE TABLE t2(x);
143ef6764a1Sdrh    SELECT c FROM t1 ORDER BY c;
144ef6764a1Sdrh  }
145*0d65dc0eSdrh} {}
146*0d65dc0eSdrh
147*0d65dc0eSdrh# Six columns of configuration data as follows:
148*0d65dc0eSdrh#
149*0d65dc0eSdrh#   i      The reference number of the test
150*0d65dc0eSdrh#   conf   The conflict resolution algorithm on the BEGIN statement
151*0d65dc0eSdrh#   cmd    An INSERT or REPLACE command to execute against table t1
152*0d65dc0eSdrh#   t0     True if there is an error from $cmd
153*0d65dc0eSdrh#   t1     Content of "c" column of t1 assuming no error in $cmd
154*0d65dc0eSdrh#   t2     Content of "x" column of t2
155*0d65dc0eSdrh#
156*0d65dc0eSdrhforeach {i conf cmd t0 t1 t2} {
157*0d65dc0eSdrh  1 {}       INSERT                  1 {}  1
158*0d65dc0eSdrh  2 {}       {INSERT OR IGNORE}      0 3   1
159*0d65dc0eSdrh  3 {}       {INSERT OR REPLACE}     0 4   1
160*0d65dc0eSdrh  4 {}       REPLACE                 0 4   1
161*0d65dc0eSdrh  5 {}       {INSERT OR FAIL}        1 {}  1
162*0d65dc0eSdrh  6 {}       {INSERT OR ABORT}       1 {}  1
163*0d65dc0eSdrh  7 {}       {INSERT OR ROLLBACK}    1 {}  {}
164*0d65dc0eSdrh  8 IGNORE   INSERT                  0 3   1
165*0d65dc0eSdrh  9 IGNORE   {INSERT OR IGNORE}      0 3   1
166*0d65dc0eSdrh 10 IGNORE   {INSERT OR REPLACE}     0 4   1
167*0d65dc0eSdrh 11 IGNORE   REPLACE                 0 4   1
168*0d65dc0eSdrh 12 IGNORE   {INSERT OR FAIL}        1 {}  1
169*0d65dc0eSdrh 13 IGNORE   {INSERT OR ABORT}       1 {}  1
170*0d65dc0eSdrh 14 IGNORE   {INSERT OR ROLLBACK}    1 {}  {}
171*0d65dc0eSdrh 15 REPLACE  INSERT                  0 4   1
172*0d65dc0eSdrh 16 FAIL     INSERT                  1 {}  1
173*0d65dc0eSdrh 17 ABORT    INSERT                  1 {}  1
174*0d65dc0eSdrh 18 ROLLBACK INSERT                  1 {}  {}
175*0d65dc0eSdrh} {
176*0d65dc0eSdrh  do_test conflict-3.$i {
177*0d65dc0eSdrh    if {$conf!=""} {set conf "ON CONFLICT $conf"}
178*0d65dc0eSdrh    set r0 [catch {execsql [subst {
179*0d65dc0eSdrh      DELETE FROM t1;
180*0d65dc0eSdrh      DELETE FROM t2;
181*0d65dc0eSdrh      INSERT INTO t1 VALUES(1,2,3);
182*0d65dc0eSdrh      BEGIN $conf;
183*0d65dc0eSdrh      INSERT INTO t2 VALUES(1);
184*0d65dc0eSdrh      $cmd INTO t1 VALUES(1,2,4);
185*0d65dc0eSdrh    }]} r1]
186*0d65dc0eSdrh    execsql {COMMIT}
187*0d65dc0eSdrh    if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
188*0d65dc0eSdrh    set r2 [execsql {SELECT x FROM t2}]
189*0d65dc0eSdrh    list $r0 $r1 $r2
190*0d65dc0eSdrh  } [list $t0 $t1 $t2]
191ef6764a1Sdrh}
192*0d65dc0eSdrh
193*0d65dc0eSdrhdo_test conflict-4.0 {
194*0d65dc0eSdrh  execsql {
195*0d65dc0eSdrh    DROP TABLE t2;
196*0d65dc0eSdrh    CREATE TABLE t2(x);
197*0d65dc0eSdrh    SELECT x FROM t2;
198ef6764a1Sdrh  }
199*0d65dc0eSdrh} {}
200*0d65dc0eSdrh
201*0d65dc0eSdrh# Six columns of configuration data as follows:
202*0d65dc0eSdrh#
203*0d65dc0eSdrh#   i      The reference number of the test
204*0d65dc0eSdrh#   conf1  The conflict resolution algorithm on the UNIQUE constraint
205*0d65dc0eSdrh#   conf2  The conflict resolution algorithm on the BEGIN statement
206*0d65dc0eSdrh#   cmd    An INSERT or REPLACE command to execute against table t1
207*0d65dc0eSdrh#   t0     True if there is an error from $cmd
208*0d65dc0eSdrh#   t1     Content of "c" column of t1 assuming no error in $cmd
209*0d65dc0eSdrh#   t2     Content of "x" column of t2
210*0d65dc0eSdrh#
211*0d65dc0eSdrhforeach {i conf1 conf2 cmd t0 t1 t2} {
212*0d65dc0eSdrh  1 {}       {}       INSERT                  1 {}  1
213*0d65dc0eSdrh  2 REPLACE  {}       INSERT                  0 4   1
214*0d65dc0eSdrh  3 IGNORE   {}       INSERT                  0 3   1
215*0d65dc0eSdrh  4 FAIL     {}       INSERT                  1 {}  1
216*0d65dc0eSdrh  5 ABORT    {}       INSERT                  1 {}  1
217*0d65dc0eSdrh  6 ROLLBACK {}       INSERT                  1 {}  {}
218*0d65dc0eSdrh  7 REPLACE  {}       {INSERT OR IGNORE}      0 3   1
219*0d65dc0eSdrh  8 IGNORE   {}       {INSERT OR REPLACE}     0 4   1
220*0d65dc0eSdrh  9 FAIL     {}       {INSERT OR IGNORE}      0 3   1
221*0d65dc0eSdrh 10 ABORT    {}       {INSERT OR REPLACE}     0 4   1
222*0d65dc0eSdrh 11 ROLLBACK {}       {INSERT OR IGNORE }     0 3   1
223*0d65dc0eSdrh 12 REPLACE  IGNORE   INSERT                  0 4   1
224*0d65dc0eSdrh 13 IGNORE   REPLACE  INSERT                  0 3   1
225*0d65dc0eSdrh 14 FAIL     IGNORE   INSERT                  1 {}  1
226*0d65dc0eSdrh 15 ABORT    REPLACE  INSERT                  1 {}  1
227*0d65dc0eSdrh 16 ROLLBACK IGNORE   INSERT                  1 {}  {}
228*0d65dc0eSdrh} {
229*0d65dc0eSdrh  do_test conflict-4.$i {
230*0d65dc0eSdrh    if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
231*0d65dc0eSdrh    if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
232*0d65dc0eSdrh    set r0 [catch {execsql [subst {
233*0d65dc0eSdrh      DROP TABLE t1;
234*0d65dc0eSdrh      CREATE TABLE t1(a,b,c,UNIQUE(a,b) $conf1);
235*0d65dc0eSdrh      DELETE FROM t2;
236*0d65dc0eSdrh      INSERT INTO t1 VALUES(1,2,3);
237*0d65dc0eSdrh      BEGIN $conf2;
238*0d65dc0eSdrh      INSERT INTO t2 VALUES(1);
239*0d65dc0eSdrh      $cmd INTO t1 VALUES(1,2,4);
240*0d65dc0eSdrh    }]} r1]
241*0d65dc0eSdrh    execsql {COMMIT}
242*0d65dc0eSdrh    if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
243*0d65dc0eSdrh    set r2 [execsql {SELECT x FROM t2}]
244*0d65dc0eSdrh    list $r0 $r1 $r2
245*0d65dc0eSdrh  } [list $t0 $t1 $t2]
246ef6764a1Sdrh}
247*0d65dc0eSdrh
248*0d65dc0eSdrhdo_test conflict-5.0 {
249*0d65dc0eSdrh  execsql {
250*0d65dc0eSdrh    DROP TABLE t2;
251*0d65dc0eSdrh    CREATE TABLE t2(x);
252*0d65dc0eSdrh    SELECT x FROM t2;
253*0d65dc0eSdrh  }
254*0d65dc0eSdrh} {}
255*0d65dc0eSdrh
256*0d65dc0eSdrh# Six columns of configuration data as follows:
257*0d65dc0eSdrh#
258*0d65dc0eSdrh#   i      The reference number of the test
259*0d65dc0eSdrh#   conf1  The conflict resolution algorithm on the NOT NULL constraint
260*0d65dc0eSdrh#   conf2  The conflict resolution algorithm on the BEGIN statement
261*0d65dc0eSdrh#   cmd    An INSERT or REPLACE command to execute against table t1
262*0d65dc0eSdrh#   t0     True if there is an error from $cmd
263*0d65dc0eSdrh#   t1     Content of "c" column of t1 assuming no error in $cmd
264*0d65dc0eSdrh#   t2     Content of "x" column of t2
265*0d65dc0eSdrh#
266*0d65dc0eSdrhforeach {i conf1 conf2 cmd t0 t1 t2} {
267*0d65dc0eSdrh  1 {}       {}       INSERT                  1 {}  1
268*0d65dc0eSdrh  2 REPLACE  {}       INSERT                  0 5   1
269*0d65dc0eSdrh  3 IGNORE   {}       INSERT                  0 {}  1
270*0d65dc0eSdrh  4 FAIL     {}       INSERT                  1 {}  1
271*0d65dc0eSdrh  5 ABORT    {}       INSERT                  1 {}  1
272*0d65dc0eSdrh  6 ROLLBACK {}       INSERT                  1 {}  {}
273*0d65dc0eSdrh  7 REPLACE  {}       {INSERT OR IGNORE}      0 {}  1
274*0d65dc0eSdrh  8 IGNORE   {}       {INSERT OR REPLACE}     0 5   1
275*0d65dc0eSdrh  9 FAIL     {}       {INSERT OR IGNORE}      0 {}  1
276*0d65dc0eSdrh 10 ABORT    {}       {INSERT OR REPLACE}     0 5   1
277*0d65dc0eSdrh 11 ROLLBACK {}       {INSERT OR IGNORE}      0 {}  1
278*0d65dc0eSdrh 12 {}       {}       {INSERT OR IGNORE}      0 {}  1
279*0d65dc0eSdrh 13 {}       {}       {INSERT OR REPLACE}     0 5   1
280*0d65dc0eSdrh 14 {}       {}       {INSERT OR FAIL}        1 {}  1
281*0d65dc0eSdrh 15 {}       {}       {INSERT OR ABORT}       1 {}  1
282*0d65dc0eSdrh 16 {}       {}       {INSERT OR ROLLBACK}    1 {}  {}
283*0d65dc0eSdrh 17 {}       IGNORE   INSERT                  0 {}  1
284*0d65dc0eSdrh 18 {}       REPLACE  INSERT                  0 5   1
285*0d65dc0eSdrh 19 {}       FAIL     INSERT                  1 {}  1
286*0d65dc0eSdrh 20 {}       ABORT    INSERT                  1 {}  1
287*0d65dc0eSdrh 21 {}       ROLLBACK INSERT                  1 {}  {}
288*0d65dc0eSdrh 22 REPLACE  FAIL     INSERT                  0 5   1
289*0d65dc0eSdrh 23 IGNORE   ROLLBACK INSERT                  0 {}  1
290*0d65dc0eSdrh} {
291*0d65dc0eSdrh  if {$t0} {set t1 {constraint failed}}
292*0d65dc0eSdrh  do_test conflict-5.$i {
293*0d65dc0eSdrh    if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
294*0d65dc0eSdrh    if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
295*0d65dc0eSdrh    set r0 [catch {execsql [subst {
296*0d65dc0eSdrh      DROP TABLE t1;
297*0d65dc0eSdrh      CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5);
298*0d65dc0eSdrh      DELETE FROM t2;
299*0d65dc0eSdrh      BEGIN $conf2;
300*0d65dc0eSdrh      INSERT INTO t2 VALUES(1);
301*0d65dc0eSdrh      $cmd INTO t1 VALUES(1,2,NULL);
302*0d65dc0eSdrh    }]} r1]
303*0d65dc0eSdrh    execsql {COMMIT}
304*0d65dc0eSdrh    if {!$r0} {set r1 [execsql {SELECT c FROM t1}]}
305*0d65dc0eSdrh    set r2 [execsql {SELECT x FROM t2}]
306*0d65dc0eSdrh    list $r0 $r1 $r2
307*0d65dc0eSdrh  } [list $t0 $t1 $t2]
308*0d65dc0eSdrh}
309*0d65dc0eSdrh
310*0d65dc0eSdrhdo_test conflict-6.0 {
311*0d65dc0eSdrh  execsql {
312*0d65dc0eSdrh    DROP TABLE t2;
313*0d65dc0eSdrh    CREATE TABLE t2(a,b,c);
314*0d65dc0eSdrh    INSERT INTO t2 VALUES(1,2,1);
315*0d65dc0eSdrh    INSERT INTO t2 VALUES(2,3,2);
316*0d65dc0eSdrh    INSERT INTO t2 VALUES(3,4,1);
317*0d65dc0eSdrh    INSERT INTO t2 VALUES(4,5,4);
318*0d65dc0eSdrh    SELECT c FROM t2 ORDER BY b;
319*0d65dc0eSdrh    CREATE TABLE t3(x);
320*0d65dc0eSdrh    INSERT INTO t3 VALUES(1);
321*0d65dc0eSdrh  }
322*0d65dc0eSdrh} {1 2 1 4}
323*0d65dc0eSdrh
324*0d65dc0eSdrh# Six columns of configuration data as follows:
325*0d65dc0eSdrh#
326*0d65dc0eSdrh#   i      The reference number of the test
327*0d65dc0eSdrh#   conf1  The conflict resolution algorithm on the UNIQUE constraint
328*0d65dc0eSdrh#   conf2  The conflict resolution algorithm on the BEGIN statement
329*0d65dc0eSdrh#   cmd    An UPDATE command to execute against table t1
330*0d65dc0eSdrh#   t0     True if there is an error from $cmd
331*0d65dc0eSdrh#   t1     Content of "b" column of t1 assuming no error in $cmd
332*0d65dc0eSdrh#   t2     Content of "x" column of t3
333*0d65dc0eSdrh#
334*0d65dc0eSdrhforeach {i conf1 conf2 cmd t0 t1 t2} {
335*0d65dc0eSdrh  1 {}       {}       UPDATE                  1 {6 7 8 9}  1
336*0d65dc0eSdrh  2 REPLACE  {}       UPDATE                  0 {7 6 9}    1
337*0d65dc0eSdrh  3 IGNORE   {}       UPDATE                  0 {6 7 3 9}  1
338*0d65dc0eSdrh  4 FAIL     {}       UPDATE                  1 {6 7 3 4}  1
339*0d65dc0eSdrh  5 ABORT    {}       UPDATE                  1 {1 2 3 4}  1
340*0d65dc0eSdrh  6 ROLLBACK {}       UPDATE                  1 {1 2 3 4}  0
341*0d65dc0eSdrh  7 REPLACE  {}       {UPDATE OR IGNORE}      0 {6 7 3 9}  1
342*0d65dc0eSdrh  8 IGNORE   {}       {UPDATE OR REPLACE}     0 {7 6 9}    1
343*0d65dc0eSdrh  9 FAIL     {}       {UPDATE OR IGNORE}      0 {6 7 3 9}  1
344*0d65dc0eSdrh 10 ABORT    {}       {UPDATE OR REPLACE}     0 {7 6 9}    1
345*0d65dc0eSdrh 11 ROLLBACK {}       {UPDATE OR IGNORE}      0 {6 7 3 9}   1
346*0d65dc0eSdrh 12 {}       {}       {UPDATE OR IGNORE}      0 {6 7 3 9}  1
347*0d65dc0eSdrh 13 {}       {}       {UPDATE OR REPLACE}     0 {7 6 9}    1
348*0d65dc0eSdrh 14 {}       {}       {UPDATE OR FAIL}        1 {6 7 3 4}  1
349*0d65dc0eSdrh 15 {}       {}       {UPDATE OR ABORT}       1 {1 2 3 4}  1
350*0d65dc0eSdrh 16 {}       {}       {UPDATE OR ROLLBACK}    1 {1 2 3 4}  0
351*0d65dc0eSdrh 17 {}       IGNORE   UPDATE                  0 {6 7 3 9}  1
352*0d65dc0eSdrh 18 {}       REPLACE  UPDATE                  0 {7 6 9}    1
353*0d65dc0eSdrh 19 {}       FAIL     UPDATE                  1 {6 7 3 4}  1
354*0d65dc0eSdrh 20 {}       ABORT    UPDATE                  1 {1 2 3 4}  1
355*0d65dc0eSdrh 21 {}       ROLLBACK UPDATE                  1 {1 2 3 4}  0
356*0d65dc0eSdrh 22 REPLACE  FAIL     UPDATE                  0 {7 6 9}    1
357*0d65dc0eSdrh 23 IGNORE   ROLLBACK UPDATE                  0 {6 7 3 9}  1
358*0d65dc0eSdrh} {
359*0d65dc0eSdrh  if {$t0} {set t1 {constraint failed}}
360*0d65dc0eSdrh  do_test conflict-6.$i {
361*0d65dc0eSdrh    if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
362*0d65dc0eSdrh    if {$conf2!=""} {set conf2 "ON CONFLICT $conf2"}
363*0d65dc0eSdrh    set r0 [catch {execsql [subst {
364*0d65dc0eSdrh      DROP TABLE t1;
365*0d65dc0eSdrh      CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1);
366*0d65dc0eSdrh      INSERT INTO t1 SELECT * FROM t2;
367*0d65dc0eSdrh      UPDATE t3 SET x=0;
368*0d65dc0eSdrh      BEGIN $conf2;
369*0d65dc0eSdrh      $cmd t3 SET x=1;
370*0d65dc0eSdrh      $cmd t1 SET a=c+5;
371*0d65dc0eSdrh    }]} r1]
372*0d65dc0eSdrh    execsql {COMMIT}
373*0d65dc0eSdrh    if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]}
374*0d65dc0eSdrh    set r2 [execsql {SELECT x FROM t3}]
375*0d65dc0eSdrh    list $r0 $r1 $r2
376*0d65dc0eSdrh  } [list $t0 $t1 $t2]
377*0d65dc0eSdrh}
378ef6764a1Sdrh
379bb37fdc7Sdrh
380bb37fdc7Sdrhfinish_test
381