mirror of
https://github.com/sqlite/sqlite.git
synced 2025-08-01 06:27:03 +03:00
Add some more simple test cases for UPSERT. And a minor fix.
FossilOrigin-Name: 27cd3b2fb2ad0cf2b36741bd1057cb7973954d40456e9db158261a38b049d2b5
This commit is contained in:
69
test/upsert4.test
Normal file
69
test/upsert4.test
Normal file
@ -0,0 +1,69 @@
|
||||
# 2018-04-17
|
||||
#
|
||||
# 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 upsert2
|
||||
|
||||
foreach {tn sql} {
|
||||
1 { CREATE TABLE t1(a INTEGER PRIMARY KEY, b, c UNIQUE) }
|
||||
2 { CREATE TABLE t1(a INT PRIMARY KEY, b, c UNIQUE) }
|
||||
3 { CREATE TABLE t1(a INT PRIMARY KEY, b, c UNIQUE) WITHOUT ROWID}
|
||||
} {
|
||||
reset_db
|
||||
execsql $sql
|
||||
|
||||
do_execsql_test 1.$tn.0 {
|
||||
INSERT INTO t1 VALUES(1, NULL, 'one');
|
||||
INSERT INTO t1 VALUES(2, NULL, 'two');
|
||||
INSERT INTO t1 VALUES(3, NULL, 'three');
|
||||
}
|
||||
|
||||
do_execsql_test 1.$tn.1 {
|
||||
INSERT INTO t1 VALUES(1, NULL, 'xyz') ON CONFLICT DO NOTHING;
|
||||
SELECT * FROM t1;
|
||||
} {
|
||||
1 {} one 2 {} two 3 {} three
|
||||
}
|
||||
|
||||
do_execsql_test 1.$tn.2 {
|
||||
INSERT INTO t1 VALUES(4, NULL, 'two') ON CONFLICT DO NOTHING;
|
||||
SELECT * FROM t1;
|
||||
} {
|
||||
1 {} one 2 {} two 3 {} three
|
||||
}
|
||||
|
||||
do_execsql_test 1.$tn.3 {
|
||||
INSERT INTO t1 VALUES(4, NULL, 'two') ON CONFLICT (c) DO UPDATE SET b = 1;
|
||||
SELECT * FROM t1;
|
||||
} {
|
||||
1 {} one 2 1 two 3 {} three
|
||||
}
|
||||
|
||||
do_execsql_test 1.$tn.4 {
|
||||
INSERT INTO t1 VALUES(2, NULL, 'zero') ON CONFLICT (a) DO UPDATE SET b=2;
|
||||
SELECT * FROM t1;
|
||||
} {1 {} one 2 2 two 3 {} three}
|
||||
|
||||
do_catchsql_test 1.$tn.5 {
|
||||
INSERT INTO t1 VALUES(2, NULL, 'zero') ON CONFLICT (a)
|
||||
DO UPDATE SET c = 'one';
|
||||
} {1 {UNIQUE constraint failed: t1.c}}
|
||||
|
||||
do_execsql_test 1.$tn.6 {
|
||||
SELECT * FROM t1;
|
||||
} {1 {} one 2 2 two 3 {} three}
|
||||
}
|
||||
|
||||
finish_test
|
||||
|
Reference in New Issue
Block a user