sl@0
|
1 |
# 2005 September 19
|
sl@0
|
2 |
#
|
sl@0
|
3 |
# The author disclaims copyright to this source code. In place of
|
sl@0
|
4 |
# a legal notice, here is a blessing:
|
sl@0
|
5 |
#
|
sl@0
|
6 |
# May you do good and not evil.
|
sl@0
|
7 |
# May you find forgiveness for yourself and forgive others.
|
sl@0
|
8 |
# May you share freely, never taking more than you give.
|
sl@0
|
9 |
#
|
sl@0
|
10 |
#***********************************************************************
|
sl@0
|
11 |
# This file implements regression tests for SQLite library.
|
sl@0
|
12 |
#
|
sl@0
|
13 |
# This file implements tests for left outer joins containing ON
|
sl@0
|
14 |
# clauses that restrict the scope of the left term of the join.
|
sl@0
|
15 |
#
|
sl@0
|
16 |
# $Id: join5.test,v 1.2 2007/06/08 00:20:48 drh Exp $
|
sl@0
|
17 |
|
sl@0
|
18 |
set testdir [file dirname $argv0]
|
sl@0
|
19 |
source $testdir/tester.tcl
|
sl@0
|
20 |
|
sl@0
|
21 |
|
sl@0
|
22 |
do_test join5-1.1 {
|
sl@0
|
23 |
execsql {
|
sl@0
|
24 |
BEGIN;
|
sl@0
|
25 |
CREATE TABLE t1(a integer primary key, b integer, c integer);
|
sl@0
|
26 |
CREATE TABLE t2(x integer primary key, y);
|
sl@0
|
27 |
CREATE TABLE t3(p integer primary key, q);
|
sl@0
|
28 |
INSERT INTO t3 VALUES(11,'t3-11');
|
sl@0
|
29 |
INSERT INTO t3 VALUES(12,'t3-12');
|
sl@0
|
30 |
INSERT INTO t2 VALUES(11,'t2-11');
|
sl@0
|
31 |
INSERT INTO t2 VALUES(12,'t2-12');
|
sl@0
|
32 |
INSERT INTO t1 VALUES(1, 5, 0);
|
sl@0
|
33 |
INSERT INTO t1 VALUES(2, 11, 2);
|
sl@0
|
34 |
INSERT INTO t1 VALUES(3, 12, 1);
|
sl@0
|
35 |
COMMIT;
|
sl@0
|
36 |
}
|
sl@0
|
37 |
} {}
|
sl@0
|
38 |
do_test join5-1.2 {
|
sl@0
|
39 |
execsql {
|
sl@0
|
40 |
select * from t1 left join t2 on t1.b=t2.x and t1.c=1
|
sl@0
|
41 |
}
|
sl@0
|
42 |
} {1 5 0 {} {} 2 11 2 {} {} 3 12 1 12 t2-12}
|
sl@0
|
43 |
do_test join5-1.3 {
|
sl@0
|
44 |
execsql {
|
sl@0
|
45 |
select * from t1 left join t2 on t1.b=t2.x where t1.c=1
|
sl@0
|
46 |
}
|
sl@0
|
47 |
} {3 12 1 12 t2-12}
|
sl@0
|
48 |
do_test join5-1.4 {
|
sl@0
|
49 |
execsql {
|
sl@0
|
50 |
select * from t1 left join t2 on t1.b=t2.x and t1.c=1
|
sl@0
|
51 |
left join t3 on t1.b=t3.p and t1.c=2
|
sl@0
|
52 |
}
|
sl@0
|
53 |
} {1 5 0 {} {} {} {} 2 11 2 {} {} 11 t3-11 3 12 1 12 t2-12 {} {}}
|
sl@0
|
54 |
do_test join5-1.5 {
|
sl@0
|
55 |
execsql {
|
sl@0
|
56 |
select * from t1 left join t2 on t1.b=t2.x and t1.c=1
|
sl@0
|
57 |
left join t3 on t1.b=t3.p where t1.c=2
|
sl@0
|
58 |
}
|
sl@0
|
59 |
} {2 11 2 {} {} 11 t3-11}
|
sl@0
|
60 |
|
sl@0
|
61 |
# Ticket #2403
|
sl@0
|
62 |
#
|
sl@0
|
63 |
do_test join5-2.1 {
|
sl@0
|
64 |
execsql {
|
sl@0
|
65 |
CREATE TABLE ab(a,b);
|
sl@0
|
66 |
INSERT INTO "ab" VALUES(1,2);
|
sl@0
|
67 |
INSERT INTO "ab" VALUES(3,NULL);
|
sl@0
|
68 |
|
sl@0
|
69 |
CREATE TABLE xy(x,y);
|
sl@0
|
70 |
INSERT INTO "xy" VALUES(2,3);
|
sl@0
|
71 |
INSERT INTO "xy" VALUES(NULL,1);
|
sl@0
|
72 |
}
|
sl@0
|
73 |
execsql {SELECT * FROM xy LEFT JOIN ab ON 0}
|
sl@0
|
74 |
} {2 3 {} {} {} 1 {} {}}
|
sl@0
|
75 |
do_test join5-2.2 {
|
sl@0
|
76 |
execsql {SELECT * FROM xy LEFT JOIN ab ON 1}
|
sl@0
|
77 |
} {2 3 1 2 2 3 3 {} {} 1 1 2 {} 1 3 {}}
|
sl@0
|
78 |
do_test join5-2.3 {
|
sl@0
|
79 |
execsql {SELECT * FROM xy LEFT JOIN ab ON NULL}
|
sl@0
|
80 |
} {2 3 {} {} {} 1 {} {}}
|
sl@0
|
81 |
do_test join5-2.4 {
|
sl@0
|
82 |
execsql {SELECT * FROM xy LEFT JOIN ab ON 0 WHERE 0}
|
sl@0
|
83 |
} {}
|
sl@0
|
84 |
do_test join5-2.5 {
|
sl@0
|
85 |
execsql {SELECT * FROM xy LEFT JOIN ab ON 1 WHERE 0}
|
sl@0
|
86 |
} {}
|
sl@0
|
87 |
do_test join5-2.6 {
|
sl@0
|
88 |
execsql {SELECT * FROM xy LEFT JOIN ab ON NULL WHERE 0}
|
sl@0
|
89 |
} {}
|
sl@0
|
90 |
do_test join5-2.7 {
|
sl@0
|
91 |
execsql {SELECT * FROM xy LEFT JOIN ab ON 0 WHERE 1}
|
sl@0
|
92 |
} {2 3 {} {} {} 1 {} {}}
|
sl@0
|
93 |
do_test join5-2.8 {
|
sl@0
|
94 |
execsql {SELECT * FROM xy LEFT JOIN ab ON 1 WHERE 1}
|
sl@0
|
95 |
} {2 3 1 2 2 3 3 {} {} 1 1 2 {} 1 3 {}}
|
sl@0
|
96 |
do_test join5-2.9 {
|
sl@0
|
97 |
execsql {SELECT * FROM xy LEFT JOIN ab ON NULL WHERE 1}
|
sl@0
|
98 |
} {2 3 {} {} {} 1 {} {}}
|
sl@0
|
99 |
do_test join5-2.10 {
|
sl@0
|
100 |
execsql {SELECT * FROM xy LEFT JOIN ab ON 0 WHERE NULL}
|
sl@0
|
101 |
} {}
|
sl@0
|
102 |
do_test join5-2.11 {
|
sl@0
|
103 |
execsql {SELECT * FROM xy LEFT JOIN ab ON 1 WHERE NULL}
|
sl@0
|
104 |
} {}
|
sl@0
|
105 |
do_test join5-2.12 {
|
sl@0
|
106 |
execsql {SELECT * FROM xy LEFT JOIN ab ON NULL WHERE NULL}
|
sl@0
|
107 |
} {}
|
sl@0
|
108 |
|
sl@0
|
109 |
|
sl@0
|
110 |
finish_test
|