2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library.
16 # This file implements tests for the NOT NULL constraint.
18 # $Id: notnull.test,v 1.3 2003/01/29 18:46:54 drh Exp $
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
28 c NOT NULL ON CONFLICT REPLACE DEFAULT 6,
29 d NOT NULL ON CONFLICT IGNORE DEFAULT 7,
30 e NOT NULL ON CONFLICT ABORT DEFAULT 8
38 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,5);
39 SELECT * FROM t1 order by a;
45 INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5);
46 SELECT * FROM t1 order by a;
48 } {1 {t1.a may not be NULL}}
52 INSERT OR IGNORE INTO t1(b,c,d,e) VALUES(2,3,4,5);
53 SELECT * FROM t1 order by a;
59 INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5);
60 SELECT * FROM t1 order by a;
62 } {1 {t1.a may not be NULL}}
66 INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5);
67 SELECT * FROM t1 order by a;
69 } {1 {t1.a may not be NULL}}
73 INSERT INTO t1(a,c,d,e) VALUES(1,3,4,5);
74 SELECT * FROM t1 order by a;
80 INSERT OR IGNORE INTO t1(a,c,d,e) VALUES(1,3,4,5);
81 SELECT * FROM t1 order by a;
87 INSERT OR REPLACE INTO t1(a,c,d,e) VALUES(1,3,4,5);
88 SELECT * FROM t1 order by a;
94 INSERT OR ABORT INTO t1(a,c,d,e) VALUES(1,3,4,5);
95 SELECT * FROM t1 order by a;
98 do_test notnull-1.10 {
101 INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
102 SELECT * FROM t1 order by a;
104 } {1 {t1.b may not be NULL}}
105 do_test notnull-1.11 {
108 INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
109 SELECT * FROM t1 order by a;
112 do_test notnull-1.12 {
115 INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
116 SELECT * FROM t1 order by a;
119 do_test notnull-1.13 {
122 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
123 SELECT * FROM t1 order by a;
126 do_test notnull-1.14 {
129 INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
130 SELECT * FROM t1 order by a;
133 do_test notnull-1.15 {
136 INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
137 SELECT * FROM t1 order by a;
140 do_test notnull-1.16 {
143 INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
144 SELECT * FROM t1 order by a;
146 } {1 {t1.c may not be NULL}}
147 do_test notnull-1.17 {
150 INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5);
151 SELECT * FROM t1 order by a;
153 } {1 {t1.d may not be NULL}}
154 do_test notnull-1.18 {
157 INSERT OR ABORT INTO t1(a,b,c,e) VALUES(1,2,3,5);
158 SELECT * FROM t1 order by a;
161 do_test notnull-1.19 {
164 INSERT INTO t1(a,b,c,d) VALUES(1,2,3,4);
165 SELECT * FROM t1 order by a;
168 do_test notnull-1.20 {
171 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null);
172 SELECT * FROM t1 order by a;
174 } {1 {t1.e may not be NULL}}
175 do_test notnull-1.21 {
178 INSERT OR REPLACE INTO t1(e,d,c,b,a) VALUES(1,2,3,null,5);
179 SELECT * FROM t1 order by a;
183 do_test notnull-2.1 {
186 INSERT INTO t1 VALUES(1,2,3,4,5);
187 UPDATE t1 SET a=null;
188 SELECT * FROM t1 ORDER BY a;
190 } {1 {t1.a may not be NULL}}
191 do_test notnull-2.2 {
194 INSERT INTO t1 VALUES(1,2,3,4,5);
195 UPDATE OR REPLACE t1 SET a=null;
196 SELECT * FROM t1 ORDER BY a;
198 } {1 {t1.a may not be NULL}}
199 do_test notnull-2.3 {
202 INSERT INTO t1 VALUES(1,2,3,4,5);
203 UPDATE OR IGNORE t1 SET a=null;
204 SELECT * FROM t1 ORDER BY a;
207 do_test notnull-2.4 {
210 INSERT INTO t1 VALUES(1,2,3,4,5);
211 UPDATE OR ABORT t1 SET a=null;
212 SELECT * FROM t1 ORDER BY a;
214 } {1 {t1.a may not be NULL}}
215 do_test notnull-2.5 {
218 INSERT INTO t1 VALUES(1,2,3,4,5);
219 UPDATE t1 SET b=null;
220 SELECT * FROM t1 ORDER BY a;
222 } {1 {t1.b may not be NULL}}
223 do_test notnull-2.6 {
226 INSERT INTO t1 VALUES(1,2,3,4,5);
227 UPDATE OR REPLACE t1 SET b=null, d=e, e=d;
228 SELECT * FROM t1 ORDER BY a;
231 do_test notnull-2.7 {
234 INSERT INTO t1 VALUES(1,2,3,4,5);
235 UPDATE OR IGNORE t1 SET b=null, d=e, e=d;
236 SELECT * FROM t1 ORDER BY a;
239 do_test notnull-2.8 {
242 INSERT INTO t1 VALUES(1,2,3,4,5);
243 UPDATE t1 SET c=null, d=e, e=d;
244 SELECT * FROM t1 ORDER BY a;
247 do_test notnull-2.9 {
250 INSERT INTO t1 VALUES(1,2,3,4,5);
251 UPDATE t1 SET d=null, a=b, b=a;
252 SELECT * FROM t1 ORDER BY a;
255 do_test notnull-2.10 {
258 INSERT INTO t1 VALUES(1,2,3,4,5);
259 UPDATE t1 SET e=null, a=b, b=a;
260 SELECT * FROM t1 ORDER BY a;
262 } {1 {t1.e may not be NULL}}
264 do_test notnull-3.0 {
266 CREATE INDEX t1a ON t1(a);
267 CREATE INDEX t1b ON t1(b);
268 CREATE INDEX t1c ON t1(c);
269 CREATE INDEX t1d ON t1(d);
270 CREATE INDEX t1e ON t1(e);
271 CREATE INDEX t1abc ON t1(a,b,c);
274 do_test notnull-3.1 {
277 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,5);
278 SELECT * FROM t1 order by a;
281 do_test notnull-3.2 {
284 INSERT INTO t1(b,c,d,e) VALUES(2,3,4,5);
285 SELECT * FROM t1 order by a;
287 } {1 {t1.a may not be NULL}}
288 do_test notnull-3.3 {
291 INSERT OR IGNORE INTO t1(b,c,d,e) VALUES(2,3,4,5);
292 SELECT * FROM t1 order by a;
295 do_test notnull-3.4 {
298 INSERT OR REPLACE INTO t1(b,c,d,e) VALUES(2,3,4,5);
299 SELECT * FROM t1 order by a;
301 } {1 {t1.a may not be NULL}}
302 do_test notnull-3.5 {
305 INSERT OR ABORT INTO t1(b,c,d,e) VALUES(2,3,4,5);
306 SELECT * FROM t1 order by a;
308 } {1 {t1.a may not be NULL}}
309 do_test notnull-3.6 {
312 INSERT INTO t1(a,c,d,e) VALUES(1,3,4,5);
313 SELECT * FROM t1 order by a;
316 do_test notnull-3.7 {
319 INSERT OR IGNORE INTO t1(a,c,d,e) VALUES(1,3,4,5);
320 SELECT * FROM t1 order by a;
323 do_test notnull-3.8 {
326 INSERT OR REPLACE INTO t1(a,c,d,e) VALUES(1,3,4,5);
327 SELECT * FROM t1 order by a;
330 do_test notnull-3.9 {
333 INSERT OR ABORT INTO t1(a,c,d,e) VALUES(1,3,4,5);
334 SELECT * FROM t1 order by a;
337 do_test notnull-3.10 {
340 INSERT INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
341 SELECT * FROM t1 order by a;
343 } {1 {t1.b may not be NULL}}
344 do_test notnull-3.11 {
347 INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
348 SELECT * FROM t1 order by a;
351 do_test notnull-3.12 {
354 INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,null,3,4,5);
355 SELECT * FROM t1 order by a;
358 do_test notnull-3.13 {
361 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
362 SELECT * FROM t1 order by a;
365 do_test notnull-3.14 {
368 INSERT OR IGNORE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
369 SELECT * FROM t1 order by a;
372 do_test notnull-3.15 {
375 INSERT OR REPLACE INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
376 SELECT * FROM t1 order by a;
379 do_test notnull-3.16 {
382 INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,null,4,5);
383 SELECT * FROM t1 order by a;
385 } {1 {t1.c may not be NULL}}
386 do_test notnull-3.17 {
389 INSERT OR ABORT INTO t1(a,b,c,d,e) VALUES(1,2,3,null,5);
390 SELECT * FROM t1 order by a;
392 } {1 {t1.d may not be NULL}}
393 do_test notnull-3.18 {
396 INSERT OR ABORT INTO t1(a,b,c,e) VALUES(1,2,3,5);
397 SELECT * FROM t1 order by a;
400 do_test notnull-3.19 {
403 INSERT INTO t1(a,b,c,d) VALUES(1,2,3,4);
404 SELECT * FROM t1 order by a;
407 do_test notnull-3.20 {
410 INSERT INTO t1(a,b,c,d,e) VALUES(1,2,3,4,null);
411 SELECT * FROM t1 order by a;
413 } {1 {t1.e may not be NULL}}
414 do_test notnull-3.21 {
417 INSERT OR REPLACE INTO t1(e,d,c,b,a) VALUES(1,2,3,null,5);
418 SELECT * FROM t1 order by a;
422 do_test notnull-4.1 {
425 INSERT INTO t1 VALUES(1,2,3,4,5);
426 UPDATE t1 SET a=null;
427 SELECT * FROM t1 ORDER BY a;
429 } {1 {t1.a may not be NULL}}
430 do_test notnull-4.2 {
433 INSERT INTO t1 VALUES(1,2,3,4,5);
434 UPDATE OR REPLACE t1 SET a=null;
435 SELECT * FROM t1 ORDER BY a;
437 } {1 {t1.a may not be NULL}}
438 do_test notnull-4.3 {
441 INSERT INTO t1 VALUES(1,2,3,4,5);
442 UPDATE OR IGNORE t1 SET a=null;
443 SELECT * FROM t1 ORDER BY a;
446 do_test notnull-4.4 {
449 INSERT INTO t1 VALUES(1,2,3,4,5);
450 UPDATE OR ABORT t1 SET a=null;
451 SELECT * FROM t1 ORDER BY a;
453 } {1 {t1.a may not be NULL}}
454 do_test notnull-4.5 {
457 INSERT INTO t1 VALUES(1,2,3,4,5);
458 UPDATE t1 SET b=null;
459 SELECT * FROM t1 ORDER BY a;
461 } {1 {t1.b may not be NULL}}
462 do_test notnull-4.6 {
465 INSERT INTO t1 VALUES(1,2,3,4,5);
466 UPDATE OR REPLACE t1 SET b=null, d=e, e=d;
467 SELECT * FROM t1 ORDER BY a;
470 do_test notnull-4.7 {
473 INSERT INTO t1 VALUES(1,2,3,4,5);
474 UPDATE OR IGNORE t1 SET b=null, d=e, e=d;
475 SELECT * FROM t1 ORDER BY a;
478 do_test notnull-4.8 {
481 INSERT INTO t1 VALUES(1,2,3,4,5);
482 UPDATE t1 SET c=null, d=e, e=d;
483 SELECT * FROM t1 ORDER BY a;
486 do_test notnull-4.9 {
489 INSERT INTO t1 VALUES(1,2,3,4,5);
490 UPDATE t1 SET d=null, a=b, b=a;
491 SELECT * FROM t1 ORDER BY a;
494 do_test notnull-4.10 {
497 INSERT INTO t1 VALUES(1,2,3,4,5);
498 UPDATE t1 SET e=null, a=b, b=a;
499 SELECT * FROM t1 ORDER BY a;
501 } {1 {t1.e may not be NULL}}