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. The
12 # focus of this file is testing expressions of the form
19 # Tests are also included for the use of TRUE and FALSE as
22 set testdir [file dirname $argv0]
23 source $testdir/tester.tcl
25 do_execsql_test istrue-100 {
26 CREATE TABLE t1(x INTEGER PRIMARY KEY, y BOOLEAN);
27 INSERT INTO t1 VALUES(1, true),(2, false),(3, null);
28 SELECT x FROM t1 WHERE y IS TRUE;
30 do_execsql_test istrue-110 {
31 SELECT x FROM t1 WHERE y IS FALSE;
33 do_execsql_test istrue-120 {
34 SELECT x FROM t1 WHERE y IS NULL;
36 do_execsql_test istrue-130 {
37 SELECT x FROM t1 WHERE y IS NOT TRUE;
39 do_execsql_test istrue-140 {
40 SELECT x FROM t1 WHERE y IS NOT FALSE;
42 do_execsql_test istrue-150 {
43 SELECT x FROM t1 WHERE y IS NOT NULL;
47 do_execsql_test istrue-160 {
48 SELECT x FROM t1 WHERE y IS TRUE OR (8==$X)
50 do_execsql_test istrue-170 {
51 SELECT x FROM t1 WHERE y IS FALSE OR (8==$X)
53 do_execsql_test istrue-180 {
54 SELECT x FROM t1 WHERE y IS NULL OR (8==$X);
56 do_execsql_test istrue-190 {
57 SELECT x FROM t1 WHERE y IS NOT TRUE OR (8==$X);
59 do_execsql_test istrue-200 {
60 SELECT x FROM t1 WHERE y IS NOT FALSE OR (8==$X);
62 do_execsql_test istrue-210 {
63 SELECT x FROM t1 WHERE y IS NOT NULL OR (8==$X);
66 do_execsql_test istrue-300 {
68 y IS TRUE, y IS FALSE, y is NULL,
69 y IS NOT TRUE, y IS NOT FALSE, y IS NOT NULL, '|'
71 } {1 1 0 0 0 1 1 | 2 0 1 0 1 0 1 | 3 0 0 1 1 1 0 |}
73 do_execsql_test istrue-400 {
74 SELECT x FROM t1 WHERE true;
76 do_execsql_test istrue-410 {
77 SELECT x FROM t1 WHERE false;
80 do_execsql_test istrue-500 {
82 a INTEGER PRIMARY KEY,
83 b BOOLEAN DEFAULT true,
84 c BOOLEAN DEFAULT(true),
85 d BOOLEAN DEFAULT false,
86 e BOOLEAN DEFAULT(false)
88 INSERT INTO t2 DEFAULT VALUES;
91 do_execsql_test istrue-510 {
94 a INTEGER PRIMARY KEY,
95 b BOOLEAN DEFAULT(not true),
96 c BOOLEAN DEFAULT(not false)
98 INSERT INTO t2(a) VALUES(99);
101 do_execsql_test istrue-520 {
104 a INTEGER PRIMARY KEY,
105 b BOOLEAN CHECK(b IS TRUE),
106 c BOOLEAN CHECK(c IS FALSE),
107 d BOOLEAN CHECK(d IS NOT TRUE),
108 e BOOLEAN CHECK(e IS NOT FALSE)
110 INSERT INTO t2 VALUES(1,true,false,null,null);
113 do_catchsql_test istrue-521 {
114 INSERT INTO t2 VALUES(2,false,false,null,null);
115 } {1 {CHECK constraint failed: t2}}
116 do_catchsql_test istrue-522 {
117 INSERT INTO t2 VALUES(2,true,true,null,null);
118 } {1 {CHECK constraint failed: t2}}
119 do_catchsql_test istrue-523 {
120 INSERT INTO t2 VALUES(2,true,false,true,null);
121 } {1 {CHECK constraint failed: t2}}
122 do_catchsql_test istrue-524 {
123 INSERT INTO t2 VALUES(2,true,false,null,false);
124 } {1 {CHECK constraint failed: t2}}
126 foreach {tn val} [list 1 NaN 2 -NaN 3 NaN0 4 -NaN0 5 Inf 6 -Inf] {
127 do_execsql_test istrue-600.$tn.1 {
128 DROP TABLE IF EXISTS t1;
131 do_test istrue-600.$tn.2 {
132 set ::STMT [sqlite3_prepare db "INSERT INTO t1 VALUES(?)" -1 TAIL]
133 sqlite3_bind_double $::STMT 1 $val
135 sqlite3_reset $::STMT
136 sqlite3_finalize $::STMT
138 do_execsql_test istrue-600.$tn.3 {
139 SELECT x IS TRUE FROM t1;
140 } [expr {$tn in [list 5 6] ? {1} : {0}}]
141 do_execsql_test istrue-600.$tn.4 {
142 SELECT x IS FALSE FROM t1;
146 do_execsql_test istrue-700 {
148 a INTEGER PRIMARY KEY,
149 b BOOLEAN DEFAULT false,
150 c BOOLEAN DEFAULT true
152 INSERT INTO t7(a) VALUES(1);
153 INSERT INTO t7(a,b,c) VALUES(2,true,false);
154 ALTER TABLE t7 ADD COLUMN d BOOLEAN DEFAULT false;
155 ALTER TABLE t7 ADD COLUMN e BOOLEAN DEFAULT true;
156 INSERT INTO t7(a,b,c) VALUES(3,true,false);
157 INSERT INTO t7 VALUES(4,false,true,true,false);
158 SELECT *,'x' FROM t7 ORDER BY a;
159 } {1 0 1 0 1 x 2 1 0 0 1 x 3 1 0 0 1 x 4 0 1 1 0 x}