3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests for the conflict resolution extension
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
25 # Create tables for the first group of tests.
27 do_test conflict-1.0 {
29 CREATE TABLE t1(a, b, c, UNIQUE(a,b));
31 SELECT c FROM t1 ORDER BY c;
35 # Six columns of configuration data as follows:
37 # i The reference number of the test
38 # cmd An INSERT or REPLACE command to execute against table t1
39 # t0 True if there is an error from $cmd
40 # t1 Content of "c" column of t1 assuming no error in $cmd
41 # t2 Content of "x" column of t2
42 # t3 Number of temporary files created by this test
44 foreach {i cmd t0 t1 t2 t3} {
46 2 {INSERT OR IGNORE} 0 3 1 0
47 3 {INSERT OR REPLACE} 0 4 1 0
49 5 {INSERT OR FAIL} 1 {} 1 0
50 6 {INSERT OR ABORT} 1 {} 1 0
51 7 {INSERT OR ROLLBACK} 1 {} {} 0
53 do_test conflict-1.$i {
54 set ::sqlite_opentemp_count 0
55 set r0 [catch {execsql [subst {
58 INSERT INTO t1 VALUES(1,2,3);
60 INSERT INTO t2 VALUES(1);
61 $cmd INTO t1 VALUES(1,2,4);
63 catch {execsql {COMMIT}}
64 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
65 set r2 [execsql {SELECT x FROM t2}]
66 set r3 $::sqlite_opentemp_count
68 } [list $t0 $t1 $t2 $t3]
71 # Create tables for the first group of tests.
73 do_test conflict-2.0 {
77 CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c, UNIQUE(a,b));
79 SELECT c FROM t1 ORDER BY c;
83 # Six columns of configuration data as follows:
85 # i The reference number of the test
86 # cmd An INSERT or REPLACE command to execute against table t1
87 # t0 True if there is an error from $cmd
88 # t1 Content of "c" column of t1 assuming no error in $cmd
89 # t2 Content of "x" column of t2
91 foreach {i cmd t0 t1 t2} {
93 2 {INSERT OR IGNORE} 0 3 1
94 3 {INSERT OR REPLACE} 0 4 1
96 5 {INSERT OR FAIL} 1 {} 1
97 6 {INSERT OR ABORT} 1 {} 1
98 7 {INSERT OR ROLLBACK} 1 {} {}
100 do_test conflict-2.$i {
101 set r0 [catch {execsql [subst {
104 INSERT INTO t1 VALUES(1,2,3);
106 INSERT INTO t2 VALUES(1);
107 $cmd INTO t1 VALUES(1,2,4);
109 catch {execsql {COMMIT}}
110 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
111 set r2 [execsql {SELECT x FROM t2}]
116 # Create tables for the first group of tests.
118 do_test conflict-3.0 {
122 CREATE TABLE t1(a, b, c INTEGER, PRIMARY KEY(c), UNIQUE(a,b));
124 SELECT c FROM t1 ORDER BY c;
128 # Six columns of configuration data as follows:
130 # i The reference number of the test
131 # cmd An INSERT or REPLACE command to execute against table t1
132 # t0 True if there is an error from $cmd
133 # t1 Content of "c" column of t1 assuming no error in $cmd
134 # t2 Content of "x" column of t2
136 foreach {i cmd t0 t1 t2} {
138 2 {INSERT OR IGNORE} 0 3 1
139 3 {INSERT OR REPLACE} 0 4 1
141 5 {INSERT OR FAIL} 1 {} 1
142 6 {INSERT OR ABORT} 1 {} 1
143 7 {INSERT OR ROLLBACK} 1 {} {}
145 do_test conflict-3.$i {
146 set r0 [catch {execsql [subst {
149 INSERT INTO t1 VALUES(1,2,3);
151 INSERT INTO t2 VALUES(1);
152 $cmd INTO t1 VALUES(1,2,4);
154 catch {execsql {COMMIT}}
155 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
156 set r2 [execsql {SELECT x FROM t2}]
161 do_test conflict-4.0 {
169 # Six columns of configuration data as follows:
171 # i The reference number of the test
172 # conf1 The conflict resolution algorithm on the UNIQUE constraint
173 # cmd An INSERT or REPLACE command to execute against table t1
174 # t0 True if there is an error from $cmd
175 # t1 Content of "c" column of t1 assuming no error in $cmd
176 # t2 Content of "x" column of t2
178 foreach {i conf1 cmd t0 t1 t2} {
180 2 REPLACE INSERT 0 4 1
181 3 IGNORE INSERT 0 3 1
183 5 ABORT INSERT 1 {} 1
184 6 ROLLBACK INSERT 1 {} {}
185 7 REPLACE {INSERT OR IGNORE} 0 3 1
186 8 IGNORE {INSERT OR REPLACE} 0 4 1
187 9 FAIL {INSERT OR IGNORE} 0 3 1
188 10 ABORT {INSERT OR REPLACE} 0 4 1
189 11 ROLLBACK {INSERT OR IGNORE } 0 3 1
191 do_test conflict-4.$i {
192 if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
193 set r0 [catch {execsql [subst {
195 CREATE TABLE t1(a,b,c,UNIQUE(a,b) $conf1);
197 INSERT INTO t1 VALUES(1,2,3);
199 INSERT INTO t2 VALUES(1);
200 $cmd INTO t1 VALUES(1,2,4);
202 catch {execsql {COMMIT}}
203 if {$r0} {set r1 {}} {set r1 [execsql {SELECT c FROM t1}]}
204 set r2 [execsql {SELECT x FROM t2}]
209 do_test conflict-5.0 {
217 # Six columns of configuration data as follows:
219 # i The reference number of the test
220 # conf1 The conflict resolution algorithm on the NOT NULL constraint
221 # cmd An INSERT or REPLACE command to execute against table t1
222 # t0 True if there is an error from $cmd
223 # t1 Content of "c" column of t1 assuming no error in $cmd
224 # t2 Content of "x" column of t2
226 foreach {i conf1 cmd t0 t1 t2} {
228 2 REPLACE INSERT 0 5 1
229 3 IGNORE INSERT 0 {} 1
231 5 ABORT INSERT 1 {} 1
232 6 ROLLBACK INSERT 1 {} {}
233 7 REPLACE {INSERT OR IGNORE} 0 {} 1
234 8 IGNORE {INSERT OR REPLACE} 0 5 1
235 9 FAIL {INSERT OR IGNORE} 0 {} 1
236 10 ABORT {INSERT OR REPLACE} 0 5 1
237 11 ROLLBACK {INSERT OR IGNORE} 0 {} 1
238 12 {} {INSERT OR IGNORE} 0 {} 1
239 13 {} {INSERT OR REPLACE} 0 5 1
240 14 {} {INSERT OR FAIL} 1 {} 1
241 15 {} {INSERT OR ABORT} 1 {} 1
242 16 {} {INSERT OR ROLLBACK} 1 {} {}
244 if {$t0} {set t1 {NOT NULL constraint failed: t1.c}}
245 do_test conflict-5.$i {
246 if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
247 set r0 [catch {execsql [subst {
249 CREATE TABLE t1(a,b,c NOT NULL $conf1 DEFAULT 5);
252 INSERT INTO t2 VALUES(1);
253 $cmd INTO t1 VALUES(1,2,NULL);
255 catch {execsql {COMMIT}}
256 if {!$r0} {set r1 [execsql {SELECT c FROM t1}]}
257 set r2 [execsql {SELECT x FROM t2}]
262 do_test conflict-6.0 {
265 CREATE TABLE t2(a,b,c);
266 INSERT INTO t2 VALUES(1,2,1);
267 INSERT INTO t2 VALUES(2,3,2);
268 INSERT INTO t2 VALUES(3,4,1);
269 INSERT INTO t2 VALUES(4,5,4);
270 SELECT c FROM t2 ORDER BY b;
272 INSERT INTO t3 VALUES(1);
276 # Six columns of configuration data as follows:
278 # i The reference number of the test
279 # conf1 The conflict resolution algorithm on the UNIQUE constraint
280 # cmd An UPDATE command to execute against table t1
281 # t0 True if there is an error from $cmd
282 # t1 Content of "b" column of t1 assuming no error in $cmd
283 # t2 Content of "x" column of t3
284 # t3 Number of temporary files for tables
285 # t4 Number of temporary files for statement journals
287 # Update (2007-08-21): Since temporary table files are now opened lazily,
288 # and none of the following tests use large quantities of data, t3 is always 0.
290 # Update (2016-03-04): Subjournals now also open lazily, so t4 is also always 0.
292 foreach {i conf1 cmd t0 t1 t2 t3 t4} {
293 1 {} UPDATE 1 {6 7 8 9} 1 0 0
294 2 REPLACE UPDATE 0 {7 6 9} 1 0 0
295 3 IGNORE UPDATE 0 {6 7 3 9} 1 0 0
296 4 FAIL UPDATE 1 {6 7 3 4} 1 0 0
297 5 ABORT UPDATE 1 {1 2 3 4} 1 0 0
298 6 ROLLBACK UPDATE 1 {1 2 3 4} 0 0 0
299 7 REPLACE {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0
300 8 IGNORE {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0
301 9 FAIL {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0
302 10 ABORT {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0
303 11 ROLLBACK {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0
304 12 {} {UPDATE OR IGNORE} 0 {6 7 3 9} 1 0 0
305 13 {} {UPDATE OR REPLACE} 0 {7 6 9} 1 0 0
306 14 {} {UPDATE OR FAIL} 1 {6 7 3 4} 1 0 0
307 15 {} {UPDATE OR ABORT} 1 {1 2 3 4} 1 0 0
308 16 {} {UPDATE OR ROLLBACK} 1 {1 2 3 4} 0 0 0
310 if {$t0} {set t1 {UNIQUE constraint failed: t1.a}}
311 if {[info exists TEMP_STORE] && $TEMP_STORE==3} {
314 set t3 [expr {$t3+$t4}]
316 do_test conflict-6.$i {
319 if {$conf1!=""} {set conf1 "ON CONFLICT $conf1"}
320 execsql {pragma temp_store=file}
321 set ::sqlite_opentemp_count 0
322 set r0 [catch {execsql [subst {
324 CREATE TABLE t1(a,b,c, UNIQUE(a) $conf1);
325 INSERT INTO t1 SELECT * FROM t2;
332 catch {execsql {COMMIT}}
333 if {!$r0} {set r1 [execsql {SELECT a FROM t1 ORDER BY b}]}
334 set r2 [execsql {SELECT x FROM t3}]
335 list $r0 $r1 $r2 $::sqlite_opentemp_count
336 } [list $t0 $t1 $t2 $t3]
339 # Test to make sure a lot of IGNOREs don't cause a stack overflow
341 do_test conflict-7.1 {
346 CREATE TABLE t1(a unique, b);
348 for {set i 1} {$i<=50} {incr i} {
349 execsql "INSERT into t1 values($i,[expr {$i+1}]);"
352 SELECT count(*), min(a), max(b) FROM t1;
355 do_test conflict-7.2 {
357 PRAGMA count_changes=on;
358 UPDATE OR IGNORE t1 SET a=1000;
361 do_test conflict-7.2.1 {
364 do_test conflict-7.3 {
366 SELECT b FROM t1 WHERE a=1000;
369 do_test conflict-7.4 {
371 SELECT count(*) FROM t1;
374 do_test conflict-7.5 {
376 PRAGMA count_changes=on;
377 UPDATE OR REPLACE t1 SET a=1001;
380 do_test conflict-7.5.1 {
383 do_test conflict-7.6 {
385 SELECT b FROM t1 WHERE a=1001;
388 do_test conflict-7.7 {
390 SELECT count(*) FROM t1;
394 # Update for version 3: A SELECT statement no longer resets the change
395 # counter (Test result changes from 0 to 50).
396 do_test conflict-7.7.1 {
400 # Make sure the row count is right for rows that are ignored on
403 do_test conflict-8.1 {
406 INSERT INTO t1 VALUES(1,2);
409 INSERT OR IGNORE INTO t1 VALUES(2,3);
412 do_test conflict-8.1.1 {
415 do_test conflict-8.2 {
417 INSERT OR IGNORE INTO t1 VALUES(2,4);
420 do_test conflict-8.2.1 {
423 do_test conflict-8.3 {
425 INSERT OR REPLACE INTO t1 VALUES(2,4);
428 do_test conflict-8.3.1 {
431 do_test conflict-8.4 {
433 INSERT OR IGNORE INTO t1 SELECT * FROM t1;
436 do_test conflict-8.4.1 {
439 do_test conflict-8.5 {
441 INSERT OR IGNORE INTO t1 SELECT a+2,b+2 FROM t1;
444 do_test conflict-8.5.1 {
447 do_test conflict-8.6 {
449 INSERT OR IGNORE INTO t1 SELECT a+3,b+3 FROM t1;
452 do_test conflict-8.6.1 {
456 integrity_check conflict-8.99
458 do_test conflict-9.1 {
460 PRAGMA count_changes=0;
462 a INTEGER UNIQUE ON CONFLICT IGNORE,
463 b INTEGER UNIQUE ON CONFLICT FAIL,
464 c INTEGER UNIQUE ON CONFLICT REPLACE,
465 d INTEGER UNIQUE ON CONFLICT ABORT,
466 e INTEGER UNIQUE ON CONFLICT ROLLBACK
469 INSERT INTO t3 VALUES(1);
473 do_test conflict-9.2 {
475 INSERT INTO t2 VALUES(1,1,1,1,1);
476 INSERT INTO t2 VALUES(2,2,2,2,2);
479 } {0 {1 1 1 1 1 2 2 2 2 2}}
480 do_test conflict-9.3 {
482 INSERT INTO t2 VALUES(1,3,3,3,3);
485 } {0 {1 1 1 1 1 2 2 2 2 2}}
486 do_test conflict-9.4 {
488 UPDATE t2 SET a=a+1 WHERE a=1;
491 } {0 {1 1 1 1 1 2 2 2 2 2}}
492 do_test conflict-9.5 {
494 INSERT INTO t2 VALUES(3,1,3,3,3);
497 } {1 {UNIQUE constraint failed: t2.b}}
498 do_test conflict-9.6 {
500 UPDATE t2 SET b=b+1 WHERE b=1;
503 } {1 {UNIQUE constraint failed: t2.b}}
504 do_test conflict-9.7 {
508 INSERT INTO t2 VALUES(3,1,3,3,3);
511 } {1 {UNIQUE constraint failed: t2.b}}
512 do_test conflict-9.8 {
514 execsql {SELECT * FROM t3}
516 do_test conflict-9.9 {
520 UPDATE t2 SET b=b+1 WHERE b=1;
523 } {1 {UNIQUE constraint failed: t2.b}}
524 do_test conflict-9.10 {
526 execsql {SELECT * FROM t3}
528 do_test conflict-9.11 {
530 INSERT INTO t2 VALUES(3,3,3,1,3);
533 } {1 {UNIQUE constraint failed: t2.d}}
534 do_test conflict-9.12 {
536 UPDATE t2 SET d=d+1 WHERE d=1;
539 } {1 {UNIQUE constraint failed: t2.d}}
540 do_test conflict-9.13 {
544 INSERT INTO t2 VALUES(3,3,3,1,3);
547 } {1 {UNIQUE constraint failed: t2.d}}
548 do_test conflict-9.14 {
550 execsql {SELECT * FROM t3}
552 do_test conflict-9.15 {
556 UPDATE t2 SET d=d+1 WHERE d=1;
559 } {1 {UNIQUE constraint failed: t2.d}}
560 do_test conflict-9.16 {
562 execsql {SELECT * FROM t3}
564 do_test conflict-9.17 {
566 INSERT INTO t2 VALUES(3,3,3,3,1);
569 } {1 {UNIQUE constraint failed: t2.e}}
570 do_test conflict-9.18 {
572 UPDATE t2 SET e=e+1 WHERE e=1;
575 } {1 {UNIQUE constraint failed: t2.e}}
576 do_test conflict-9.19 {
580 INSERT INTO t2 VALUES(3,3,3,3,1);
583 } {1 {UNIQUE constraint failed: t2.e}}
584 verify_ex_errcode conflict-9.21b SQLITE_CONSTRAINT_UNIQUE
585 do_test conflict-9.20 {
586 catch {execsql {COMMIT}}
587 execsql {SELECT * FROM t3}
589 do_test conflict-9.21 {
593 UPDATE t2 SET e=e+1 WHERE e=1;
596 } {1 {UNIQUE constraint failed: t2.e}}
597 verify_ex_errcode conflict-9.21b SQLITE_CONSTRAINT_UNIQUE
598 do_test conflict-9.22 {
599 catch {execsql {COMMIT}}
600 execsql {SELECT * FROM t3}
602 do_test conflict-9.23 {
604 INSERT INTO t2 VALUES(3,3,1,3,3);
607 } {0 {2 2 2 2 2 3 3 1 3 3}}
608 do_test conflict-9.24 {
610 UPDATE t2 SET c=c-1 WHERE c=2;
614 do_test conflict-9.25 {
618 INSERT INTO t2 VALUES(3,3,1,3,3);
622 do_test conflict-9.26 {
623 catch {execsql {COMMIT}}
624 execsql {SELECT * FROM t3}
627 do_test conflict-10.1 {
631 INSERT OR ROLLBACK INTO t1 VALUES(1,2);
632 INSERT OR ROLLBACK INTO t1 VALUES(1,3);
635 execsql {SELECT * FROM t1}
637 do_test conflict-10.2 {
640 CREATE UNIQUE INDEX t4x ON t4(x);
642 INSERT OR ROLLBACK INTO t4 VALUES(1);
643 INSERT OR ROLLBACK INTO t4 VALUES(1);
646 execsql {SELECT * FROM t4}
649 # Ticket #1171. Make sure statement rollbacks do not
650 # damage the database.
652 do_test conflict-11.1 {
654 -- Create a database object (pages 2, 3 of the file)
656 CREATE TABLE abc(a UNIQUE, b, c);
657 INSERT INTO abc VALUES(1, 2, 3);
658 INSERT INTO abc VALUES(4, 5, 6);
659 INSERT INTO abc VALUES(7, 8, 9);
664 # Set a small cache size so that changes will spill into
667 PRAGMA cache_size = 10;
670 # Make lots of changes. Because of the small cache, some
671 # (most?) of these changes will spill into the disk file.
672 # In other words, some of the changes will not be held in
677 -- Make sure the pager is in EXCLUSIVE state.
678 CREATE TABLE def(d, e, f);
679 INSERT INTO def VALUES
680 ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz');
681 INSERT INTO def SELECT * FROM def;
682 INSERT INTO def SELECT * FROM def;
683 INSERT INTO def SELECT * FROM def;
684 INSERT INTO def SELECT * FROM def;
685 INSERT INTO def SELECT * FROM def;
686 INSERT INTO def SELECT * FROM def;
687 INSERT INTO def SELECT * FROM def;
688 DELETE FROM abc WHERE a = 4;
691 # Execute a statement that does a statement rollback due to
692 # a constraint failure.
695 INSERT INTO abc SELECT 10, 20, 30 FROM def;
698 # Rollback the database. Verify that the state of the ABC table
699 # is unchanged from the beginning of the transaction. In other words,
700 # make sure the DELETE on table ABC that occurred within the transaction
707 } {1 2 3 4 5 6 7 8 9}
708 integrity_check conflict-11.2
710 # Repeat test conflict-11.1 but this time commit.
712 do_test conflict-11.3 {
715 -- Make sure the pager is in EXCLUSIVE state.
716 UPDATE abc SET a=a+1;
717 CREATE TABLE def(d, e, f);
718 INSERT INTO def VALUES
719 ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz');
720 INSERT INTO def SELECT * FROM def;
721 INSERT INTO def SELECT * FROM def;
722 INSERT INTO def SELECT * FROM def;
723 INSERT INTO def SELECT * FROM def;
724 INSERT INTO def SELECT * FROM def;
725 INSERT INTO def SELECT * FROM def;
726 INSERT INTO def SELECT * FROM def;
727 DELETE FROM abc WHERE a = 4;
730 INSERT INTO abc SELECT 10, 20, 30 FROM def;
736 } {1 2 3 4 5 6 7 8 9}
737 # Repeat test conflict-11.1 but this time commit.
739 do_test conflict-11.5 {
742 -- Make sure the pager is in EXCLUSIVE state.
743 CREATE TABLE def(d, e, f);
744 INSERT INTO def VALUES
745 ('xxxxxxxxxxxxxxx', 'yyyyyyyyyyyyyyyy', 'zzzzzzzzzzzzzzzz');
746 INSERT INTO def SELECT * FROM def;
747 INSERT INTO def SELECT * FROM def;
748 INSERT INTO def SELECT * FROM def;
749 INSERT INTO def SELECT * FROM def;
750 INSERT INTO def SELECT * FROM def;
751 INSERT INTO def SELECT * FROM def;
752 INSERT INTO def SELECT * FROM def;
753 DELETE FROM abc WHERE a = 4;
756 INSERT INTO abc SELECT 10, 20, 30 FROM def;
763 integrity_check conflict-11.6
765 # Make sure UPDATE OR REPLACE works on tables that have only
766 # an INTEGER PRIMARY KEY.
768 do_test conflict-12.1 {
770 CREATE TABLE t5(a INTEGER PRIMARY KEY, b text);
771 INSERT INTO t5 VALUES(1,'one');
772 INSERT INTO t5 VALUES(2,'two');
776 do_test conflict-12.2 {
778 UPDATE OR IGNORE t5 SET a=a+1 WHERE a=1;
782 do_test conflict-12.3 {
784 UPDATE t5 SET a=a+1 WHERE a=1;
786 } {1 {UNIQUE constraint failed: t5.a}}
787 verify_ex_errcode conflict-12.3b SQLITE_CONSTRAINT_PRIMARYKEY
788 do_test conflict-12.4 {
790 UPDATE OR REPLACE t5 SET a=a+1 WHERE a=1;
794 do_test conflict-12.5 {
797 INSERT INTO t5b(rowid, x) VALUES(1,10),(2,11);
798 UPDATE t5b SET rowid=rowid+1 WHERE x=10;
800 } {1 {UNIQUE constraint failed: t5b.rowid}}
801 verify_ex_errcode conflict-12.5b SQLITE_CONSTRAINT_ROWID
804 # Ticket [c38baa3d969eab7946dc50ba9d9b4f0057a19437]
805 # REPLACE works like ABORT on a CHECK constraint.
807 do_test conflict-13.1 {
809 CREATE TABLE t13(a CHECK(a!=2));
811 REPLACE INTO t13 VALUES(1);
814 REPLACE INTO t13 VALUES(2);
816 } {1 {CHECK constraint failed: a!=2}}
817 verify_ex_errcode conflict-13.1b SQLITE_CONSTRAINT_CHECK
818 do_test conflict-13.2 {
820 REPLACE INTO t13 VALUES(3);
827 # Ticket https://www.sqlite.org/src/tktview/e6f1f2e34dceeb1ed61531c7e9
828 # Verify that it is not possible to sneak a NULL value into a NOT NULL
829 # column using REPLACE.
831 do_catchsql_test conflict-14.1 {
832 DROP TABLE IF EXISTS t1;
833 CREATE TABLE t1(x NOT NULL DEFAULT NULL);
834 REPLACE INTO t1 DEFAULT VALUES;
835 } {1 {NOT NULL constraint failed: t1.x}}
837 # 2019-12-15 gramfuzz1 find
838 # Three UNIQUE constraints, where the third would is a duplicate except
839 # that it adds ON CONFLICT REPLACE. Verify that the indexes end up
840 # sorted in the correct order (REPLACE last) so that constraint processing
844 do_execsql_test conflict-15.10 {
848 UNIQUE(x,x) ON CONFLICT REPLACE
850 INSERT INTO t1(x) VALUES(1);
853 do_catchsql_test conflict-15.20 {
854 INSERT INTO t1(x) VALUES(1);
855 } {1 {UNIQUE constraint failed: t1.x}}
856 do_execsql_test conflict-15.30 {
860 # 2023-01-16 https://sqlite.org/forum/forumpost/aa580a5af38a58e3
861 # The parser accepts an ON CONFLICT clause on table CHECK constraints
862 # but not on column CHECK constraints. But the CHECK constraint is
863 # ignored. It has been like this since version 3.0.0.
865 # There might be applications and/or databases in the wild that have
866 # table CHECK constraints with ON CONFLICT clauses. In as much as this
867 # is a harmless quirk, we continue to support it in order to avoid
868 # breaking those legacy applications and databases.
871 do_catchsql_test conflict-16.1 {
872 -- ON CONFLICT clauses are not allowed on column CHECK constraints
873 CREATE TABLE t1(a INT CHECK( a!=5 ) ON CONFLICT ignore);
874 } {1 {near "ON": syntax error}}
875 do_execsql_test conflict-16.2 {
876 -- ON CONFLICT is allowed on table CHECK constraints
877 CREATE TABLE t1(a INT, CHECK( a!=5 ) ON CONFLICT ignore);
879 do_catchsql_test conflict-16.3 {
880 -- The ON CONFLICT clause is in-op
881 INSERT INTO t1(a) VALUES(4),(5),(6);
882 } {1 {CHECK constraint failed: a!=5}}
883 do_execsql_test conflict-16.4 {
884 SELECT a FROM t1 ORDER BY a;
886 do_execsql_test conflict-16.5 {
887 INSERT OR IGNORE INTO t1(a) VALUES(4),(5),(6);
888 SELECT a FROM t1 ORDER BY a;