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 | 901afd4 | 2003-08-26 11:25:58 +0000 | [diff] [blame^] | 16 | # $Id: misc2.test,v 1.7 2003/08/26 11:25:58 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} |