3 # The author disclaims copyright to this source code. In place of
4 # a legal notice, here is a blessing:
6 # May you do good and not evil.
7 # May you find forgiveness for yourself and forgive others.
8 # May you share freely, never taking more than you give.
10 #***********************************************************************
11 # This file implements regression tests for SQLite library.
13 # This file implements tests for the NOT NULL constraint.
15 # $Id: notnull.test,v 1.4 2006/01/17 09:35:02 danielk1977 Exp $
17 set testdir [file dirname $argv0]
18 source $testdir/tester.tcl
30 c NOT NULL ON CONFLICT REPLACE DEFAULT 6,
31 d NOT NULL ON CONFLICT IGNORE DEFAULT 7,
32 e NOT NULL ON CONFLICT ABORT DEFAULT 8
40 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,5);
41 SELECT * FROM t1 order by a;
47 INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5);
48 SELECT * FROM t1 order by a;
50 } {1 {t1.a may not be NULL}}
54 INSERT OR IGNORE INTO t1(b,c,d,e) VALUES(2,3,4,5);
55 SELECT * FROM t1 order by a;
61 INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5);
62 SELECT * FROM t1 order by a;
64 } {1 {t1.a may not be NULL}}
68 INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5);
69 SELECT * FROM t1 order by a;
71 } {1 {t1.a may not be NULL}}
75 INSERT INTO t1(a,c,d,e) VALUES(1,3,4,5);
76 SELECT * FROM t1 order by a;
82 INSERT OR IGNORE INTO t1(a,c,d,e) VALUES(1,3,4,5);
83 SELECT * FROM t1 order by a;
89 INSERT OR REPLACE INTO t1(a,c,d,e) VALUES(1,3,4,5);
90 SELECT * FROM t1 order by a;
96 INSERT OR ABORT INTO t1(a,c,d,e) VALUES(1,3,4,5);
97 SELECT * FROM t1 order by a;
100 do_test notnull-1.10 {
103 INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
104 SELECT * FROM t1 order by a;
106 } {1 {t1.b may not be NULL}}
107 do_test notnull-1.11 {
110 INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
111 SELECT * FROM t1 order by a;
114 do_test notnull-1.12 {
117 INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
118 SELECT * FROM t1 order by a;
121 do_test notnull-1.13 {
124 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
125 SELECT * FROM t1 order by a;
128 do_test notnull-1.14 {
131 INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
132 SELECT * FROM t1 order by a;
135 do_test notnull-1.15 {
138 INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
139 SELECT * FROM t1 order by a;
142 do_test notnull-1.16 {
145 INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
146 SELECT * FROM t1 order by a;
148 } {1 {t1.c may not be NULL}}
149 do_test notnull-1.17 {
152 INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5);
153 SELECT * FROM t1 order by a;
155 } {1 {t1.d may not be NULL}}
156 do_test notnull-1.18 {
159 INSERT OR ABORT INTO t1(a,b,c,e) VALUES(1,2,3,5);
160 SELECT * FROM t1 order by a;
163 do_test notnull-1.19 {
166 INSERT INTO t1(a,b,c,d) VALUES(1,2,3,4);
167 SELECT * FROM t1 order by a;
170 do_test notnull-1.20 {
173 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null);
174 SELECT * FROM t1 order by a;
176 } {1 {t1.e may not be NULL}}
177 do_test notnull-1.21 {
180 INSERT OR REPLACE INTO t1(e,d,c,b,a) VALUES(1,2,3,null,5);
181 SELECT * FROM t1 order by a;
185 do_test notnull-2.1 {
188 INSERT INTO t1 VALUES(1,2,3,4,5);
189 UPDATE t1 SET a=null;
190 SELECT * FROM t1 ORDER BY a;
192 } {1 {t1.a may not be NULL}}
193 do_test notnull-2.2 {
196 INSERT INTO t1 VALUES(1,2,3,4,5);
197 UPDATE OR REPLACE t1 SET a=null;
198 SELECT * FROM t1 ORDER BY a;
200 } {1 {t1.a may not be NULL}}
201 do_test notnull-2.3 {
204 INSERT INTO t1 VALUES(1,2,3,4,5);
205 UPDATE OR IGNORE t1 SET a=null;
206 SELECT * FROM t1 ORDER BY a;
209 do_test notnull-2.4 {
212 INSERT INTO t1 VALUES(1,2,3,4,5);
213 UPDATE OR ABORT t1 SET a=null;
214 SELECT * FROM t1 ORDER BY a;
216 } {1 {t1.a may not be NULL}}
217 do_test notnull-2.5 {
220 INSERT INTO t1 VALUES(1,2,3,4,5);
221 UPDATE t1 SET b=null;
222 SELECT * FROM t1 ORDER BY a;
224 } {1 {t1.b may not be NULL}}
225 do_test notnull-2.6 {
228 INSERT INTO t1 VALUES(1,2,3,4,5);
229 UPDATE OR REPLACE t1 SET b=null, d=e, e=d;
230 SELECT * FROM t1 ORDER BY a;
233 do_test notnull-2.7 {
236 INSERT INTO t1 VALUES(1,2,3,4,5);
237 UPDATE OR IGNORE t1 SET b=null, d=e, e=d;
238 SELECT * FROM t1 ORDER BY a;
241 do_test notnull-2.8 {
244 INSERT INTO t1 VALUES(1,2,3,4,5);
245 UPDATE t1 SET c=null, d=e, e=d;
246 SELECT * FROM t1 ORDER BY a;
249 do_test notnull-2.9 {
252 INSERT INTO t1 VALUES(1,2,3,4,5);
253 UPDATE t1 SET d=null, a=b, b=a;
254 SELECT * FROM t1 ORDER BY a;
257 do_test notnull-2.10 {
260 INSERT INTO t1 VALUES(1,2,3,4,5);
261 UPDATE t1 SET e=null, a=b, b=a;
262 SELECT * FROM t1 ORDER BY a;
264 } {1 {t1.e may not be NULL}}
266 do_test notnull-3.0 {
268 CREATE INDEX t1a ON t1(a);
269 CREATE INDEX t1b ON t1(b);
270 CREATE INDEX t1c ON t1(c);
271 CREATE INDEX t1d ON t1(d);
272 CREATE INDEX t1e ON t1(e);
273 CREATE INDEX t1abc ON t1(a,b,c);
276 do_test notnull-3.1 {
279 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,5);
280 SELECT * FROM t1 order by a;
283 do_test notnull-3.2 {
286 INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5);
287 SELECT * FROM t1 order by a;
289 } {1 {t1.a may not be NULL}}
290 do_test notnull-3.3 {
293 INSERT OR IGNORE INTO t1(b,c,d,e) VALUES(2,3,4,5);
294 SELECT * FROM t1 order by a;
297 do_test notnull-3.4 {
300 INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5);
301 SELECT * FROM t1 order by a;
303 } {1 {t1.a may not be NULL}}
304 do_test notnull-3.5 {
307 INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5);
308 SELECT * FROM t1 order by a;
310 } {1 {t1.a may not be NULL}}
311 do_test notnull-3.6 {
314 INSERT INTO t1(a,c,d,e) VALUES(1,3,4,5);
315 SELECT * FROM t1 order by a;
318 do_test notnull-3.7 {
321 INSERT OR IGNORE INTO t1(a,c,d,e) VALUES(1,3,4,5);
322 SELECT * FROM t1 order by a;
325 do_test notnull-3.8 {
328 INSERT OR REPLACE INTO t1(a,c,d,e) VALUES(1,3,4,5);
329 SELECT * FROM t1 order by a;
332 do_test notnull-3.9 {
335 INSERT OR ABORT INTO t1(a,c,d,e) VALUES(1,3,4,5);
336 SELECT * FROM t1 order by a;
339 do_test notnull-3.10 {
342 INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
343 SELECT * FROM t1 order by a;
345 } {1 {t1.b may not be NULL}}
346 do_test notnull-3.11 {
349 INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
350 SELECT * FROM t1 order by a;
353 do_test notnull-3.12 {
356 INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
357 SELECT * FROM t1 order by a;
360 do_test notnull-3.13 {
363 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
364 SELECT * FROM t1 order by a;
367 do_test notnull-3.14 {
370 INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
371 SELECT * FROM t1 order by a;
374 do_test notnull-3.15 {
377 INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
378 SELECT * FROM t1 order by a;
381 do_test notnull-3.16 {
384 INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
385 SELECT * FROM t1 order by a;
387 } {1 {t1.c may not be NULL}}
388 do_test notnull-3.17 {
391 INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5);
392 SELECT * FROM t1 order by a;
394 } {1 {t1.d may not be NULL}}
395 do_test notnull-3.18 {
398 INSERT OR ABORT INTO t1(a,b,c,e) VALUES(1,2,3,5);
399 SELECT * FROM t1 order by a;
402 do_test notnull-3.19 {
405 INSERT INTO t1(a,b,c,d) VALUES(1,2,3,4);
406 SELECT * FROM t1 order by a;
409 do_test notnull-3.20 {
412 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null);
413 SELECT * FROM t1 order by a;
415 } {1 {t1.e may not be NULL}}
416 do_test notnull-3.21 {
419 INSERT OR REPLACE INTO t1(e,d,c,b,a) VALUES(1,2,3,null,5);
420 SELECT * FROM t1 order by a;
424 do_test notnull-4.1 {
427 INSERT INTO t1 VALUES(1,2,3,4,5);
428 UPDATE t1 SET a=null;
429 SELECT * FROM t1 ORDER BY a;
431 } {1 {t1.a may not be NULL}}
432 do_test notnull-4.2 {
435 INSERT INTO t1 VALUES(1,2,3,4,5);
436 UPDATE OR REPLACE t1 SET a=null;
437 SELECT * FROM t1 ORDER BY a;
439 } {1 {t1.a may not be NULL}}
440 do_test notnull-4.3 {
443 INSERT INTO t1 VALUES(1,2,3,4,5);
444 UPDATE OR IGNORE t1 SET a=null;
445 SELECT * FROM t1 ORDER BY a;
448 do_test notnull-4.4 {
451 INSERT INTO t1 VALUES(1,2,3,4,5);
452 UPDATE OR ABORT t1 SET a=null;
453 SELECT * FROM t1 ORDER BY a;
455 } {1 {t1.a may not be NULL}}
456 do_test notnull-4.5 {
459 INSERT INTO t1 VALUES(1,2,3,4,5);
460 UPDATE t1 SET b=null;
461 SELECT * FROM t1 ORDER BY a;
463 } {1 {t1.b may not be NULL}}
464 do_test notnull-4.6 {
467 INSERT INTO t1 VALUES(1,2,3,4,5);
468 UPDATE OR REPLACE t1 SET b=null, d=e, e=d;
469 SELECT * FROM t1 ORDER BY a;
472 do_test notnull-4.7 {
475 INSERT INTO t1 VALUES(1,2,3,4,5);
476 UPDATE OR IGNORE t1 SET b=null, d=e, e=d;
477 SELECT * FROM t1 ORDER BY a;
480 do_test notnull-4.8 {
483 INSERT INTO t1 VALUES(1,2,3,4,5);
484 UPDATE t1 SET c=null, d=e, e=d;
485 SELECT * FROM t1 ORDER BY a;
488 do_test notnull-4.9 {
491 INSERT INTO t1 VALUES(1,2,3,4,5);
492 UPDATE t1 SET d=null, a=b, b=a;
493 SELECT * FROM t1 ORDER BY a;
496 do_test notnull-4.10 {
499 INSERT INTO t1 VALUES(1,2,3,4,5);
500 UPDATE t1 SET e=null, a=b, b=a;
501 SELECT * FROM t1 ORDER BY a;
503 } {1 {t1.e may not be NULL}}
505 # Test that bug 29ab7be99f is fixed.
507 do_test notnull-5.1 {
509 DROP TABLE IF EXISTS t1;
510 CREATE TABLE t1(a, b NOT NULL);
511 CREATE TABLE t2(c, d);
512 INSERT INTO t2 VALUES(3, 4);
513 INSERT INTO t2 VALUES(5, NULL);
516 do_test notnull-5.2 {
518 INSERT INTO t1 VALUES(1, 2);
519 INSERT INTO t1 SELECT * FROM t2;
521 } {1 {t1.b may not be NULL}}
522 do_test notnull-5.3 {
523 execsql { SELECT * FROM t1 }
525 do_test notnull-5.4 {
529 INSERT INTO t1 VALUES(1, 2);
530 INSERT INTO t1 SELECT * FROM t2;
533 } {1 {t1.b may not be NULL}}
534 do_test notnull-5.5 {
535 execsql { SELECT * FROM t1 }