1# 2003 June 21 2# 3# The author disclaims copyright to this source code. In place of 4# a legal notice, here is a blessing: 5# 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. 9# 10#*********************************************************************** 11# This file implements regression tests for SQLite library. 12# 13# This file implements tests for miscellanous features that were 14# left out of other test files. 15# 16# $Id: misc2.test,v 1.14 2004/11/16 15:50:21 danielk1977 Exp $ 17 18set testdir [file dirname $argv0] 19source $testdir/tester.tcl 20 21ifcapable {trigger} { 22# Test for ticket #360 23# 24do_test misc2-1.1 { 25 catchsql { 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; 30 END; 31 INSERT INTO foo(bar) VALUES (1); 32 } 33} {0 {}} 34do_test misc2-1.2 { 35 catchsql { 36 INSERT INTO foo(bar) VALUES (111); 37 } 38} {1 aiieee} 39} ;# endif trigger 40 41# Make sure ROWID works on a view and a subquery. Ticket #364 42# 43do_test misc2-2.1 { 44 execsql { 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); 49 SELECT rowid, * FROM (SELECT * FROM t1, t2); 50 } 51} {{} 1 2 3 7 8 9} 52do_test misc2-2.2 { 53 execsql { 54 CREATE VIEW v1 AS SELECT * FROM t1, t2; 55 SELECT rowid, * FROM v1; 56 } 57} {{} 1 2 3 7 8 9} 58 59# Check name binding precedence. Ticket #387 60# 61do_test misc2-3.1 { 62 catchsql { 63 SELECT t1.b+t2.b AS a, t1.a, t2.a FROM t1, t2 WHERE a==10 64 } 65} {1 {ambiguous column name: a}} 66 67# Make sure 32-bit integer overflow is handled properly in queries. 68# ticket #408 69# 70do_test misc2-4.1 { 71 execsql { 72 INSERT INTO t1 VALUES(4000000000,'a','b'); 73 SELECT a FROM t1 WHERE a>1; 74 } 75} {4000000000} 76do_test misc2-4.2 { 77 execsql { 78 INSERT INTO t1 VALUES(2147483648,'b2','c2'); 79 INSERT INTO t1 VALUES(2147483647,'b3','c3'); 80 SELECT a FROM t1 WHERE a>2147483647; 81 } 82} {4000000000 2147483648} 83do_test misc2-4.3 { 84 execsql { 85 SELECT a FROM t1 WHERE a<2147483648; 86 } 87} {1 2147483647} 88do_test misc2-4.4 { 89 execsql { 90 SELECT a FROM t1 WHERE a<=2147483648; 91 } 92} {1 2147483648 2147483647} 93do_test misc2-4.5 { 94 execsql { 95 SELECT a FROM t1 WHERE a<10000000000; 96 } 97} {1 4000000000 2147483648 2147483647} 98do_test misc2-4.6 { 99 execsql { 100 SELECT a FROM t1 WHERE a<1000000000000 ORDER BY 1; 101 } 102} {1 2147483647 2147483648 4000000000} 103 104# There were some issues with expanding a SrcList object using a call 105# to sqliteSrcListAppend() if the SrcList had previously been duplicated 106# using a call to sqliteSrcListDup(). Ticket #416. The following test 107# makes sure the problem has been fixed. 108# 109do_test misc2-5.1 { 110 execsql { 111 CREATE TABLE x(a,b); 112 CREATE VIEW y AS 113 SELECT x1.b AS p, x2.b AS q FROM x AS x1, x AS x2 WHERE x1.a=x2.a; 114 CREATE VIEW z AS 115 SELECT y1.p, y2.p FROM y AS y1, y AS y2 WHERE y1.q=y2.q; 116 SELECT * from z; 117 } 118} {} 119 120# Make sure we can open a database with an empty filename. What this 121# does is store the database in a temporary file that is deleted when 122# the database is closed. Ticket #432. 123# 124do_test misc2-6.1 { 125 db close 126 sqlite3 db {} 127 execsql { 128 CREATE TABLE t1(a,b); 129 INSERT INTO t1 VALUES(1,2); 130 SELECT * FROM t1; 131 } 132} {1 2} 133 134# Ticket #453. If the SQL ended with "-", the tokenizer was calling that 135# an incomplete token, which caused problem. The solution was to just call 136# it a minus sign. 137# 138do_test misc2-8.1 { 139 catchsql {-} 140} {1 {near "-": syntax error}} 141 142# Ticket #513. Make sure the VDBE stack does not grow on a 3-way join. 143# 144do_test misc2-9.1 { 145 execsql { 146 BEGIN; 147 CREATE TABLE counts(n INTEGER PRIMARY KEY); 148 INSERT INTO counts VALUES(0); 149 INSERT INTO counts VALUES(1); 150 INSERT INTO counts SELECT n+2 FROM counts; 151 INSERT INTO counts SELECT n+4 FROM counts; 152 INSERT INTO counts SELECT n+8 FROM counts; 153 COMMIT; 154 155 CREATE TEMP TABLE x AS 156 SELECT dim1.n, dim2.n, dim3.n 157 FROM counts AS dim1, counts AS dim2, counts AS dim3 158 WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10; 159 160 SELECT count(*) FROM x; 161 } 162} {1000} 163do_test misc2-9.2 { 164 execsql { 165 DROP TABLE x; 166 CREATE TEMP TABLE x AS 167 SELECT dim1.n, dim2.n, dim3.n 168 FROM counts AS dim1, counts AS dim2, counts AS dim3 169 WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6; 170 171 SELECT count(*) FROM x; 172 } 173} {1000} 174do_test misc2-9.3 { 175 execsql { 176 DROP TABLE x; 177 CREATE TEMP TABLE x AS 178 SELECT dim1.n, dim2.n, dim3.n, dim4.n 179 FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4 180 WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5; 181 182 SELECT count(*) FROM x; 183 } 184} [expr 5*5*5*5] 185 186finish_test 187