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 miscellanous features that were
17 # left out of other test files.
19 # $Id: misc3.test,v 1.10 2004/03/17 23:32:08 drh Exp $
21 set testdir [file dirname $argv0]
22 source $testdir/tester.tcl
24 # Ticket #529. Make sure an ABORT does not damage the in-memory cache
25 # that will be used by subsequent statements in the same transaction.
29 CREATE TABLE t1(a UNIQUE,b);
31 VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_');
37 INSERT INTO t1 VALUES(2,'x');
38 UPDATE t1 SET b=substr(b,1,500);
41 catchsql {UPDATE t1 SET a=CASE a WHEN 2 THEN 1 ELSE a END, b='y';}
45 PRAGMA integrity_check;
53 CREATE TABLE t1(a UNIQUE,b);
55 VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_');
56 INSERT INTO t1 SELECT a+1, b||b FROM t1;
57 INSERT INTO t1 SELECT a+2, b||b FROM t1;
58 INSERT INTO t1 SELECT a+4, b FROM t1;
59 INSERT INTO t1 SELECT a+8, b FROM t1;
60 INSERT INTO t1 SELECT a+16, b FROM t1;
61 INSERT INTO t1 SELECT a+32, b FROM t1;
62 INSERT INTO t1 SELECT a+64, b FROM t1;
66 catchsql {UPDATE t1 SET a=CASE a WHEN 128 THEN 127 ELSE a END, b='';}
68 INSERT INTO t1 VALUES(200,'hello out there');
70 PRAGMA integrity_check;
74 # Tests of the sqliteAtoF() function in util.c
77 execsql {SELECT 2e-25*0.5e25}
80 execsql {SELECT 2.0e-25*000000.500000000000000000000000000000e+00025}
83 execsql {SELECT 000000000002e-0000000025*0.5e25}
86 execsql {SELECT 2e-25*0.5e250}
89 execsql {SELECT 2.0e-250*0.5e25}
92 execsql {SELECT '-2.0e-127' * '-0.5e27'}
95 execsql {SELECT '+2.0e-127' * '-0.5e27'}
98 execsql {SELECT 2.0e-27 * '+0.5e+127'}
101 execsql {SELECT 2.0e-27 * '+0.000005e+132'}
104 # Ticket #522. Make sure integer overflow is handled properly in
108 execsql {PRAGMA integrity_check}
112 CREATE TABLE t2(a INT UNIQUE);
113 PRAGMA integrity_check;
118 INSERT INTO t2 VALUES(2147483648);
119 PRAGMA integrity_check;
124 INSERT INTO t2 VALUES(-2147483649);
125 PRAGMA integrity_check;
130 INSERT INTO t2 VALUES(+2147483649);
131 PRAGMA integrity_check;
136 INSERT INTO t2 VALUES(+2147483647);
137 INSERT INTO t2 VALUES(-2147483648);
138 INSERT INTO t2 VALUES(-2147483647);
139 INSERT INTO t2 VALUES(2147483646);
140 SELECT * FROM t2 ORDER BY a;
142 } {-2147483649 -2147483648 -2147483647 2147483646 2147483647 2147483648 2147483649}
145 SELECT * FROM t2 WHERE a>=-2147483648 ORDER BY a;
147 } {-2147483648 -2147483647 2147483646 2147483647 2147483648 2147483649}
150 SELECT * FROM t2 WHERE a>-2147483648 ORDER BY a;
152 } {-2147483647 2147483646 2147483647 2147483648 2147483649}
155 SELECT * FROM t2 WHERE a>-2147483649 ORDER BY a;
157 } {-2147483648 -2147483647 2147483646 2147483647 2147483648 2147483649}
160 SELECT * FROM t2 WHERE a>=0 AND a<2147483649 ORDER BY a DESC;
162 } {2147483648 2147483647 2147483646}
165 SELECT * FROM t2 WHERE a>=0 AND a<=2147483648 ORDER BY a DESC;
167 } {2147483648 2147483647 2147483646}
170 SELECT * FROM t2 WHERE a>=0 AND a<2147483648 ORDER BY a DESC;
172 } {2147483647 2147483646}
175 SELECT * FROM t2 WHERE a>=0 AND a<=2147483647 ORDER BY a DESC;
177 } {2147483647 2147483646}
180 SELECT * FROM t2 WHERE a>=0 AND a<2147483647 ORDER BY a DESC;
184 # Ticket #565. A stack overflow is occurring when the subquery to the
185 # right of an IN operator contains many NULLs
189 CREATE TABLE t3(a INTEGER PRIMARY KEY, b);
190 INSERT INTO t3(b) VALUES('abc');
191 INSERT INTO t3(b) VALUES('xyz');
192 INSERT INTO t3(b) VALUES(NULL);
193 INSERT INTO t3(b) VALUES(NULL);
194 INSERT INTO t3(b) SELECT b||'d' FROM t3;
195 INSERT INTO t3(b) SELECT b||'e' FROM t3;
196 INSERT INTO t3(b) SELECT b||'f' FROM t3;
197 INSERT INTO t3(b) SELECT b||'g' FROM t3;
198 INSERT INTO t3(b) SELECT b||'h' FROM t3;
199 SELECT count(a), count(b) FROM t3;
204 SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3);
209 SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3 ORDER BY a+1);
213 # Ticket #601: Putting a left join inside "SELECT * FROM (<join-here>)"
214 # gives different results that if the outer "SELECT * FROM ..." is omitted.
218 CREATE TABLE x1 (b, c);
219 INSERT INTO x1 VALUES('dog',3);
220 INSERT INTO x1 VALUES('cat',1);
221 INSERT INTO x1 VALUES('dog',4);
222 CREATE TABLE x2 (c, e);
223 INSERT INTO x2 VALUES(1,'one');
224 INSERT INTO x2 VALUES(2,'two');
225 INSERT INTO x2 VALUES(3,'three');
226 INSERT INTO x2 VALUES(4,'four');
227 SELECT x2.c AS c, e, b FROM x2 LEFT JOIN
228 (SELECT b, max(c) AS c FROM x1 GROUP BY b)
231 } {1 one cat 2 two {} 3 three {} 4 four dog}
235 SELECT x2.c AS c, e, b FROM x2 LEFT JOIN
236 (SELECT b, max(c) AS c FROM x1 GROUP BY b)
240 } {1 one cat 2 two {} 3 three {} 4 four dog}
242 # Ticket #626: make sure EXPLAIN prevents BEGIN and COMMIT from working.
245 execsql {EXPLAIN BEGIN}
249 execsql {EXPLAIN COMMIT}
253 execsql {BEGIN; EXPLAIN ROLLBACK}
257 # Ticket #640: vdbe stack overflow with a LIMIT clause on a SELECT inside
266 CREATE TRIGGER r1 AFTER DELETE ON y1 FOR EACH ROW BEGIN
267 INSERT INTO y3(c) SELECT b FROM y2 ORDER BY b LIMIT 1;
269 INSERT INTO y1 VALUES(1);
270 INSERT INTO y1 VALUES(2);
271 INSERT INTO y1 SELECT a+2 FROM y1;
272 INSERT INTO y1 SELECT a+4 FROM y1;
273 INSERT INTO y1 SELECT a+8 FROM y1;
274 INSERT INTO y1 SELECT a+16 FROM y1;
275 INSERT INTO y2 SELECT a FROM y1;
277 SELECT count(*) FROM y1;
283 SELECT count(*) FROM y1;
288 SELECT count(*) FROM y3;
292 # Ticket #668: VDBE stack overflow occurs when the left-hand side
293 # of an IN expression is NULL and the result is used as an integer, not
298 SELECT count(CASE WHEN b IN ('abc','xyz') THEN 'x' END) FROM t3
303 SELECT count(*) FROM t3 WHERE 1+(b IN ('abc','xyz'))==2