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: misc2.test,v 1.22 2005/04/29 02:10:00 drh Exp $
18 set testdir [file dirname $argv0]
19 source $testdir/tester.tcl
22 # Test for ticket #360
26 CREATE TABLE FOO(bar integer);
27 CREATE TRIGGER foo_insert BEFORE INSERT ON foo BEGIN
28 SELECT CASE WHEN (NOT new.bar BETWEEN 0 AND 20)
29 THEN raise(rollback, 'aiieee') END;
31 INSERT INTO foo(bar) VALUES (1);
36 INSERT INTO foo(bar) VALUES (111);
41 # Make sure ROWID works on a view and a subquery. Ticket #364
45 CREATE TABLE t1(a,b,c);
46 INSERT INTO t1 VALUES(1,2,3);
47 CREATE TABLE t2(a,b,c);
48 INSERT INTO t2 VALUES(7,8,9);
55 SELECT rowid, * FROM (SELECT * FROM t1, t2);
61 CREATE VIEW v1 AS SELECT * FROM t1, t2;
62 SELECT rowid, * FROM v1;
67 # Check name binding precedence. Ticket #387
71 SELECT t1.b+t2.b AS a, t1.a, t2.a FROM t1, t2 WHERE a==10
73 } {1 {ambiguous column name: a}}
75 # Make sure 32-bit integer overflow is handled properly in queries.
80 INSERT INTO t1 VALUES(4000000000,'a','b');
81 SELECT a FROM t1 WHERE a>1;
86 INSERT INTO t1 VALUES(2147483648,'b2','c2');
87 INSERT INTO t1 VALUES(2147483647,'b3','c3');
88 SELECT a FROM t1 WHERE a>2147483647;
90 } {4000000000 2147483648}
93 SELECT a FROM t1 WHERE a<2147483648;
98 SELECT a FROM t1 WHERE a<=2147483648;
100 } {1 2147483648 2147483647}
103 SELECT a FROM t1 WHERE a<10000000000;
105 } {1 4000000000 2147483648 2147483647}
108 SELECT a FROM t1 WHERE a<1000000000000 ORDER BY 1;
110 } {1 2147483647 2147483648 4000000000}
112 # There were some issues with expanding a SrcList object using a call
113 # to sqliteSrcListAppend() if the SrcList had previously been duplicated
114 # using a call to sqliteSrcListDup(). Ticket #416. The following test
115 # makes sure the problem has been fixed.
122 SELECT x1.b AS p, x2.b AS q FROM x AS x1, x AS x2 WHERE x1.a=x2.a;
124 SELECT y1.p, y2.p FROM y AS y1, y AS y2 WHERE y1.q=y2.q;
130 # Make sure we can open a database with an empty filename. What this
131 # does is store the database in a temporary file that is deleted when
132 # the database is closed. Ticket #432.
138 CREATE TABLE t1(a,b);
139 INSERT INTO t1 VALUES(1,2);
144 # Make sure we get an error message (not a segfault) on an attempt to
145 # update a table from within the callback of a select on that same
150 file delete -force test.db
154 INSERT INTO t1 VALUES(1);
157 db eval {SELECT rowid FROM t1} {} {
158 db eval "DELETE FROM t1 WHERE rowid=$rowid"
162 } {1 {database table is locked}}
165 db eval {SELECT rowid FROM t1} {} {
166 db eval "INSERT INTO t1 VALUES(3)"
170 } {1 {database table is locked}}
176 INSERT INTO t1 VALUES(1);
179 db eval {SELECT rowid FROM t1} {} {
180 db eval "DELETE FROM t1 WHERE rowid=$rowid"
184 } {1 {database table is locked}}
187 db eval {SELECT rowid FROM t1} {} {
188 db eval "INSERT INTO t1 VALUES(3)"
192 } {1 {database table is locked}}
196 file delete -force test.db
199 # Ticket #453. If the SQL ended with "-", the tokenizer was calling that
200 # an incomplete token, which caused problem. The solution was to just call
205 } {1 {near "-": syntax error}}
207 # Ticket #513. Make sure the VDBE stack does not grow on a 3-way join.
213 CREATE TABLE counts(n INTEGER PRIMARY KEY);
214 INSERT INTO counts VALUES(0);
215 INSERT INTO counts VALUES(1);
216 INSERT INTO counts SELECT n+2 FROM counts;
217 INSERT INTO counts SELECT n+4 FROM counts;
218 INSERT INTO counts SELECT n+8 FROM counts;
221 CREATE TEMP TABLE x AS
222 SELECT dim1.n, dim2.n, dim3.n
223 FROM counts AS dim1, counts AS dim2, counts AS dim3
224 WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10;
226 SELECT count(*) FROM x;
232 CREATE TEMP TABLE x AS
233 SELECT dim1.n, dim2.n, dim3.n
234 FROM counts AS dim1, counts AS dim2, counts AS dim3
235 WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6;
237 SELECT count(*) FROM x;
243 CREATE TEMP TABLE x AS
244 SELECT dim1.n, dim2.n, dim3.n, dim4.n
245 FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4
246 WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5;
248 SELECT count(*) FROM x;
253 # Ticket #1229. Sometimes when a "NEW.X" appears in a SELECT without
254 # a FROM clause deep within a trigger, the code generator is unable to
255 # trace the NEW.X back to an original table and thus figure out its
258 # The SQL code below was causing a segfault.
262 CREATE TABLE t1229(x);
263 CREATE TRIGGER r1229 BEFORE INSERT ON t1229 BEGIN
264 INSERT INTO t1229 SELECT y FROM (SELECT new.x y);
266 INSERT INTO t1229 VALUES(1);