sl@0: # 2002 May 24 sl@0: # sl@0: # The author disclaims copyright to this source code. In place of sl@0: # a legal notice, here is a blessing: sl@0: # sl@0: # May you do good and not evil. sl@0: # May you find forgiveness for yourself and forgive others. sl@0: # May you share freely, never taking more than you give. sl@0: # sl@0: #*********************************************************************** sl@0: # This file implements regression tests for SQLite library. sl@0: # sl@0: # This file implements tests for left outer joins containing WHERE sl@0: # clauses that restrict the scope of the left term of the join. sl@0: # sl@0: # $Id: join4.test,v 1.4 2005/03/29 03:11:00 danielk1977 Exp $ sl@0: sl@0: set testdir [file dirname $argv0] sl@0: source $testdir/tester.tcl sl@0: sl@0: ifcapable tempdb { sl@0: do_test join4-1.1 { sl@0: execsql { sl@0: create temp table t1(a integer, b varchar(10)); sl@0: insert into t1 values(1,'one'); sl@0: insert into t1 values(2,'two'); sl@0: insert into t1 values(3,'three'); sl@0: insert into t1 values(4,'four'); sl@0: sl@0: create temp table t2(x integer, y varchar(10), z varchar(10)); sl@0: insert into t2 values(2,'niban','ok'); sl@0: insert into t2 values(4,'yonban','err'); sl@0: } sl@0: execsql { sl@0: select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok' sl@0: } sl@0: } {2 two 2 niban ok} sl@0: } else { sl@0: do_test join4-1.1 { sl@0: execsql { sl@0: create table t1(a integer, b varchar(10)); sl@0: insert into t1 values(1,'one'); sl@0: insert into t1 values(2,'two'); sl@0: insert into t1 values(3,'three'); sl@0: insert into t1 values(4,'four'); sl@0: sl@0: create table t2(x integer, y varchar(10), z varchar(10)); sl@0: insert into t2 values(2,'niban','ok'); sl@0: insert into t2 values(4,'yonban','err'); sl@0: } sl@0: execsql { sl@0: select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok' sl@0: } sl@0: } {2 two 2 niban ok} sl@0: } sl@0: do_test join4-1.2 { sl@0: execsql { sl@0: select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok' sl@0: } sl@0: } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}} sl@0: do_test join4-1.3 { sl@0: execsql { sl@0: create index i2 on t2(z); sl@0: } sl@0: execsql { sl@0: select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok' sl@0: } sl@0: } {2 two 2 niban ok} sl@0: do_test join4-1.4 { sl@0: execsql { sl@0: select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok' sl@0: } sl@0: } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}} sl@0: do_test join4-1.5 { sl@0: execsql { sl@0: select * from t1 left outer join t2 on t1.a=t2.x where t2.z>='ok' sl@0: } sl@0: } {2 two 2 niban ok} sl@0: do_test join4-1.4 { sl@0: execsql { sl@0: select * from t1 left outer join t2 on t1.a=t2.x and t2.z>='ok' sl@0: } sl@0: } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}} sl@0: ifcapable subquery { sl@0: do_test join4-1.6 { sl@0: execsql { sl@0: select * from t1 left outer join t2 on t1.a=t2.x where t2.z IN ('ok') sl@0: } sl@0: } {2 two 2 niban ok} sl@0: do_test join4-1.7 { sl@0: execsql { sl@0: select * from t1 left outer join t2 on t1.a=t2.x and t2.z IN ('ok') sl@0: } sl@0: } {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}} sl@0: } sl@0: sl@0: sl@0: finish_test