drh | 8ce10ba | 2003-06-22 01:41:49 +0000 | [diff] [blame] | 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 | # |
drh | acf4ac9 | 2003-12-17 23:57:34 +0000 | [diff] [blame] | 16 | # $Id: misc2.test,v 1.11 2003/12/17 23:57:36 drh Exp $ |
drh | 8ce10ba | 2003-06-22 01:41:49 +0000 | [diff] [blame] | 17 | |
| 18 | set testdir [file dirname $argv0] |
| 19 | source $testdir/tester.tcl |
| 20 | |
| 21 | # Test for ticket #360 |
| 22 | # |
| 23 | do_test misc2-1.1 { |
| 24 | catchsql { |
| 25 | CREATE TABLE FOO(bar integer); |
| 26 | CREATE TRIGGER foo_insert BEFORE INSERT ON foo BEGIN |
| 27 | SELECT CASE WHEN (NOT new.bar BETWEEN 0 AND 20) |
| 28 | THEN raise(rollback, 'aiieee') END; |
| 29 | END; |
| 30 | INSERT INTO foo(bar) VALUES (1); |
| 31 | } |
drh | dc339ee | 2003-06-29 20:25:08 +0000 | [diff] [blame] | 32 | } {0 {}} |
| 33 | do_test misc2-1.2 { |
| 34 | catchsql { |
| 35 | INSERT INTO foo(bar) VALUES (111); |
| 36 | } |
drh | 8ce10ba | 2003-06-22 01:41:49 +0000 | [diff] [blame] | 37 | } {1 aiieee} |
drh | d60ccc6 | 2003-06-24 10:39:46 +0000 | [diff] [blame] | 38 | |
| 39 | # Make sure ROWID works on a view and a subquery. Ticket #364 |
| 40 | # |
| 41 | do_test misc2-2.1 { |
| 42 | execsql { |
| 43 | CREATE TABLE t1(a,b,c); |
| 44 | INSERT INTO t1 VALUES(1,2,3); |
drh | da808d5 | 2003-07-09 16:34:56 +0000 | [diff] [blame] | 45 | CREATE TABLE t2(a,b,c); |
drh | d60ccc6 | 2003-06-24 10:39:46 +0000 | [diff] [blame] | 46 | INSERT INTO t2 VALUES(7,8,9); |
| 47 | SELECT rowid, * FROM (SELECT * FROM t1, t2); |
| 48 | } |
| 49 | } {{} 1 2 3 7 8 9} |
| 50 | do_test misc2-2.2 { |
| 51 | execsql { |
| 52 | CREATE VIEW v1 AS SELECT * FROM t1, t2; |
| 53 | SELECT rowid, * FROM v1; |
| 54 | } |
| 55 | } {{} 1 2 3 7 8 9} |
drh | da808d5 | 2003-07-09 16:34:56 +0000 | [diff] [blame] | 56 | |
| 57 | # Check name binding precedence. Ticket #387 |
| 58 | # |
| 59 | do_test misc2-3.1 { |
| 60 | catchsql { |
| 61 | SELECT t1.b+t2.b AS a, t1.a, t2.a FROM t1, t2 WHERE a==10 |
| 62 | } |
| 63 | } {1 {ambiguous column name: a}} |
drh | dc2d94d | 2003-07-27 17:16:06 +0000 | [diff] [blame] | 64 | |
| 65 | # Make sure 32-bit integer overflow is handled properly in queries. |
| 66 | # ticket #408 |
| 67 | # |
| 68 | do_test misc2-4.1 { |
| 69 | execsql { |
| 70 | INSERT INTO t1 VALUES(4000000000,'a','b'); |
| 71 | SELECT a FROM t1 WHERE a>1; |
| 72 | } |
| 73 | } {4000000000} |
| 74 | do_test misc2-4.2 { |
| 75 | execsql { |
| 76 | INSERT INTO t1 VALUES(2147483648,'b2','c2'); |
| 77 | INSERT INTO t1 VALUES(2147483647,'b3','c3'); |
| 78 | SELECT a FROM t1 WHERE a>2147483647; |
| 79 | } |
| 80 | } {4000000000 2147483648} |
| 81 | do_test misc2-4.3 { |
| 82 | execsql { |
| 83 | SELECT a FROM t1 WHERE a<2147483648; |
| 84 | } |
| 85 | } {1 2147483647} |
| 86 | do_test misc2-4.4 { |
| 87 | execsql { |
| 88 | SELECT a FROM t1 WHERE a<=2147483648; |
| 89 | } |
| 90 | } {1 2147483648 2147483647} |
| 91 | do_test misc2-4.5 { |
| 92 | execsql { |
| 93 | SELECT a FROM t1 WHERE a<10000000000; |
| 94 | } |
| 95 | } {1 4000000000 2147483648 2147483647} |
| 96 | do_test misc2-4.6 { |
| 97 | execsql { |
| 98 | SELECT a FROM t1 WHERE a<1000000000000 ORDER BY 1; |
| 99 | } |
| 100 | } {1 2147483647 2147483648 4000000000} |
drh | 4305d10 | 2003-07-30 12:34:12 +0000 | [diff] [blame] | 101 | |
| 102 | # There were some issues with expanding a SrcList object using a call |
| 103 | # to sqliteSrcListAppend() if the SrcList had previously been duplicated |
| 104 | # using a call to sqliteSrcListDup(). Ticket #416. The following test |
| 105 | # makes sure the problem has been fixed. |
| 106 | # |
| 107 | do_test misc2-5.1 { |
| 108 | execsql { |
| 109 | CREATE TABLE x(a,b); |
| 110 | CREATE VIEW y AS |
| 111 | SELECT x1.b AS p, x2.b AS q FROM x AS x1, x AS x2 WHERE x1.a=x2.a; |
| 112 | CREATE VIEW z AS |
| 113 | SELECT y1.p, y2.p FROM y AS y1, y AS y2 WHERE y1.q=y2.q; |
| 114 | SELECT * from z; |
| 115 | } |
| 116 | } {} |
drh | 901afd4 | 2003-08-26 11:25:58 +0000 | [diff] [blame] | 117 | |
| 118 | # Make sure we can open a database with an empty filename. What this |
| 119 | # does is store the database in a temporary file that is deleted when |
| 120 | # the database is closed. Ticket #432. |
| 121 | # |
| 122 | do_test misc2-6.1 { |
| 123 | db close |
| 124 | sqlite db {} |
| 125 | execsql { |
| 126 | CREATE TABLE t1(a,b); |
| 127 | INSERT INTO t1 VALUES(1,2); |
| 128 | SELECT * FROM t1; |
| 129 | } |
| 130 | } {1 2} |
drh | e4c6169 | 2003-08-27 22:54:31 +0000 | [diff] [blame] | 131 | |
| 132 | # Make sure we get an error message (not a segfault) on an attempt to |
| 133 | # update a table from within the callback of a select on that same |
| 134 | # table. |
| 135 | # |
| 136 | do_test misc2-7.1 { |
| 137 | db close |
| 138 | file delete -force test.db |
| 139 | sqlite db test.db |
| 140 | execsql { |
| 141 | CREATE TABLE t1(x); |
| 142 | INSERT INTO t1 VALUES(1); |
| 143 | } |
| 144 | set rc [catch { |
| 145 | db eval {SELECT rowid FROM t1} {} { |
| 146 | db eval "DELETE FROM t1 WHERE rowid=$rowid" |
| 147 | } |
| 148 | } msg] |
| 149 | lappend rc $msg |
| 150 | } {1 {database table is locked}} |
| 151 | do_test misc2-7.2 { |
| 152 | set rc [catch { |
| 153 | db eval {SELECT rowid FROM t1} {} { |
| 154 | db eval "INSERT INTO t1 VALUES(3)" |
| 155 | } |
| 156 | } msg] |
| 157 | lappend rc $msg |
| 158 | } {1 {database table is locked}} |
| 159 | do_test misc2-7.3 { |
| 160 | db close |
| 161 | file delete -force test.db |
| 162 | sqlite db :memory: |
| 163 | execsql { |
| 164 | CREATE TABLE t1(x); |
| 165 | INSERT INTO t1 VALUES(1); |
| 166 | } |
| 167 | set rc [catch { |
| 168 | db eval {SELECT rowid FROM t1} {} { |
| 169 | db eval "DELETE FROM t1 WHERE rowid=$rowid" |
| 170 | } |
| 171 | } msg] |
| 172 | lappend rc $msg |
| 173 | } {1 {database table is locked}} |
| 174 | do_test misc2-7.4 { |
| 175 | set rc [catch { |
| 176 | db eval {SELECT rowid FROM t1} {} { |
| 177 | db eval "INSERT INTO t1 VALUES(3)" |
| 178 | } |
| 179 | } msg] |
| 180 | lappend rc $msg |
| 181 | } {1 {database table is locked}} |
drh | 61b487d | 2003-09-12 02:08:14 +0000 | [diff] [blame] | 182 | |
| 183 | # Ticket #453. If the SQL ended with "-", the tokenizer was calling that |
| 184 | # an incomplete token, which caused problem. The solution was to just call |
| 185 | # it a minus sign. |
| 186 | # |
| 187 | do_test misc2-8.1 { |
| 188 | catchsql {-} |
| 189 | } {1 {near "-": syntax error}} |
drh | 0f18bfa | 2003-12-10 01:31:21 +0000 | [diff] [blame] | 190 | |
| 191 | # Ticket #513. Make sure the VDBE stack does not grow on a 3-way join. |
| 192 | # |
| 193 | do_test misc2-9.1 { |
| 194 | execsql { |
| 195 | BEGIN; |
| 196 | CREATE TABLE counts(n INTEGER PRIMARY KEY); |
| 197 | INSERT INTO counts VALUES(0); |
| 198 | INSERT INTO counts VALUES(1); |
| 199 | INSERT INTO counts SELECT n+2 FROM counts; |
| 200 | INSERT INTO counts SELECT n+4 FROM counts; |
| 201 | INSERT INTO counts SELECT n+8 FROM counts; |
| 202 | COMMIT; |
| 203 | |
| 204 | CREATE TEMP TABLE x AS |
| 205 | SELECT dim1.n, dim2.n, dim3.n |
| 206 | FROM counts AS dim1, counts AS dim2, counts AS dim3 |
| 207 | WHERE dim1.n<10 AND dim2.n<10 AND dim3.n<10; |
| 208 | |
| 209 | SELECT count(*) FROM x; |
| 210 | } |
| 211 | } {1000} |
| 212 | do_test misc2-9.2 { |
| 213 | execsql { |
| 214 | DROP TABLE x; |
| 215 | CREATE TEMP TABLE x AS |
| 216 | SELECT dim1.n, dim2.n, dim3.n |
| 217 | FROM counts AS dim1, counts AS dim2, counts AS dim3 |
| 218 | WHERE dim1.n>=6 AND dim2.n>=6 AND dim3.n>=6; |
| 219 | |
| 220 | SELECT count(*) FROM x; |
| 221 | } |
| 222 | } {1000} |
| 223 | do_test misc2-9.3 { |
| 224 | execsql { |
| 225 | DROP TABLE x; |
| 226 | CREATE TEMP TABLE x AS |
| 227 | SELECT dim1.n, dim2.n, dim3.n, dim4.n |
| 228 | FROM counts AS dim1, counts AS dim2, counts AS dim3, counts AS dim4 |
| 229 | WHERE dim1.n<5 AND dim2.n<5 AND dim3.n<5 AND dim4.n<5; |
| 230 | |
| 231 | SELECT count(*) FROM x; |
| 232 | } |
| 233 | } [expr 5*5*5*5] |
drh | acf4ac9 | 2003-12-17 23:57:34 +0000 | [diff] [blame] | 234 | |
| 235 | finish_test |