xref: /sqlite-3.40.0/test/join4.test (revision 2ffb1185)
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.1 2004/07/19 19:14:01 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  }
46btree_breakpoint
47  execsql {
48    select * from t1 left outer join t2 on t1.a=t2.x where t2.z='ok'
49  }
50} {2 two 2 niban ok}
51do_test join4-1.4 {
52  execsql {
53    select * from t1 left outer join t2 on t1.a=t2.x and t2.z='ok'
54  }
55} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
56do_test join4-1.5 {
57  execsql {
58    select * from t1 left outer join t2 on t1.a=t2.x where t2.z>='ok'
59  }
60} {2 two 2 niban ok}
61do_test join4-1.4 {
62  execsql {
63    select * from t1 left outer join t2 on t1.a=t2.x and t2.z>='ok'
64  }
65} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
66do_test join4-1.6 {
67  execsql {
68    select * from t1 left outer join t2 on t1.a=t2.x where t2.z IN ('ok')
69  }
70} {2 two 2 niban ok}
71do_test join4-1.7 {
72  execsql {
73    select * from t1 left outer join t2 on t1.a=t2.x and t2.z IN ('ok')
74  }
75} {1 one {} {} {} 2 two 2 niban ok 3 three {} {} {} 4 four {} {} {}}
76
77
78finish_test
79