| Index: third_party/sqlite/src/test/check.test
|
| diff --git a/third_party/sqlite/src/test/check.test b/third_party/sqlite/src/test/check.test
|
| index d2867a096ebc588dc63cba3572682e1eae658822..02b99f2ac9137c18a8507855d083f7393f8da49e 100644
|
| --- a/third_party/sqlite/src/test/check.test
|
| +++ b/third_party/sqlite/src/test/check.test
|
| @@ -15,6 +15,7 @@
|
|
|
| set testdir [file dirname $argv0]
|
| source $testdir/tester.tcl
|
| +set ::testprefix check
|
|
|
| # Only run these tests if the build includes support for CHECK constraints
|
| ifcapable !check {
|
| @@ -40,7 +41,7 @@ do_test check-1.3 {
|
| catchsql {
|
| INSERT INTO t1 VALUES(6,7);
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t1}}
|
| do_test check-1.4 {
|
| execsql {
|
| SELECT * FROM t1;
|
| @@ -50,7 +51,7 @@ do_test check-1.5 {
|
| catchsql {
|
| INSERT INTO t1 VALUES(4,3);
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t1}}
|
| do_test check-1.6 {
|
| execsql {
|
| SELECT * FROM t1;
|
| @@ -87,7 +88,7 @@ do_test check-1.12 {
|
| catchsql {
|
| UPDATE t1 SET x=7 WHERE x==2
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t1}}
|
| do_test check-1.13 {
|
| execsql {
|
| SELECT * FROM t1;
|
| @@ -97,7 +98,7 @@ do_test check-1.14 {
|
| catchsql {
|
| UPDATE t1 SET x=5 WHERE x==2
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t1}}
|
| do_test check-1.15 {
|
| execsql {
|
| SELECT * FROM t1;
|
| @@ -117,9 +118,9 @@ do_test check-1.17 {
|
| do_test check-2.1 {
|
| execsql {
|
| CREATE TABLE t2(
|
| - x INTEGER CHECK( typeof(coalesce(x,0))=="integer" ),
|
| - y REAL CHECK( typeof(coalesce(y,0.1))=='real' ),
|
| - z TEXT CHECK( typeof(coalesce(z,''))=='text' )
|
| + x INTEGER CONSTRAINT one CHECK( typeof(coalesce(x,0))=="integer" ),
|
| + y REAL CONSTRAINT two CHECK( typeof(coalesce(y,0.1))=='real' ),
|
| + z TEXT CONSTRAINT three CHECK( typeof(coalesce(z,''))=='text' )
|
| );
|
| }
|
| } {}
|
| @@ -141,17 +142,59 @@ do_test check-2.4 {
|
| catchsql {
|
| INSERT INTO t2 VALUES(1.1, NULL, NULL);
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: one}}
|
| do_test check-2.5 {
|
| catchsql {
|
| INSERT INTO t2 VALUES(NULL, 5, NULL);
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: two}}
|
| do_test check-2.6 {
|
| catchsql {
|
| INSERT INTO t2 VALUES(NULL, NULL, 3.14159);
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: three}}
|
| +
|
| +# Undocumented behavior: The CONSTRAINT name clause can follow a constraint.
|
| +# Such a clause is ignored. But the parser must accept it for backwards
|
| +# compatibility.
|
| +#
|
| +do_test check-2.10 {
|
| + execsql {
|
| + CREATE TABLE t2b(
|
| + x INTEGER CHECK( typeof(coalesce(x,0))=='integer' ) CONSTRAINT one,
|
| + y TEXT PRIMARY KEY constraint two,
|
| + z INTEGER,
|
| + UNIQUE(x,z) constraint three
|
| + );
|
| + }
|
| +} {}
|
| +do_test check-2.11 {
|
| + catchsql {
|
| + INSERT INTO t2b VALUES('xyzzy','hi',5);
|
| + }
|
| +} {1 {CHECK constraint failed: t2b}}
|
| +do_test check-2.12 {
|
| + execsql {
|
| + CREATE TABLE t2c(
|
| + x INTEGER CONSTRAINT x_one CONSTRAINT x_two
|
| + CHECK( typeof(coalesce(x,0))=='integer' )
|
| + CONSTRAINT x_two CONSTRAINT x_three,
|
| + y INTEGER, z INTEGER,
|
| + CONSTRAINT u_one UNIQUE(x,y,z) CONSTRAINT u_two
|
| + );
|
| + }
|
| +} {}
|
| +do_test check-2.13 {
|
| + catchsql {
|
| + INSERT INTO t2c VALUES('xyzzy',7,8);
|
| + }
|
| +} {1 {CHECK constraint failed: x_two}}
|
| +do_test check-2.cleanup {
|
| + execsql {
|
| + DROP TABLE IF EXISTS t2b;
|
| + DROP TABLE IF EXISTS t2c;
|
| + }
|
| +} {}
|
|
|
| ifcapable subquery {
|
| do_test check-3.1 {
|
| @@ -213,7 +256,7 @@ do_test check-3.9 {
|
| catchsql {
|
| INSERT INTO t3 VALUES(111,222,333);
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t3}}
|
|
|
| do_test check-4.1 {
|
| execsql {
|
| @@ -255,7 +298,7 @@ do_test check-4.6 {
|
| catchsql {
|
| UPDATE t4 SET x=0, y=1;
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t4}}
|
| do_test check-4.7 {
|
| execsql {
|
| SELECT * FROM t4;
|
| @@ -273,7 +316,7 @@ do_test check-4.9 {
|
| PRAGMA ignore_check_constraints=OFF;
|
| UPDATE t4 SET x=0, y=2;
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t4}}
|
| ifcapable vacuum {
|
| do_test check_4.10 {
|
| catchsql {
|
| @@ -324,7 +367,7 @@ do_test check-6.5 {
|
| catchsql {
|
| UPDATE OR FAIL t1 SET x=7-x, y=y+1;
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t1}}
|
| do_test check-6.6 {
|
| execsql {
|
| SELECT * FROM t1;
|
| @@ -336,7 +379,7 @@ do_test check-6.7 {
|
| INSERT INTO t1 VALUES(1,30.0);
|
| INSERT OR ROLLBACK INTO t1 VALUES(8,40.0);
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t1}}
|
| do_test check-6.8 {
|
| catchsql {
|
| COMMIT;
|
| @@ -355,7 +398,7 @@ do_test check-6.12 {
|
| catchsql {
|
| REPLACE INTO t1 VALUES(6,7);
|
| }
|
| -} {1 {constraint failed}}
|
| +} {1 {CHECK constraint failed: t1}}
|
| do_test check-6.13 {
|
| execsql {SELECT * FROM t1}
|
| } {3 12.0 2 20.0}
|
| @@ -371,4 +414,49 @@ do_test check-6.15 {
|
|
|
| }
|
|
|
| +#--------------------------------------------------------------------------
|
| +# If a connection opens a database that contains a CHECK constraint that
|
| +# uses an unknown UDF, the schema should not be considered malformed.
|
| +# Attempting to modify the table should fail (since the CHECK constraint
|
| +# cannot be tested).
|
| +#
|
| +reset_db
|
| +proc myfunc {x} {expr $x < 10}
|
| +db func myfunc myfunc
|
| +
|
| +do_execsql_test 7.1 { CREATE TABLE t6(a CHECK (myfunc(a))) }
|
| +do_execsql_test 7.2 { INSERT INTO t6 VALUES(9) }
|
| +do_catchsql_test 7.3 { INSERT INTO t6 VALUES(11) } \
|
| + {1 {CHECK constraint failed: t6}}
|
| +
|
| +do_test 7.4 {
|
| + sqlite3 db2 test.db
|
| + execsql { SELECT * FROM t6 } db2
|
| +} {9}
|
| +
|
| +do_test 7.5 {
|
| + catchsql { INSERT INTO t6 VALUES(8) } db2
|
| +} {1 {unknown function: myfunc()}}
|
| +
|
| +do_test 7.6 {
|
| + catchsql { CREATE TABLE t7(a CHECK (myfunc(a))) } db2
|
| +} {1 {no such function: myfunc}}
|
| +
|
| +do_test 7.7 {
|
| + db2 func myfunc myfunc
|
| + execsql { INSERT INTO t6 VALUES(8) } db2
|
| +} {}
|
| +
|
| +do_test 7.8 {
|
| + db2 func myfunc myfunc
|
| + catchsql { INSERT INTO t6 VALUES(12) } db2
|
| +} {1 {CHECK constraint failed: t6}}
|
| +
|
| +# 2013-08-02: Silently ignore database name qualifiers in CHECK constraints.
|
| +#
|
| +do_execsql_test 8.1 {
|
| + CREATE TABLE t810(a, CHECK( main.t810.a>0 ));
|
| + CREATE TABLE t811(b, CHECK( xyzzy.t811.b BETWEEN 5 AND 10 ));
|
| +} {}
|
| +
|
| finish_test
|
|
|