sqlite/test/join2.test
dan f112f0b3de Add a test case for ticket [25e335f802dd].
FossilOrigin-Name: e500c15a9f55aed1601f7c14169dd56fd76f1fdd
2017-01-10 17:37:49 +00:00

96 lines
2.4 KiB
Plaintext

# 2002 May 24
#
# The author disclaims copyright to this source code. In place of
# a legal notice, here is a blessing:
#
# May you do good and not evil.
# May you find forgiveness for yourself and forgive others.
# May you share freely, never taking more than you give.
#
#***********************************************************************
# This file implements regression tests for SQLite library.
#
# This file implements tests for joins, including outer joins.
#
set testdir [file dirname $argv0]
source $testdir/tester.tcl
set testprefix join2
do_test join2-1.1 {
execsql {
CREATE TABLE t1(a,b);
INSERT INTO t1 VALUES(1,11);
INSERT INTO t1 VALUES(2,22);
INSERT INTO t1 VALUES(3,33);
SELECT * FROM t1;
}
} {1 11 2 22 3 33}
do_test join2-1.2 {
execsql {
CREATE TABLE t2(b,c);
INSERT INTO t2 VALUES(11,111);
INSERT INTO t2 VALUES(33,333);
INSERT INTO t2 VALUES(44,444);
SELECT * FROM t2;
}
} {11 111 33 333 44 444};
do_test join2-1.3 {
execsql {
CREATE TABLE t3(c,d);
INSERT INTO t3 VALUES(111,1111);
INSERT INTO t3 VALUES(444,4444);
INSERT INTO t3 VALUES(555,5555);
SELECT * FROM t3;
}
} {111 1111 444 4444 555 5555}
do_test join2-1.4 {
execsql {
SELECT * FROM
t1 NATURAL JOIN t2 NATURAL JOIN t3
}
} {1 11 111 1111}
do_test join2-1.5 {
execsql {
SELECT * FROM
t1 NATURAL JOIN t2 NATURAL LEFT OUTER JOIN t3
}
} {1 11 111 1111 3 33 333 {}}
do_test join2-1.6 {
execsql {
SELECT * FROM
t1 NATURAL LEFT OUTER JOIN t2 NATURAL JOIN t3
}
} {1 11 111 1111}
ifcapable subquery {
do_test join2-1.7 {
execsql {
SELECT * FROM
t1 NATURAL LEFT OUTER JOIN (t2 NATURAL JOIN t3)
}
} {1 11 111 1111 2 22 {} {} 3 33 {} {}}
}
#-------------------------------------------------------------------------
# Check that ticket [25e335f802ddc] has been resolved. It should be an
# error for the ON clause of a LEFT JOIN to refer to a table to its right.
#
do_execsql_test 2.0 {
CREATE TABLE aa(a);
CREATE TABLE bb(b);
CREATE TABLE cc(c);
INSERT INTO aa VALUES('one');
INSERT INTO bb VALUES('one');
INSERT INTO cc VALUES('one');
}
do_catchsql_test 2.1 {
SELECT * FROM aa LEFT JOIN cc ON (a=b) JOIN bb ON (b=c);
} {1 {ON clause references tables to its right}}
do_catchsql_test 2.2 {
SELECT * FROM aa JOIN cc ON (a=b) JOIN bb ON (b=c);
} {0 {one one one}}
finish_test