2 #pragma ident "%Z%%M% %I% %E% SMI"
6 # The author disclaims copyright to this source code. In place of
7 # a legal notice, here is a blessing:
9 # May you do good and not evil.
10 # May you find forgiveness for yourself and forgive others.
11 # May you share freely, never taking more than you give.
13 #***********************************************************************
14 # This file implements regression tests for SQLite library.
16 # This file implements tests for miscellanous features that were
17 # left out of other test files.
19 # $Id: misc2.test,v 1.11 2003/12/17 23:57:36 drh Exp $
21 set testdir [file dirname $argv0]
22 source $testdir/tester.tcl
24 # Test for ticket #360
28 CREATE TABLE FOO(bar integer);
29 CREATE TRIGGER foo_insert BEFORE INSERT ON foo BEGIN
30 SELECT CASE WHEN (NOT new.bar BETWEEN 0 AND 20)
31 THEN raise(rollback, 'aiieee') END;
33 INSERT INTO foo(bar) VALUES (1);
38 INSERT INTO foo(bar) VALUES (111);
42 # Make sure ROWID works on a view and a subquery. Ticket #364
46 CREATE TABLE t1(a,b,c);
47 INSERT INTO t1 VALUES(1,2,3);
48 CREATE TABLE t2(a,b,c);
49 INSERT INTO t2 VALUES(7,8,9);
50 SELECT rowid, * FROM (SELECT * FROM t1, t2);
55 CREATE VIEW v1 AS SELECT * FROM t1, t2;
56 SELECT rowid, * FROM v1;
60 # Check name binding precedence. Ticket #387
64 SELECT t1.b+t2.b AS a, t1.a, t2.a FROM t1, t2 WHERE a==10
66 } {1 {ambiguous column name: a}}
68 # Make sure 32-bit integer overflow is handled properly in queries.
73 INSERT INTO t1 VALUES(4000000000,'a','b');
74 SELECT a FROM t1 WHERE a>1;
79 INSERT INTO t1 VALUES(2147483648,'b2','c2');
80 INSERT INTO t1 VALUES(2147483647,'b3','c3');
81 SELECT a FROM t1 WHERE a>2147483647;
83 } {4000000000 2147483648}
86 SELECT a FROM t1 WHERE a<2147483648;
91 SELECT a FROM t1 WHERE a<=2147483648;
93 } {1 2147483648 2147483647}
96 SELECT a FROM t1 WHERE a<10000000000;
98 } {1 4000000000 2147483648 2147483647}
101 SELECT a FROM t1 WHERE a<1000000000000 ORDER BY 1;
103 } {1 2147483647 2147483648 4000000000}
105 # There were some issues with expanding a SrcList object using a call
106 # to sqliteSrcListAppend() if the SrcList had previously been duplicated
107 # using a call to sqliteSrcListDup(). Ticket #416. The following test
108 # makes sure the problem has been fixed.
114 SELECT x1.b AS p, x2.b AS q FROM x AS x1, x AS x2 WHERE x1.a=x2.a;
116 SELECT y1.p, y2.p FROM y AS y1, y AS y2 WHERE y1.q=y2.q;
121 # Make sure we can open a database with an empty filename. What this
122 # does is store the database in a temporary file that is deleted when
123 # the database is closed. Ticket #432.
129 CREATE TABLE t1(a,b);
130 INSERT INTO t1 VALUES(1,2);
135 # Make sure we get an error message (not a segfault) on an attempt to
136 # update a table from within the callback of a select on that same
141 file delete -force test.db
145 INSERT INTO t1 VALUES(1);
148 db eval {SELECT rowid FROM t1} {} {
149 db eval "DELETE FROM t1 WHERE rowid=$rowid"
153 } {1 {database table is locked}}
156 db eval {SELECT rowid FROM t1} {} {
157 db eval "INSERT INTO t1 VALUES(3)"
161 } {1 {database table is locked}}
164 file delete -force test.db
168 INSERT INTO t1 VALUES(1);
171 db eval {SELECT rowid FROM t1} {} {
172 db eval "DELETE FROM t1 WHERE rowid=$rowid"
176 } {1 {database table is locked}}
179 db eval {SELECT rowid FROM t1} {} {
180 db eval "INSERT INTO t1 VALUES(3)"
184 } {1 {database table is locked}}
186 # Ticket #453. If the SQL ended with "-", the tokenizer was calling that
187 # an incomplete token, which caused problem. The solution was to just call
192 } {1 {near "-": syntax error}}
194 # Ticket #513. Make sure the VDBE stack does not grow on a 3-way join.
199 CREATE TABLE counts(n INTEGER PRIMARY KEY);
200 INSERT INTO counts VALUES(0);
201 INSERT INTO counts VALUES(1);
202 INSERT INTO counts SELECT n+2 FROM counts;
203 INSERT INTO counts SELECT n+4 FROM counts;
204 INSERT INTO counts SELECT n+8 FROM counts;
207 CREATE TEMP TABLE x AS
208 SELECT dim1.n, dim2.n, dim3.n
209 FROM counts AS dim1, counts AS dim2, counts AS dim3
210 WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10;
212 SELECT count(*) FROM x;
218 CREATE TEMP TABLE x AS
219 SELECT dim1.n, dim2.n, dim3.n
220 FROM counts AS dim1, counts AS dim2, counts AS dim3
221 WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6;
223 SELECT count(*) FROM x;
229 CREATE TEMP TABLE x AS
230 SELECT dim1.n, dim2.n, dim3.n, dim4.n
231 FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4
232 WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5;
234 SELECT count(*) FROM x;