18feb4b1dSdrh# 2002 May 24 28feb4b1dSdrh# 38feb4b1dSdrh# The author disclaims copyright to this source code. In place of 48feb4b1dSdrh# a legal notice, here is a blessing: 58feb4b1dSdrh# 68feb4b1dSdrh# May you do good and not evil. 78feb4b1dSdrh# May you find forgiveness for yourself and forgive others. 88feb4b1dSdrh# May you share freely, never taking more than you give. 98feb4b1dSdrh# 108feb4b1dSdrh#*********************************************************************** 118feb4b1dSdrh# This file implements regression tests for SQLite library. 128feb4b1dSdrh# 138feb4b1dSdrh# This file implements tests for joins, including outer joins, where 148feb4b1dSdrh# there are a large number of tables involved in the join. 158feb4b1dSdrh# 16*1398ad36Sdrh# $Id: join3.test,v 1.4 2005/01/19 23:24:51 drh Exp $ 178feb4b1dSdrh 188feb4b1dSdrhset testdir [file dirname $argv0] 198feb4b1dSdrhsource $testdir/tester.tcl 208feb4b1dSdrh 218feb4b1dSdrh# An unrestricted join 228feb4b1dSdrh# 236d08b4d6Sdrhcatch {unset ::result} 248feb4b1dSdrhset result {} 25*1398ad36Sdrhfor {set N 1} {$N<=$bitmask_size} {incr N} { 268feb4b1dSdrh lappend result $N 278feb4b1dSdrh do_test join3-1.$N { 288feb4b1dSdrh execsql "CREATE TABLE t${N}(x);" 298feb4b1dSdrh execsql "INSERT INTO t$N VALUES($N)" 308feb4b1dSdrh set sql "SELECT * FROM t1" 318feb4b1dSdrh for {set i 2} {$i<=$N} {incr i} {append sql ", t$i"} 328feb4b1dSdrh execsql $sql 338feb4b1dSdrh } $result 348feb4b1dSdrh} 358feb4b1dSdrh 368feb4b1dSdrh# Joins with a comparison 378feb4b1dSdrh# 388feb4b1dSdrhset result {} 39*1398ad36Sdrhfor {set N 1} {$N<=$bitmask_size} {incr N} { 408feb4b1dSdrh lappend result $N 418feb4b1dSdrh do_test join3-2.$N { 428feb4b1dSdrh set sql "SELECT * FROM t1" 438feb4b1dSdrh for {set i 2} {$i<=$N} {incr i} {append sql ", t$i"} 448feb4b1dSdrh set sep WHERE 458feb4b1dSdrh for {set i 1} {$i<$N} {incr i} { 468feb4b1dSdrh append sql " $sep t[expr {$i+1}].x==t$i.x+1" 478feb4b1dSdrh set sep AND 488feb4b1dSdrh } 498feb4b1dSdrh execsql $sql 508feb4b1dSdrh } $result 518feb4b1dSdrh} 528feb4b1dSdrh 53*1398ad36Sdrh# Error of too many tables in the join 54*1398ad36Sdrh# 55*1398ad36Sdrhdo_test join3-3.1 { 56*1398ad36Sdrh set sql "SELECT * FROM t1 AS t0, t1" 57*1398ad36Sdrh for {set i 2} {$i<=$bitmask_size} {incr i} {append sql ", t$i"} 58*1398ad36Sdrh catchsql $sql 59*1398ad36Sdrh} [list 1 "at most $bitmask_size tables in a join"] 60*1398ad36Sdrh 61*1398ad36Sdrh 628feb4b1dSdrhfinish_test 63