1# 2# 2003 December 17 3# 4# The author disclaims copyright to this source code. In place of 5# a legal notice, here is a blessing: 6# 7# May you do good and not evil. 8# May you find forgiveness for yourself and forgive others. 9# May you share freely, never taking more than you give. 10# 11#*********************************************************************** 12# This file implements regression tests for SQLite library. 13# 14# This file implements tests for miscellanous features that were 15# left out of other test files. 16# 17# $Id: misc3.test,v 1.10 2004/03/17 23:32:08 drh Exp $ 18 19set testdir [file dirname $argv0] 20source $testdir/tester.tcl 21 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. 24# 25do_test misc3-1.1 { 26 execsql { 27 CREATE TABLE t1(a UNIQUE,b); 28 INSERT INTO t1 29 VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_'); 30 UPDATE t1 SET b=b||b; 31 UPDATE t1 SET b=b||b; 32 UPDATE t1 SET b=b||b; 33 UPDATE t1 SET b=b||b; 34 UPDATE t1 SET b=b||b; 35 INSERT INTO t1 VALUES(2,'x'); 36 UPDATE t1 SET b=substr(b,1,500); 37 BEGIN; 38 } 39 catchsql {UPDATE t1 SET a=CASE a WHEN 2 THEN 1 ELSE a END, b='y';} 40 execsql { 41 CREATE TABLE t2(x,y); 42 COMMIT; 43 PRAGMA integrity_check; 44 } 45} ok 46do_test misc3-1.2 { 47 execsql { 48 DROP TABLE t1; 49 DROP TABLE t2; 50 VACUUM; 51 CREATE TABLE t1(a UNIQUE,b); 52 INSERT INTO t1 53 VALUES(1,'a23456789_b23456789_c23456789_d23456789_e23456789_'); 54 INSERT INTO t1 SELECT a+1, b||b FROM t1; 55 INSERT INTO t1 SELECT a+2, b||b FROM t1; 56 INSERT INTO t1 SELECT a+4, b FROM t1; 57 INSERT INTO t1 SELECT a+8, b FROM t1; 58 INSERT INTO t1 SELECT a+16, b FROM t1; 59 INSERT INTO t1 SELECT a+32, b FROM t1; 60 INSERT INTO t1 SELECT a+64, b FROM t1; 61 62 BEGIN; 63 } 64 catchsql {UPDATE t1 SET a=CASE a WHEN 128 THEN 127 ELSE a END, b='';} 65 execsql { 66 INSERT INTO t1 VALUES(200,'hello out there'); 67 COMMIT; 68 PRAGMA integrity_check; 69 } 70} ok 71 72# Tests of the sqliteAtoF() function in util.c 73# 74do_test misc3-2.1 { 75 execsql {SELECT 2e-25*0.5e25} 76} 1 77do_test misc3-2.2 { 78 execsql {SELECT 2.0e-25*000000.500000000000000000000000000000e+00025} 79} 1 80do_test misc3-2.3 { 81 execsql {SELECT 000000000002e-0000000025*0.5e25} 82} 1 83do_test misc3-2.4 { 84 execsql {SELECT 2e-25*0.5e250} 85} 1e+225 86do_test misc3-2.5 { 87 execsql {SELECT 2.0e-250*0.5e25} 88} 1e-225 89do_test misc3-2.6 { 90 execsql {SELECT '-2.0e-127' * '-0.5e27'} 91} 1e-100 92do_test misc3-2.7 { 93 execsql {SELECT '+2.0e-127' * '-0.5e27'} 94} -1e-100 95do_test misc3-2.8 { 96 execsql {SELECT 2.0e-27 * '+0.5e+127'} 97} 1e+100 98do_test misc3-2.9 { 99 execsql {SELECT 2.0e-27 * '+0.000005e+132'} 100} 1e+100 101 102# Ticket #522. Make sure integer overflow is handled properly in 103# indices. 104# 105do_test misc3-3.1 { 106 execsql {PRAGMA integrity_check} 107} ok 108do_test misc3-3.2 { 109 execsql { 110 CREATE TABLE t2(a INT UNIQUE); 111 PRAGMA integrity_check; 112 } 113} ok 114do_test misc3-3.3 { 115 execsql { 116 INSERT INTO t2 VALUES(2147483648); 117 PRAGMA integrity_check; 118 } 119} ok 120do_test misc3-3.4 { 121 execsql { 122 INSERT INTO t2 VALUES(-2147483649); 123 PRAGMA integrity_check; 124 } 125} ok 126do_test misc3-3.5 { 127 execsql { 128 INSERT INTO t2 VALUES(+2147483649); 129 PRAGMA integrity_check; 130 } 131} ok 132do_test misc3-3.6 { 133 execsql { 134 INSERT INTO t2 VALUES(+2147483647); 135 INSERT INTO t2 VALUES(-2147483648); 136 INSERT INTO t2 VALUES(-2147483647); 137 INSERT INTO t2 VALUES(2147483646); 138 SELECT * FROM t2 ORDER BY a; 139 } 140} {-2147483649 -2147483648 -2147483647 2147483646 2147483647 2147483648 2147483649} 141do_test misc3-3.7 { 142 execsql { 143 SELECT * FROM t2 WHERE a>=-2147483648 ORDER BY a; 144 } 145} {-2147483648 -2147483647 2147483646 2147483647 2147483648 2147483649} 146do_test misc3-3.8 { 147 execsql { 148 SELECT * FROM t2 WHERE a>-2147483648 ORDER BY a; 149 } 150} {-2147483647 2147483646 2147483647 2147483648 2147483649} 151do_test misc3-3.9 { 152 execsql { 153 SELECT * FROM t2 WHERE a>-2147483649 ORDER BY a; 154 } 155} {-2147483648 -2147483647 2147483646 2147483647 2147483648 2147483649} 156do_test misc3-3.10 { 157 execsql { 158 SELECT * FROM t2 WHERE a>=0 AND a<2147483649 ORDER BY a DESC; 159 } 160} {2147483648 2147483647 2147483646} 161do_test misc3-3.11 { 162 execsql { 163 SELECT * FROM t2 WHERE a>=0 AND a<=2147483648 ORDER BY a DESC; 164 } 165} {2147483648 2147483647 2147483646} 166do_test misc3-3.12 { 167 execsql { 168 SELECT * FROM t2 WHERE a>=0 AND a<2147483648 ORDER BY a DESC; 169 } 170} {2147483647 2147483646} 171do_test misc3-3.13 { 172 execsql { 173 SELECT * FROM t2 WHERE a>=0 AND a<=2147483647 ORDER BY a DESC; 174 } 175} {2147483647 2147483646} 176do_test misc3-3.14 { 177 execsql { 178 SELECT * FROM t2 WHERE a>=0 AND a<2147483647 ORDER BY a DESC; 179 } 180} {2147483646} 181 182# Ticket #565. A stack overflow is occurring when the subquery to the 183# right of an IN operator contains many NULLs 184# 185do_test misc3-4.1 { 186 execsql { 187 CREATE TABLE t3(a INTEGER PRIMARY KEY, b); 188 INSERT INTO t3(b) VALUES('abc'); 189 INSERT INTO t3(b) VALUES('xyz'); 190 INSERT INTO t3(b) VALUES(NULL); 191 INSERT INTO t3(b) VALUES(NULL); 192 INSERT INTO t3(b) SELECT b||'d' FROM t3; 193 INSERT INTO t3(b) SELECT b||'e' FROM t3; 194 INSERT INTO t3(b) SELECT b||'f' FROM t3; 195 INSERT INTO t3(b) SELECT b||'g' FROM t3; 196 INSERT INTO t3(b) SELECT b||'h' FROM t3; 197 SELECT count(a), count(b) FROM t3; 198 } 199} {128 64} 200do_test misc3-4.2 { 201 execsql { 202 SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3); 203 } 204} {64} 205do_test misc3-4.3 { 206 execsql { 207 SELECT count(a) FROM t3 WHERE b IN (SELECT b FROM t3 ORDER BY a+1); 208 } 209} {64} 210 211# Ticket #601: Putting a left join inside "SELECT * FROM (<join-here>)" 212# gives different results that if the outer "SELECT * FROM ..." is omitted. 213# 214do_test misc3-5.1 { 215 execsql { 216 CREATE TABLE x1 (b, c); 217 INSERT INTO x1 VALUES('dog',3); 218 INSERT INTO x1 VALUES('cat',1); 219 INSERT INTO x1 VALUES('dog',4); 220 CREATE TABLE x2 (c, e); 221 INSERT INTO x2 VALUES(1,'one'); 222 INSERT INTO x2 VALUES(2,'two'); 223 INSERT INTO x2 VALUES(3,'three'); 224 INSERT INTO x2 VALUES(4,'four'); 225 SELECT x2.c AS c, e, b FROM x2 LEFT JOIN 226 (SELECT b, max(c) AS c FROM x1 GROUP BY b) 227 USING(c); 228 } 229} {1 one cat 2 two {} 3 three {} 4 four dog} 230do_test misc4-5.2 { 231 execsql { 232 SELECT * FROM ( 233 SELECT x2.c AS c, e, b FROM x2 LEFT JOIN 234 (SELECT b, max(c) AS c FROM x1 GROUP BY b) 235 USING(c) 236 ); 237 } 238} {1 one cat 2 two {} 3 three {} 4 four dog} 239 240# Ticket #626: make sure EXPLAIN prevents BEGIN and COMMIT from working. 241# 242do_test misc3-6.1 { 243 execsql {EXPLAIN BEGIN} 244 catchsql {BEGIN} 245} {0 {}} 246do_test misc3-6.2 { 247 execsql {EXPLAIN COMMIT} 248 catchsql {COMMIT} 249} {0 {}} 250do_test misc3-6.3 { 251 execsql {BEGIN; EXPLAIN ROLLBACK} 252 catchsql {ROLLBACK} 253} {0 {}} 254 255# Ticket #640: vdbe stack overflow with a LIMIT clause on a SELECT inside 256# of a trigger. 257# 258do_test misc3-7.1 { 259 execsql { 260 BEGIN; 261 CREATE TABLE y1(a); 262 CREATE TABLE y2(b); 263 CREATE TABLE y3(c); 264 CREATE TRIGGER r1 AFTER DELETE ON y1 FOR EACH ROW BEGIN 265 INSERT INTO y3(c) SELECT b FROM y2 ORDER BY b LIMIT 1; 266 END; 267 INSERT INTO y1 VALUES(1); 268 INSERT INTO y1 VALUES(2); 269 INSERT INTO y1 SELECT a+2 FROM y1; 270 INSERT INTO y1 SELECT a+4 FROM y1; 271 INSERT INTO y1 SELECT a+8 FROM y1; 272 INSERT INTO y1 SELECT a+16 FROM y1; 273 INSERT INTO y2 SELECT a FROM y1; 274 COMMIT; 275 SELECT count(*) FROM y1; 276 } 277} 32 278do_test misc3-7.2 { 279 execsql { 280 DELETE FROM y1; 281 SELECT count(*) FROM y1; 282 } 283} 0 284do_test misc3-7.3 { 285 execsql { 286 SELECT count(*) FROM y3; 287 } 288} 32 289 290# Ticket #668: VDBE stack overflow occurs when the left-hand side 291# of an IN expression is NULL and the result is used as an integer, not 292# as a jump. 293# 294do_test misc-8.1 { 295 execsql { 296 SELECT count(CASE WHEN b IN ('abc','xyz') THEN 'x' END) FROM t3 297 } 298} {2} 299do_test misc-8.2 { 300 execsql { 301 SELECT count(*) FROM t3 WHERE 1+(b IN ('abc','xyz'))==2 302 } 303} {2} 304 305finish_test 306