# 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.
SELECT a,b,c FROM t1 ORDER BY a;
} {1 2 3 2 3 4}
-# Insert two rows where the second conflicts on C. The first row show go
-# and and then there should be a constraint error.
+# Insert two rows where the second conflicts on C. The first row should
+# be inserted then there should be a constraint error.
#
-do_test 1.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 1.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 1.4 {
SELECT a,b,c FROM t1 ORDER BY a;
} {1 2 3 2 3 4 4 5 6}
-# Replete the tests above, but this time on a table non-INTEGER primary key.
+# Table t2 is the same as t1 and the tests are the same except
+# that t2 has ON CONFLICT ABORT for column c which is overridden
+# to IGNORE using an ON CONFLICT clause in the INSERT.
+do_execsql_test 1.4 {
+ CREATE TABLE t2(
+ a INTEGER PRIMARY KEY ON CONFLICT REPLACE,
+ b UNIQUE ON CONFLICT IGNORE,
+ c UNIQUE ON CONFLICT ABORT
+ );
+ INSERT INTO t2(a,b,c) VALUES(1,2,3), (2,3,4);
+ SELECT a,b,c FROM t2 ORDER BY a;
+} {1 2 3 2 3 4}
+do_execsql_test 1.5 {
+ INSERT INTO t2(a,b,c) VALUES(4,5,6), (5,6,4)
+ ON CONFLICT(c) DO NOTHING;
+} {}
+do_execsql_test 1.6 {
+ SELECT a,b,c FROM t2 ORDER BY a;
+} {1 2 3 2 3 4 4 5 6}
+do_execsql_test 1.7 {
+ INSERT INTO t2(a,b,c) VALUES(9,3,8),(10,11,12)
+ ON CONFLICT(c) DO NOTHING;
+} {}
+do_execsql_test 1.8 {
+ SELECT a,b,c FROM t2 ORDER BY a;
+} {1 2 3 2 3 4 4 5 6 10 11 12}
+do_execsql_test 1.99 {PRAGMA integrity_check} ok
+
+
+# Repeat the tests above, but this time on a table non-INTEGER primary key.
#
do_execsql_test 2.1 {
DROP TABLE t1;
SELECT a,b,c FROM t1 ORDER BY a;
} {1 2 3 2 3 4 4 5 6}
-# Replete again on a WITHOUT ROWID table.
+# Table t2 is the same as t1 and the tests are the same except
+# that t2 has ON CONFLICT ABORT for column c which is overridden
+# to IGNORE using an ON CONFLICT clause in the INSERT.
+do_execsql_test 2.5 {
+ DROP TABLE t2;
+ CREATE TABLE t2(
+ a INT PRIMARY KEY ON CONFLICT REPLACE,
+ b UNIQUE ON CONFLICT FAIL,
+ c UNIQUE ON CONFLICT ABORT
+ );
+ INSERT INTO t2(a,b,c) VALUES(1,2,3), (2,3,4);
+ SELECT a,b,c FROM t2 ORDER BY a;
+} {1 2 3 2 3 4}
+do_execsql_test 2.6 {
+ INSERT INTO t2(a,b,c) VALUES(4,5,6), (5,6,4)
+ ON CONFLICT(c) DO NOTHING;
+} {}
+do_execsql_test 2.7 {
+ SELECT a,b,c FROM t2 ORDER BY a;
+} {1 2 3 2 3 4 4 5 6}
+do_execsql_test 2.99 {PRAGMA integrity_check} ok
+
+
+# Repeat again on a WITHOUT ROWID table.
#
do_execsql_test 3.1 {
DROP TABLE t1;
# Insert two rows where the second conflicts on C. The first row show go
# and and then there should be a constraint error.
#
-do_test 3.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 3.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 3.4 {
SELECT a,b,c FROM t1 ORDER BY a;
} {1 2 3 2 3 4 4 5 6}
+# Table t2 is the same as t1 and the tests are the same except
+# that t2 has ON CONFLICT ABORT for column c which is overridden
+# to IGNORE using an ON CONFLICT clause in the INSERT.
+do_execsql_test 3.5 {
+ DROP TABLE t2;
+ CREATE TABLE t2(
+ a INT PRIMARY KEY ON CONFLICT REPLACE,
+ b UNIQUE ON CONFLICT FAIL,
+ c UNIQUE ON CONFLICT ABORT
+ ) WITHOUT ROWID;
+ INSERT INTO t2(a,b,c) VALUES(1,2,3), (2,3,4);
+ SELECT a,b,c FROM t2 ORDER BY a;
+} {1 2 3 2 3 4}
+do_execsql_test 3.6 {
+ INSERT INTO t2(a,b,c) VALUES(4,5,6), (5,6,4)
+ ON CONFLICT(c) DO NOTHING;
+} {}
+do_execsql_test 3.7 {
+ SELECT a,b,c FROM t2 ORDER BY a;
+} {1 2 3 2 3 4 4 5 6}
+do_execsql_test 3.99 {PRAGMA integrity_check} ok
+
# Arrange the table rows in a different order and repeat.
#
do_execsql_test 4.1 {
# Insert two rows where the second conflicts on C. The first row show go
# and and then there should be a constraint error.
#
-do_test 4.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 4.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 4.4 {
SELECT a,b,c FROM t1 ORDER BY a;
} {1 2 3 2 3 4 4 5 6}
+do_execsql_test 4.99 {PRAGMA integrity_check} ok
# Arrange the table rows in a different order and repeat.
#
# Insert two rows where the second conflicts on C. The first row show go
# and and then there should be a constraint error.
#
-do_test 5.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 5.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 5.4 {
SELECT a,b,c FROM t1 ORDER BY a;
# Insert two rows where the second conflicts on C. The first row show go
# and and then there should be a constraint error.
#
-do_test 6.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 6.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 6.4 {
SELECT a,b,c FROM t1 ORDER BY a;
# Insert two rows where the second conflicts on C. The first row show go
# and and then there should be a constraint error.
#
-do_test 7.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 7.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 7.4 {
SELECT a,b,c FROM t1 ORDER BY a;
# Insert two rows where the second conflicts on C. The first row show go
# and and then there should be a constraint error.
#
-do_test 8.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 8.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 8.4 {
SELECT a,b,c FROM t1 ORDER BY a;
# Insert two rows where the second conflicts on C. The first row show go
# and and then there should be a constraint error.
#
-do_test 9.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 9.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 9.4 {
SELECT a,b,c FROM t1 ORDER BY a;
# Insert two rows where the second conflicts on C. The first row show go
# and and then there should be a constraint error.
#
-do_test 10.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 10.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 10.4 {
SELECT a,b,c FROM t1 ORDER BY a;
# Insert two rows where the second conflicts on C. The first row show go
# and and then there should be a constraint error.
#
-do_test 11.3 {
- catchsql {INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);}
+do_catchsql_test 11.3 {
+ INSERT INTO t1(a,b,c) VALUES(4,5,6), (5,6,4);
} {1 {UNIQUE constraint failed: t1.c}}
do_execsql_test 11.4 {
SELECT a,b,c FROM t1 ORDER BY a;
# Check that ticket [f68dc596c4] has been fixed.
#
do_execsql_test 12.1 {
+ DROP TABLE t2;
CREATE TABLE t2(a INTEGER PRIMARY KEY, b TEXT);
INSERT INTO t2 VALUES(111, '111');
}