First public contribution.
3 # Portions Copyright (c) 2007-2008 Nokia Corporation and/or its subsidiaries. All rights reserved.
5 # The author disclaims copyright to this source code. In place of
6 # a legal notice, here is a blessing:
8 # May you do good and not evil.
9 # May you find forgiveness for yourself and forgive others.
10 # May you share freely, never taking more than you give.
12 #***********************************************************************
13 # This file implements regression tests for SQLite library.
15 # This file implements tests for miscellanous features that were
16 # left out of other test files.
18 # $Id: misc3.test,v 1.19 2008/06/25 02:47:57 drh Exp $
20 set testdir [file dirname $argv0]
21 source $testdir/tester.tcl
23 ifcapable {integrityck} {
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;
49 ifcapable {integrityck} {
55 ifcapable {vacuum} {execsql VACUUM}
57 CREATE TABLE t1(a UNIQUE,b);
59 VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_');
60 INSERT INTO t1 SELECT a+1, b||b FROM t1;
61 INSERT INTO t1 SELECT a+2, b||b FROM t1;
62 INSERT INTO t1 SELECT a+4, b FROM t1;
63 INSERT INTO t1 SELECT a+8, b FROM t1;
64 INSERT INTO t1 SELECT a+16, b FROM t1;
65 INSERT INTO t1 SELECT a+32, b FROM t1;
66 INSERT INTO t1 SELECT a+64, b FROM t1;
69 catchsql {UPDATE t1 SET a=CASE a WHEN 128 THEN 127 ELSE a END, b='';}
71 INSERT INTO t1 VALUES(200,'hello out there');
73 PRAGMA integrity_check;
78 # Tests of the sqliteAtoF() function in util.c
81 execsql {SELECT 2e-25*0.5e25}
84 execsql {SELECT 2.0e-25*000000.500000000000000000000000000000e+00025}
87 execsql {SELECT 000000000002e-0000000025*0.5e25}
90 execsql {SELECT 2e-25*0.5e250}
93 execsql {SELECT 2.0e-250*0.5e25}
96 # Symbian OS: the next test fails due to problems in sprintf/printf formatting.
97 if {$::tcl_platform(platform)!="symbian"} {
99 execsql {SELECT '-2.0e-127' * '-0.5e27'}
102 execsql {SELECT '+2.0e-127' * '-0.5e27'}
106 execsql {SELECT 2.0e-27 * '+0.5e+127'}
109 execsql {SELECT 2.0e-27 * '+0.000005e+132'}
112 # Ticket #522. Make sure integer overflow is handled properly in
115 integrity_check misc3-3.1
118 CREATE TABLE t2(a INT UNIQUE);
121 integrity_check misc3-3.2.1
124 INSERT INTO t2 VALUES(2147483648);
127 integrity_check misc3-3.3.1
130 INSERT INTO t2 VALUES(-2147483649);
133 integrity_check misc3-3.4.1
136 INSERT INTO t2 VALUES(+2147483649);
139 integrity_check misc3-3.5.1
142 INSERT INTO t2 VALUES(+2147483647);
143 INSERT INTO t2 VALUES(-2147483648);
144 INSERT INTO t2 VALUES(-2147483647);
145 INSERT INTO t2 VALUES(2147483646);
146 SELECT * FROM t2 ORDER BY a;
148 } {-2147483649 -2147483648 -2147483647 2147483646 2147483647 2147483648 2147483649}
151 SELECT * FROM t2 WHERE a>=-2147483648 ORDER BY a;
153 } {-2147483648 -2147483647 2147483646 2147483647 2147483648 2147483649}
156 SELECT * FROM t2 WHERE a>-2147483648 ORDER BY a;
158 } {-2147483647 2147483646 2147483647 2147483648 2147483649}
161 SELECT * FROM t2 WHERE a>-2147483649 ORDER BY a;
163 } {-2147483648 -2147483647 2147483646 2147483647 2147483648 2147483649}
166 SELECT * FROM t2 WHERE a>=0 AND a<2147483649 ORDER BY a DESC;
168 } {2147483648 2147483647 2147483646}
171 SELECT * FROM t2 WHERE a>=0 AND a<=2147483648 ORDER BY a DESC;
173 } {2147483648 2147483647 2147483646}
176 SELECT * FROM t2 WHERE a>=0 AND a<2147483648 ORDER BY a DESC;
178 } {2147483647 2147483646}
181 SELECT * FROM t2 WHERE a>=0 AND a<=2147483647 ORDER BY a DESC;
183 } {2147483647 2147483646}
186 SELECT * FROM t2 WHERE a>=0 AND a<2147483647 ORDER BY a DESC;
190 # Ticket #565. A stack overflow is occurring when the subquery to the
191 # right of an IN operator contains many NULLs
195 CREATE TABLE t3(a INTEGER PRIMARY KEY, b);
196 INSERT INTO t3(b) VALUES('abc');
197 INSERT INTO t3(b) VALUES('xyz');
198 INSERT INTO t3(b) VALUES(NULL);
199 INSERT INTO t3(b) VALUES(NULL);
200 INSERT INTO t3(b) SELECT b||'d' FROM t3;
201 INSERT INTO t3(b) SELECT b||'e' FROM t3;
202 INSERT INTO t3(b) SELECT b||'f' FROM t3;
203 INSERT INTO t3(b) SELECT b||'g' FROM t3;
204 INSERT INTO t3(b) SELECT b||'h' FROM t3;
205 SELECT count(a), count(b) FROM t3;
211 SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3);
216 SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3 ORDER BY a+1);
221 # Ticket #601: Putting a left join inside "SELECT * FROM (<join-here>)"
222 # gives different results that if the outer "SELECT * FROM ..." is omitted.
227 CREATE TABLE x1 (b, c);
228 INSERT INTO x1 VALUES('dog',3);
229 INSERT INTO x1 VALUES('cat',1);
230 INSERT INTO x1 VALUES('dog',4);
231 CREATE TABLE x2 (c, e);
232 INSERT INTO x2 VALUES(1,'one');
233 INSERT INTO x2 VALUES(2,'two');
234 INSERT INTO x2 VALUES(3,'three');
235 INSERT INTO x2 VALUES(4,'four');
236 SELECT x2.c AS c, e, b FROM x2 LEFT JOIN
237 (SELECT b, max(c)+0 AS c FROM x1 GROUP BY b)
240 } {1 one cat 2 two {} 3 three {} 4 four dog}
244 SELECT x2.c AS c, e, b FROM x2 LEFT JOIN
245 (SELECT b, max(c)+0 AS c FROM x1 GROUP BY b)
249 } {1 one cat 2 two {} 3 three {} 4 four dog}
252 ifcapable {explain} {
253 # Ticket #626: make sure EXPLAIN prevents BEGIN and COMMIT from working.
256 execsql {EXPLAIN BEGIN}
260 execsql {EXPLAIN COMMIT}
264 execsql {BEGIN; EXPLAIN ROLLBACK}
268 # Do some additional EXPLAIN operations to exercise the displayP4 logic.
272 a INTEGER DEFAULT 54321,
273 b TEXT DEFAULT "hello",
274 c REAL DEFAULT 3.1415926
276 CREATE UNIQUE INDEX ex1i1 ON ex1(a);
279 regexp { IsUnique \d+ \d+ \d+ \d+ } $x
283 EXPLAIN SELECT a+123456789012, b*4.5678, c FROM ex1 ORDER BY +a, b DESC
285 set y [regexp { 123456789012 } $x]
286 lappend y [regexp { 4.5678 } $x]
287 lappend y [regexp { hello } $x]
288 lappend y [regexp {,-BINARY} $x]
293 ifcapable {trigger} {
294 # Ticket #640: vdbe stack overflow with a LIMIT clause on a SELECT inside
303 CREATE TRIGGER r1 AFTER DELETE ON y1 FOR EACH ROW BEGIN
304 INSERT INTO y3(c) SELECT b FROM y2 ORDER BY b LIMIT 1;
306 INSERT INTO y1 VALUES(1);
307 INSERT INTO y1 VALUES(2);
308 INSERT INTO y1 SELECT a+2 FROM y1;
309 INSERT INTO y1 SELECT a+4 FROM y1;
310 INSERT INTO y1 SELECT a+8 FROM y1;
311 INSERT INTO y1 SELECT a+16 FROM y1;
312 INSERT INTO y2 SELECT a FROM y1;
314 SELECT count(*) FROM y1;
320 SELECT count(*) FROM y1;
325 SELECT count(*) FROM y3;
330 # Ticket #668: VDBE stack overflow occurs when the left-hand side
331 # of an IN expression is NULL and the result is used as an integer, not
337 SELECT count(CASE WHEN b IN ('abc','xyz') THEN 'x' END) FROM t3
342 SELECT count(*) FROM t3 WHERE 1+(b IN ('abc','xyz'))==2