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