drh | 63db039 | 2013-01-17 16:18:55 +0000 | [diff] [blame] | 1 | # 2013 April 17 |
| 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. The |
| 12 | # focus of this script is testing of transitive WHERE clause constraints |
| 13 | # |
| 14 | |
| 15 | set testdir [file dirname $argv0] |
| 16 | source $testdir/tester.tcl |
| 17 | |
| 18 | do_execsql_test transitive1-100 { |
| 19 | CREATE TABLE t1(a TEXT, b TEXT, c TEXT COLLATE NOCASE); |
| 20 | INSERT INTO t1 VALUES('abc','abc','Abc'); |
| 21 | INSERT INTO t1 VALUES('def','def','def'); |
| 22 | INSERT INTO t1 VALUES('ghi','ghi','GHI'); |
| 23 | CREATE INDEX t1a1 ON t1(a); |
| 24 | CREATE INDEX t1a2 ON t1(a COLLATE nocase); |
| 25 | |
| 26 | SELECT * FROM t1 WHERE a=b AND c=b AND c='DEF'; |
| 27 | } {def def def} |
| 28 | do_execsql_test transitive1-110 { |
| 29 | SELECT * FROM t1 WHERE a=b AND c=b AND c>='DEF' ORDER BY +a; |
| 30 | } {def def def ghi ghi GHI} |
| 31 | do_execsql_test transitive1-120 { |
| 32 | SELECT * FROM t1 WHERE a=b AND c=b AND c<='DEF' ORDER BY +a; |
| 33 | } {abc abc Abc def def def} |
| 34 | |
| 35 | do_execsql_test transitive1-200 { |
| 36 | CREATE TABLE t2(a INTEGER, b INTEGER, c TEXT); |
| 37 | INSERT INTO t2 VALUES(100,100,100); |
| 38 | INSERT INTO t2 VALUES(20,20,20); |
| 39 | INSERT INTO t2 VALUES(3,3,3); |
| 40 | |
| 41 | SELECT * FROM t2 WHERE a=b AND c=b AND c=20; |
| 42 | } {20 20 20} |
| 43 | do_execsql_test transitive1-210 { |
| 44 | SELECT * FROM t2 WHERE a=b AND c=b AND c>=20 ORDER BY +a; |
| 45 | } {3 3 3 20 20 20} |
| 46 | do_execsql_test transitive1-220 { |
| 47 | SELECT * FROM t2 WHERE a=b AND c=b AND c<=20 ORDER BY +a; |
| 48 | } {20 20 20 100 100 100} |
| 49 | |
drh | b5246e5 | 2013-07-08 21:12:57 +0000 | [diff] [blame] | 50 | # Test cases for ticket [[d805526eae253103] 2013-07-08 |
| 51 | # "Incorrect join result or assertion fault due to transitive constraints" |
| 52 | # |
| 53 | do_execsql_test transitive1-300 { |
| 54 | CREATE TABLE t301(w INTEGER PRIMARY KEY, x); |
| 55 | CREATE TABLE t302(y INTEGER UNIQUE, z); |
| 56 | INSERT INTO t301 VALUES(1,2),(3,4),(5,6); |
| 57 | INSERT INTO t302 VALUES(1,3),(3,6),(5,7); |
| 58 | SELECT * |
| 59 | FROM t301 CROSS JOIN t302 |
| 60 | WHERE w=y AND y IS NOT NULL |
| 61 | ORDER BY +w; |
| 62 | } {1 2 1 3 3 4 3 6 5 6 5 7} |
| 63 | do_execsql_test transitive1-301 { |
| 64 | SELECT * |
| 65 | FROM t301 CROSS JOIN t302 |
| 66 | WHERE w=y AND y IS NOT NULL |
| 67 | ORDER BY w; |
| 68 | } {1 2 1 3 3 4 3 6 5 6 5 7} |
| 69 | do_execsql_test transitive1-310 { |
| 70 | SELECT * |
| 71 | FROM t301 CROSS JOIN t302 ON w=y |
| 72 | WHERE y>1 |
| 73 | ORDER BY +w |
| 74 | } {3 4 3 6 5 6 5 7} |
| 75 | do_execsql_test transitive1-311 { |
| 76 | SELECT * |
| 77 | FROM t301 CROSS JOIN t302 ON w=y |
| 78 | WHERE y>1 |
| 79 | ORDER BY w |
| 80 | } {3 4 3 6 5 6 5 7} |
| 81 | do_execsql_test transitive1-312 { |
| 82 | SELECT * |
| 83 | FROM t301 CROSS JOIN t302 ON w=y |
| 84 | WHERE y>1 |
| 85 | ORDER BY w DESC |
| 86 | } {5 6 5 7 3 4 3 6} |
| 87 | do_execsql_test transitive1-320 { |
| 88 | SELECT * |
| 89 | FROM t301 CROSS JOIN t302 ON w=y |
| 90 | WHERE y BETWEEN 2 AND 4; |
| 91 | } {3 4 3 6} |
| 92 | do_execsql_test transitive1-331 { |
| 93 | SELECT * |
| 94 | FROM t301 CROSS JOIN t302 ON w=y |
| 95 | WHERE y BETWEEN 1 AND 4 |
| 96 | ORDER BY w; |
| 97 | } {1 2 1 3 3 4 3 6} |
| 98 | do_execsql_test transitive1-332 { |
| 99 | SELECT * |
| 100 | FROM t301 CROSS JOIN t302 ON w=y |
| 101 | WHERE y BETWEEN 1 AND 4 |
| 102 | ORDER BY w DESC; |
| 103 | } {3 4 3 6 1 2 1 3} |
| 104 | |
drh | 63db039 | 2013-01-17 16:18:55 +0000 | [diff] [blame] | 105 | finish_test |