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 miscellanous features that were
14 # left out of other test files.
16 # $Id: misc3.test,v 1.20 2009/05/06 00:49:01 drh Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
21 ifcapable {integrityck} {
22 # Ticket #529. Make sure an ABORT does not damage the in-memory cache
23 # that will be used by subsequent statements in the same transaction.
27 CREATE TABLE t1(a UNIQUE,b);
29 VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_');
35 INSERT INTO t1 VALUES(2,'x');
36 UPDATE t1 SET b=substr(b,1,500);
39 catchsql {UPDATE t1 SET a=CASE a WHEN 2 THEN 1 ELSE a END, b='y';}
43 PRAGMA integrity_check;
47 ifcapable {integrityck} {
53 ifcapable {vacuum} {execsql VACUUM}
55 CREATE TABLE t1(a UNIQUE,b);
57 VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_');
58 INSERT INTO t1 SELECT a+1, b||b FROM t1;
59 INSERT INTO t1 SELECT a+2, b||b FROM t1;
60 INSERT INTO t1 SELECT a+4, b FROM t1;
61 INSERT INTO t1 SELECT a+8, b FROM t1;
62 INSERT INTO t1 SELECT a+16, b FROM t1;
63 INSERT INTO t1 SELECT a+32, b FROM t1;
64 INSERT INTO t1 SELECT a+64, b FROM t1;
67 catchsql {UPDATE t1 SET a=CASE a WHEN 128 THEN 127 ELSE a END, b='';}
69 INSERT INTO t1 VALUES(200,'hello out there');
71 PRAGMA integrity_check;
76 # Tests of the sqliteAtoF() function in util.c
79 execsql {SELECT 2e-25*0.5e25}
82 execsql {SELECT 2.0e-25*000000.500000000000000000000000000000e+00025}
85 execsql {SELECT 000000000002e-0000000025*0.5e25}
88 execsql {SELECT 2e-25*0.5e250}
91 execsql {SELECT 2.0e-250*0.5e25}
94 execsql {SELECT '-2.0e-127' * '-0.5e27'}
97 execsql {SELECT '+2.0e-127' * '-0.5e27'}
100 execsql {SELECT 2.0e-27 * '+0.5e+127'}
103 execsql {SELECT 2.0e-27 * '+0.000005e+132'}
106 # Ticket #522. Make sure integer overflow is handled properly in
109 integrity_check misc3-3.1
112 CREATE TABLE t2(a INT UNIQUE);
115 integrity_check misc3-3.2.1
118 INSERT INTO t2 VALUES(2147483648);
121 integrity_check misc3-3.3.1
124 INSERT INTO t2 VALUES(-2147483649);
127 integrity_check misc3-3.4.1
130 INSERT INTO t2 VALUES(+2147483649);
133 integrity_check misc3-3.5.1
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;
205 SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3);
210 SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3 ORDER BY a+1);
215 # Ticket #601: Putting a left join inside "SELECT * FROM (<join-here>)"
216 # gives different results that if the outer "SELECT * FROM ..." is omitted.
221 CREATE TABLE x1 (b, c);
222 INSERT INTO x1 VALUES('dog',3);
223 INSERT INTO x1 VALUES('cat',1);
224 INSERT INTO x1 VALUES('dog',4);
225 CREATE TABLE x2 (c, e);
226 INSERT INTO x2 VALUES(1,'one');
227 INSERT INTO x2 VALUES(2,'two');
228 INSERT INTO x2 VALUES(3,'three');
229 INSERT INTO x2 VALUES(4,'four');
230 SELECT x2.c AS c, e, b FROM x2 LEFT JOIN
231 (SELECT b, max(c)+0 AS c FROM x1 GROUP BY b)
234 } {1 one cat 2 two {} 3 three {} 4 four dog}
238 SELECT x2.c AS c, e, b FROM x2 LEFT JOIN
239 (SELECT b, max(c)+0 AS c FROM x1 GROUP BY b)
243 } {1 one cat 2 two {} 3 three {} 4 four dog}
246 ifcapable {explain} {
247 # Ticket #626: make sure EXPLAIN prevents BEGIN and COMMIT from working.
250 execsql {EXPLAIN BEGIN}
254 execsql {EXPLAIN COMMIT}
258 execsql {BEGIN; EXPLAIN ROLLBACK}
262 # Do some additional EXPLAIN operations to exercise the displayP4 logic.
266 a INTEGER DEFAULT 54321,
267 b TEXT DEFAULT "hello",
268 c REAL DEFAULT 3.1415926
270 CREATE UNIQUE INDEX ex1i1 ON ex1(a);
273 ifcapable mergesort {
274 regexp { SorterCompare \d+ \d+ \d+ } $x
276 regexp { IsUnique \d+ \d+ \d+ \d+ } $x
279 if {[regexp {16} [db one {PRAGMA encoding}]]} {
280 do_test misc3-6.11-utf16 {
282 EXPLAIN SELECT a+123456789012, b*4.5678, c FROM ex1 ORDER BY +a, b DESC
284 set y [regexp { 123456789012 } $x]
285 lappend y [regexp { 4.5678 } $x]
286 lappend y [regexp {,-B} $x]
289 do_test misc3-6.11-utf8 {
291 EXPLAIN SELECT a+123456789012, b*4.5678, c FROM ex1 ORDER BY +a, b DESC
293 set y [regexp { 123456789012 } $x]
294 lappend y [regexp { 4.5678 } $x]
295 lappend y [regexp { hello } $x]
296 lappend y [regexp {,-B} $x]
301 ifcapable {trigger} {
302 # Ticket #640: vdbe stack overflow with a LIMIT clause on a SELECT inside
311 CREATE TRIGGER r1 AFTER DELETE ON y1 FOR EACH ROW BEGIN
312 INSERT INTO y3(c) SELECT b FROM y2 ORDER BY b LIMIT 1;
314 INSERT INTO y1 VALUES(1);
315 INSERT INTO y1 VALUES(2);
316 INSERT INTO y1 SELECT a+2 FROM y1;
317 INSERT INTO y1 SELECT a+4 FROM y1;
318 INSERT INTO y1 SELECT a+8 FROM y1;
319 INSERT INTO y1 SELECT a+16 FROM y1;
320 INSERT INTO y2 SELECT a FROM y1;
322 SELECT count(*) FROM y1;
328 SELECT count(*) FROM y1;
333 SELECT count(*) FROM y3;
338 # Ticket #668: VDBE stack overflow occurs when the left-hand side
339 # of an IN expression is NULL and the result is used as an integer, not
345 SELECT count(CASE WHEN b IN ('abc','xyz') THEN 'x' END) FROM t3
350 SELECT count(*) FROM t3 WHERE 1+(b IN ('abc','xyz'))==2