4 # The author disclaims copyright to this source code. In place of
5 # a legal notice, here is a blessing:
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.
11 #***********************************************************************
12 # This file implements regression tests for SQLite library.
14 # This file implements tests for miscellanous features that were
15 # left out of other test files.
17 # $Id: misc2.test,v 1.11 2003/12/17 23:57:36 drh Exp $
19 set testdir [file dirname $argv0]
20 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);
40 # Make sure ROWID works on a view and a subquery. Ticket #364
44 CREATE TABLE t1(a,b,c);
45 INSERT INTO t1 VALUES(1,2,3);
46 CREATE TABLE t2(a,b,c);
47 INSERT INTO t2 VALUES(7,8,9);
48 SELECT rowid, * FROM (SELECT * FROM t1, t2);
53 CREATE VIEW v1 AS SELECT * FROM t1, t2;
54 SELECT rowid, * FROM v1;
58 # Check name binding precedence. Ticket #387
62 SELECT t1.b+t2.b AS a, t1.a, t2.a FROM t1, t2 WHERE a==10
64 } {1 {ambiguous column name: a}}
66 # Make sure 32-bit integer overflow is handled properly in queries.
71 INSERT INTO t1 VALUES(4000000000,'a','b');
72 SELECT a FROM t1 WHERE a>1;
77 INSERT INTO t1 VALUES(2147483648,'b2','c2');
78 INSERT INTO t1 VALUES(2147483647,'b3','c3');
79 SELECT a FROM t1 WHERE a>2147483647;
81 } {4000000000 2147483648}
84 SELECT a FROM t1 WHERE a<2147483648;
89 SELECT a FROM t1 WHERE a<=2147483648;
91 } {1 2147483648 2147483647}
94 SELECT a FROM t1 WHERE a<10000000000;
96 } {1 4000000000 2147483648 2147483647}
99 SELECT a FROM t1 WHERE a<1000000000000 ORDER BY 1;
101 } {1 2147483647 2147483648 4000000000}
103 # There were some issues with expanding a SrcList object using a call
104 # to sqliteSrcListAppend() if the SrcList had previously been duplicated
105 # using a call to sqliteSrcListDup(). Ticket #416. The following test
106 # makes sure the problem has been fixed.
112 SELECT x1.b AS p, x2.b AS q FROM x AS x1, x AS x2 WHERE x1.a=x2.a;
114 SELECT y1.p, y2.p FROM y AS y1, y AS y2 WHERE y1.q=y2.q;
119 # Make sure we can open a database with an empty filename. What this
120 # does is store the database in a temporary file that is deleted when
121 # the database is closed. Ticket #432.
127 CREATE TABLE t1(a,b);
128 INSERT INTO t1 VALUES(1,2);
133 # Make sure we get an error message (not a segfault) on an attempt to
134 # update a table from within the callback of a select on that same
139 file delete -force test.db
143 INSERT INTO t1 VALUES(1);
146 db eval {SELECT rowid FROM t1} {} {
147 db eval "DELETE FROM t1 WHERE rowid=$rowid"
151 } {1 {database table is locked}}
154 db eval {SELECT rowid FROM t1} {} {
155 db eval "INSERT INTO t1 VALUES(3)"
159 } {1 {database table is locked}}
162 file delete -force test.db
166 INSERT INTO t1 VALUES(1);
169 db eval {SELECT rowid FROM t1} {} {
170 db eval "DELETE FROM t1 WHERE rowid=$rowid"
174 } {1 {database table is locked}}
177 db eval {SELECT rowid FROM t1} {} {
178 db eval "INSERT INTO t1 VALUES(3)"
182 } {1 {database table is locked}}
184 # Ticket #453. If the SQL ended with "-", the tokenizer was calling that
185 # an incomplete token, which caused problem. The solution was to just call
190 } {1 {near "-": syntax error}}
192 # Ticket #513. Make sure the VDBE stack does not grow on a 3-way join.
197 CREATE TABLE counts(n INTEGER PRIMARY KEY);
198 INSERT INTO counts VALUES(0);
199 INSERT INTO counts VALUES(1);
200 INSERT INTO counts SELECT n+2 FROM counts;
201 INSERT INTO counts SELECT n+4 FROM counts;
202 INSERT INTO counts SELECT n+8 FROM counts;
205 CREATE TEMP TABLE x AS
206 SELECT dim1.n, dim2.n, dim3.n
207 FROM counts AS dim1, counts AS dim2, counts AS dim3
208 WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10;
210 SELECT count(*) FROM x;
216 CREATE TEMP TABLE x AS
217 SELECT dim1.n, dim2.n, dim3.n
218 FROM counts AS dim1, counts AS dim2, counts AS dim3
219 WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6;
221 SELECT count(*) FROM x;
227 CREATE TEMP TABLE x AS
228 SELECT dim1.n, dim2.n, dim3.n, dim4.n
229 FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4
230 WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5;
232 SELECT count(*) FROM x;