drh | 8feb4b1 | 2004-07-19 02:12:14 +0000 | [diff] [blame] | 1 | # 2002 May 24 |
| 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 joins, including outer joins, where |
| 14 | # there are a large number of tables involved in the join. |
| 15 | # |
drh | 1398ad3 | 2005-01-19 23:24:50 +0000 | [diff] [blame] | 16 | # $Id: join3.test,v 1.4 2005/01/19 23:24:51 drh Exp $ |
drh | 8feb4b1 | 2004-07-19 02:12:14 +0000 | [diff] [blame] | 17 | |
| 18 | set testdir [file dirname $argv0] |
| 19 | source $testdir/tester.tcl |
| 20 | |
| 21 | # An unrestricted join |
| 22 | # |
drh | 6d08b4d | 2004-07-20 12:45:22 +0000 | [diff] [blame] | 23 | catch {unset ::result} |
drh | 8feb4b1 | 2004-07-19 02:12:14 +0000 | [diff] [blame] | 24 | set result {} |
drh | 1398ad3 | 2005-01-19 23:24:50 +0000 | [diff] [blame] | 25 | for {set N 1} {$N<=$bitmask_size} {incr N} { |
drh | 8feb4b1 | 2004-07-19 02:12:14 +0000 | [diff] [blame] | 26 | lappend result $N |
| 27 | do_test join3-1.$N { |
| 28 | execsql "CREATE TABLE t${N}(x);" |
| 29 | execsql "INSERT INTO t$N VALUES($N)" |
| 30 | set sql "SELECT * FROM t1" |
| 31 | for {set i 2} {$i<=$N} {incr i} {append sql ", t$i"} |
| 32 | execsql $sql |
| 33 | } $result |
| 34 | } |
| 35 | |
| 36 | # Joins with a comparison |
| 37 | # |
| 38 | set result {} |
drh | 1398ad3 | 2005-01-19 23:24:50 +0000 | [diff] [blame] | 39 | for {set N 1} {$N<=$bitmask_size} {incr N} { |
drh | 8feb4b1 | 2004-07-19 02:12:14 +0000 | [diff] [blame] | 40 | lappend result $N |
| 41 | do_test join3-2.$N { |
| 42 | set sql "SELECT * FROM t1" |
| 43 | for {set i 2} {$i<=$N} {incr i} {append sql ", t$i"} |
| 44 | set sep WHERE |
| 45 | for {set i 1} {$i<$N} {incr i} { |
| 46 | append sql " $sep t[expr {$i+1}].x==t$i.x+1" |
| 47 | set sep AND |
| 48 | } |
drh | 8feb4b1 | 2004-07-19 02:12:14 +0000 | [diff] [blame] | 49 | execsql $sql |
| 50 | } $result |
drh | 8feb4b1 | 2004-07-19 02:12:14 +0000 | [diff] [blame] | 51 | } |
| 52 | |
drh | 1398ad3 | 2005-01-19 23:24:50 +0000 | [diff] [blame] | 53 | # Error of too many tables in the join |
| 54 | # |
| 55 | do_test join3-3.1 { |
| 56 | set sql "SELECT * FROM t1 AS t0, t1" |
| 57 | for {set i 2} {$i<=$bitmask_size} {incr i} {append sql ", t$i"} |
| 58 | catchsql $sql |
| 59 | } [list 1 "at most $bitmask_size tables in a join"] |
| 60 | |
| 61 | |
drh | 8feb4b1 | 2004-07-19 02:12:14 +0000 | [diff] [blame] | 62 | finish_test |