sl@0: # 2002 January 29 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests for the NOT NULL constraint. sl@0: # sl@0: # $Id: notnull.test,v 1.4 2006/01/17 09:35:02 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable !conflict { sl@0: finish_test sl@0: return sl@0: } sl@0: sl@0: do_test notnull-1.0 { sl@0: execsql { sl@0: CREATE TABLE t1 ( sl@0: a NOT NULL, sl@0: b NOT NULL DEFAULT 5, sl@0: c NOT NULL ON CONFLICT REPLACE DEFAULT 6, sl@0: d NOT NULL ON CONFLICT IGNORE DEFAULT 7, sl@0: e NOT NULL ON CONFLICT ABORT DEFAULT 8 sl@0: ); sl@0: SELECT * FROM t1; sl@0: } sl@0: } {} sl@0: do_test notnull-1.1 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 3 4 5}} sl@0: do_test notnull-1.2 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-1.3 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR IGNORE INTO t1(b,c,d,e) VALUES(2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {}} sl@0: do_test notnull-1.4 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-1.5 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-1.6 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,c,d,e) VALUES(1,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-1.7 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR IGNORE INTO t1(a,c,d,e) VALUES(1,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-1.8 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(a,c,d,e) VALUES(1,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-1.9 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(a,c,d,e) VALUES(1,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-1.10 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.b may not be NULL}} sl@0: do_test notnull-1.11 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {}} sl@0: do_test notnull-1.12 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-1.13 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 6 4 5}} sl@0: do_test notnull-1.14 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {}} sl@0: do_test notnull-1.15 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 6 4 5}} sl@0: do_test notnull-1.16 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.c may not be NULL}} sl@0: do_test notnull-1.17 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.d may not be NULL}} sl@0: do_test notnull-1.18 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(a,b,c,e) VALUES(1,2,3,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 3 7 5}} sl@0: do_test notnull-1.19 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d) VALUES(1,2,3,4); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 3 4 8}} sl@0: do_test notnull-1.20 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.e may not be NULL}} sl@0: do_test notnull-1.21 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(e,d,c,b,a) VALUES(1,2,3,null,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {5 5 3 2 1}} sl@0: sl@0: do_test notnull-2.1 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET a=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-2.2 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR REPLACE t1 SET a=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-2.3 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR IGNORE t1 SET a=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 2 3 4 5}} sl@0: do_test notnull-2.4 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR ABORT t1 SET a=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-2.5 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET b=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.b may not be NULL}} sl@0: do_test notnull-2.6 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR REPLACE t1 SET b=null, d=e, e=d; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 5 3 5 4}} sl@0: do_test notnull-2.7 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR IGNORE t1 SET b=null, d=e, e=d; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 2 3 4 5}} sl@0: do_test notnull-2.8 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET c=null, d=e, e=d; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 2 6 5 4}} sl@0: do_test notnull-2.9 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET d=null, a=b, b=a; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 2 3 4 5}} sl@0: do_test notnull-2.10 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET e=null, a=b, b=a; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.e may not be NULL}} sl@0: sl@0: do_test notnull-3.0 { sl@0: execsql { sl@0: CREATE INDEX t1a ON t1(a); sl@0: CREATE INDEX t1b ON t1(b); sl@0: CREATE INDEX t1c ON t1(c); sl@0: CREATE INDEX t1d ON t1(d); sl@0: CREATE INDEX t1e ON t1(e); sl@0: CREATE INDEX t1abc ON t1(a,b,c); sl@0: } sl@0: } {} sl@0: do_test notnull-3.1 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 3 4 5}} sl@0: do_test notnull-3.2 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-3.3 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR IGNORE INTO t1(b,c,d,e) VALUES(2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {}} sl@0: do_test notnull-3.4 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-3.5 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-3.6 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,c,d,e) VALUES(1,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-3.7 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR IGNORE INTO t1(a,c,d,e) VALUES(1,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-3.8 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(a,c,d,e) VALUES(1,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-3.9 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(a,c,d,e) VALUES(1,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-3.10 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.b may not be NULL}} sl@0: do_test notnull-3.11 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {}} sl@0: do_test notnull-3.12 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 5 3 4 5}} sl@0: do_test notnull-3.13 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 6 4 5}} sl@0: do_test notnull-3.14 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {}} sl@0: do_test notnull-3.15 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 6 4 5}} sl@0: do_test notnull-3.16 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.c may not be NULL}} sl@0: do_test notnull-3.17 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.d may not be NULL}} sl@0: do_test notnull-3.18 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR ABORT INTO t1(a,b,c,e) VALUES(1,2,3,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 3 7 5}} sl@0: do_test notnull-3.19 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d) VALUES(1,2,3,4); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {1 2 3 4 8}} sl@0: do_test notnull-3.20 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {1 {t1.e may not be NULL}} sl@0: do_test notnull-3.21 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT OR REPLACE INTO t1(e,d,c,b,a) VALUES(1,2,3,null,5); sl@0: SELECT * FROM t1 order by a; sl@0: } sl@0: } {0 {5 5 3 2 1}} sl@0: sl@0: do_test notnull-4.1 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET a=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-4.2 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR REPLACE t1 SET a=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-4.3 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR IGNORE t1 SET a=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 2 3 4 5}} sl@0: do_test notnull-4.4 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR ABORT t1 SET a=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.a may not be NULL}} sl@0: do_test notnull-4.5 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET b=null; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.b may not be NULL}} sl@0: do_test notnull-4.6 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR REPLACE t1 SET b=null, d=e, e=d; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 5 3 5 4}} sl@0: do_test notnull-4.7 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE OR IGNORE t1 SET b=null, d=e, e=d; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 2 3 4 5}} sl@0: do_test notnull-4.8 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET c=null, d=e, e=d; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 2 6 5 4}} sl@0: do_test notnull-4.9 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET d=null, a=b, b=a; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {0 {1 2 3 4 5}} sl@0: do_test notnull-4.10 { sl@0: catchsql { sl@0: DELETE FROM t1; sl@0: INSERT INTO t1 VALUES(1,2,3,4,5); sl@0: UPDATE t1 SET e=null, a=b, b=a; sl@0: SELECT * FROM t1 ORDER BY a; sl@0: } sl@0: } {1 {t1.e may not be NULL}} sl@0: sl@0: finish_test