e9c2e772f1
clauses. The syntax now is exactly as in PostgreSQL and MySQL. Add support for WHERE clauses on the conflict-target phrase, for partial indexes. FossilOrigin-Name: 2c1b1987d8de1efa8ed7e1f199710e32ff20edf8ceec570514fc63bb1ef264e0
58 lines
1.7 KiB
Plaintext
58 lines
1.7 KiB
Plaintext
# 2018-04-12
|
|
#
|
|
# The author disclaims copyright to this source code. In place of
|
|
# a legal notice, here is a blessing:
|
|
#
|
|
# May you do good and not evil.
|
|
# May you find forgiveness for yourself and forgive others.
|
|
# May you share freely, never taking more than you give.
|
|
#
|
|
#***********************************************************************
|
|
#
|
|
# Test cases for UPSERT
|
|
|
|
set testdir [file dirname $argv0]
|
|
source $testdir/tester.tcl
|
|
set testprefix zipfile
|
|
|
|
do_execsql_test upsert1-100 {
|
|
CREATE TABLE t1(a INTEGER PRIMARY KEY, b TEXT, c DEFAULT 0);
|
|
CREATE UNIQUE INDEX t1x1 ON t1(b);
|
|
INSERT INTO t1(a,b) VALUES(1,2) ON CONFLICT DO NOTHING;
|
|
SELECT * FROM t1;
|
|
} {1 2 0}
|
|
do_execsql_test upsert1-101 {
|
|
DELETE FROM t1;
|
|
INSERT INTO t1(a,b) VALUES(2,3) ON CONFLICT(a) DO NOTHING;
|
|
SELECT * FROM t1;
|
|
} {2 3 0}
|
|
do_execsql_test upsert1-102 {
|
|
DELETE FROM t1;
|
|
INSERT INTO t1(a,b) VALUES(3,4) ON CONFLICT(b) DO NOTHING;
|
|
SELECT * FROM t1;
|
|
} {3 4 0}
|
|
do_catchsql_test upsert1-110 {
|
|
INSERT INTO t1(a,b) VALUES(5,6) ON CONFLICT(x) DO NOTHING;
|
|
SELECT * FROM t1;
|
|
} {1 {no such column: x}}
|
|
do_catchsql_test upsert1-120 {
|
|
INSERT INTO t1(a,b) VALUES(5,6) ON CONFLICT(c) DO NOTHING;
|
|
SELECT * FROM t1;
|
|
} {1 {ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint}}
|
|
do_catchsql_test upsert1-130 {
|
|
INSERT INTO t1(a,b) VALUES(5,6) ON CONFLICT(b COLLATE nocase) DO NOTHING;
|
|
SELECT * FROM t1;
|
|
} {1 {ON CONFLICT clause does not match any PRIMARY KEY or UNIQUE constraint}}
|
|
|
|
if 0 {
|
|
do_catchsql_test upsert1-200 {
|
|
DROP INDEX t1x1;
|
|
DELETE FROM t1;
|
|
CREATE UNIQUE INDEX t1x1 ON t1(a||b);
|
|
INSERT INTO t1(a,b) VALUES(5,6) ON CONFLICT(a||b) DO NOTHING;
|
|
SELECT * FROM t1;
|
|
} {0 {5 6}}
|
|
}
|
|
|
|
finish_test
|