123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500 |
- # 2002 January 29
- #
- # 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.
- #
- #***********************************************************************
- # This file implements regression tests for SQLite library.
- #
- # This file implements tests for the NOT NULL constraint.
- #
- # $Id: notnull.test,v 1.2 2002/01/31 15:54:23 drh Exp $
- set testdir [file dirname $argv0]
- source $testdir/tester.tcl
- do_test notnull-1.0 {
- execsql {
- CREATE TABLE t1 (
- a NOT NULL,
- b NOT NULL DEFAULT 5,
- c NOT NULL ON CONFLICT REPLACE DEFAULT 6,
- d NOT NULL ON CONFLICT IGNORE DEFAULT 7,
- e NOT NULL ON CONFLICT ABORT DEFAULT 8
- );
- SELECT * FROM t1;
- }
- } {}
- do_test notnull-1.1 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 3 4 5}}
- do_test notnull-1.2 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-1.3 {
- catchsql {
- DELETE FROM t1;
- INSERT OR IGNORE INTO t1(b,c,d,e) VALUES(2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {}}
- do_test notnull-1.4 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-1.5 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-1.6 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,c,d,e) VALUES(1,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-1.7 {
- catchsql {
- DELETE FROM t1;
- INSERT OR IGNORE INTO t1(a,c,d,e) VALUES(1,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-1.8 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(a,c,d,e) VALUES(1,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-1.9 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(a,c,d,e) VALUES(1,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-1.10 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-1.11 {
- catchsql {
- DELETE FROM t1;
- INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {}}
- do_test notnull-1.12 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-1.13 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 6 4 5}}
- do_test notnull-1.14 {
- catchsql {
- DELETE FROM t1;
- INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {}}
- do_test notnull-1.15 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 6 4 5}}
- do_test notnull-1.16 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-1.17 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-1.18 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(a,b,c,e) VALUES(1,2,3,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 3 7 5}}
- do_test notnull-1.19 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d) VALUES(1,2,3,4);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 3 4 8}}
- do_test notnull-1.20 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-1.21 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(e,d,c,b,a) VALUES(1,2,3,null,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {5 5 3 2 1}}
- do_test notnull-2.1 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET a=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- do_test notnull-2.2 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR REPLACE t1 SET a=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- do_test notnull-2.3 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR IGNORE t1 SET a=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 2 3 4 5}}
- do_test notnull-2.4 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR ABORT t1 SET a=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- do_test notnull-2.5 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET b=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- do_test notnull-2.6 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR REPLACE t1 SET b=null, d=e, e=d;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 5 3 5 4}}
- do_test notnull-2.7 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR IGNORE t1 SET b=null, d=e, e=d;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 2 3 4 5}}
- do_test notnull-2.8 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET c=null, d=e, e=d;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 2 6 5 4}}
- do_test notnull-2.9 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET d=null, a=b, b=a;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 2 3 4 5}}
- do_test notnull-2.10 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET e=null, a=b, b=a;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- do_test notnull-3.0 {
- execsql {
- CREATE INDEX t1a ON t1(a);
- CREATE INDEX t1b ON t1(b);
- CREATE INDEX t1c ON t1(c);
- CREATE INDEX t1d ON t1(d);
- CREATE INDEX t1e ON t1(e);
- CREATE INDEX t1abc ON t1(a,b,c);
- }
- } {}
- do_test notnull-3.1 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 3 4 5}}
- do_test notnull-3.2 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-3.3 {
- catchsql {
- DELETE FROM t1;
- INSERT OR IGNORE INTO t1(b,c,d,e) VALUES(2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {}}
- do_test notnull-3.4 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-3.5 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-3.6 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,c,d,e) VALUES(1,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-3.7 {
- catchsql {
- DELETE FROM t1;
- INSERT OR IGNORE INTO t1(a,c,d,e) VALUES(1,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-3.8 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(a,c,d,e) VALUES(1,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-3.9 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(a,c,d,e) VALUES(1,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-3.10 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-3.11 {
- catchsql {
- DELETE FROM t1;
- INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {}}
- do_test notnull-3.12 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 5 3 4 5}}
- do_test notnull-3.13 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 6 4 5}}
- do_test notnull-3.14 {
- catchsql {
- DELETE FROM t1;
- INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {}}
- do_test notnull-3.15 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 6 4 5}}
- do_test notnull-3.16 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-3.17 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-3.18 {
- catchsql {
- DELETE FROM t1;
- INSERT OR ABORT INTO t1(a,b,c,e) VALUES(1,2,3,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 3 7 5}}
- do_test notnull-3.19 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d) VALUES(1,2,3,4);
- SELECT * FROM t1 order by a;
- }
- } {0 {1 2 3 4 8}}
- do_test notnull-3.20 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null);
- SELECT * FROM t1 order by a;
- }
- } {1 {constraint failed}}
- do_test notnull-3.21 {
- catchsql {
- DELETE FROM t1;
- INSERT OR REPLACE INTO t1(e,d,c,b,a) VALUES(1,2,3,null,5);
- SELECT * FROM t1 order by a;
- }
- } {0 {5 5 3 2 1}}
- do_test notnull-4.1 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET a=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- do_test notnull-4.2 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR REPLACE t1 SET a=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- do_test notnull-4.3 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR IGNORE t1 SET a=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 2 3 4 5}}
- do_test notnull-4.4 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR ABORT t1 SET a=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- do_test notnull-4.5 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET b=null;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- do_test notnull-4.6 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR REPLACE t1 SET b=null, d=e, e=d;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 5 3 5 4}}
- do_test notnull-4.7 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE OR IGNORE t1 SET b=null, d=e, e=d;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 2 3 4 5}}
- do_test notnull-4.8 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET c=null, d=e, e=d;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 2 6 5 4}}
- do_test notnull-4.9 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET d=null, a=b, b=a;
- SELECT * FROM t1 ORDER BY a;
- }
- } {0 {1 2 3 4 5}}
- do_test notnull-4.10 {
- catchsql {
- DELETE FROM t1;
- INSERT INTO t1 VALUES(1,2,3,4,5);
- UPDATE t1 SET e=null, a=b, b=a;
- SELECT * FROM t1 ORDER BY a;
- }
- } {1 {constraint failed}}
- finish_test
|