xref: /sqlite-3.40.0/test/join4.test (revision 8d7e24f1)
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 left outer joins containing WHERE
14# clauses that restrict the scope of the left term of the join.
15#
16# $Id: join4.test,v 1.2 2004/07/19 19:28:44 drh Exp $
17
18set testdir [file dirname $argv0]
19source $testdir/tester.tcl
20
21do_test join4-1.1 {
22  execsql {
23    create temp table t1(a integer, b varchar(10));
24    insert into t1 values(1,'one');
25    insert into t1 values(2,'two');
26    insert into t1 values(3,'three');
27    insert into t1 values(4,'four');
28
29    create temp table t2(x integer, y varchar(10), z varchar(10));
30    insert into t2 values(2,'niban','ok');
31    insert into t2 values(4,'yonban','err');
32  }
33  execsql {
34    select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
35  }
36} {2 two 2 niban ok}
37do_test join4-1.2 {
38  execsql {
39    select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok'
40  }
41} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
42do_test join4-1.3 {
43  execsql {
44    create index i2 on t2(z);
45  }
46  execsql {
47    select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
48  }
49} {2 two 2 niban ok}
50do_test join4-1.4 {
51  execsql {
52    select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok'
53  }
54} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
55do_test join4-1.5 {
56  execsql {
57    select * from t1 left outer join t2 on t1.a=t2.x where t2.z>='ok'
58  }
59} {2 two 2 niban ok}
60do_test join4-1.4 {
61  execsql {
62    select * from t1 left outer join t2 on t1.a=t2.x and t2.z>='ok'
63  }
64} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
65do_test join4-1.6 {
66  execsql {
67    select * from t1 left outer join t2 on t1.a=t2.x where t2.z IN ('ok')
68  }
69} {2 two 2 niban ok}
70do_test join4-1.7 {
71  execsql {
72    select * from t1 left outer join t2 on t1.a=t2.x and t2.z IN ('ok')
73  }
74} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
75
76
77finish_test
78