# select * from T1       inner join T2 using (<列2個>) where〈 列2個, 列リスト含む 〉
#                   left outer
#                  right outer
# using(<列>), where句付きjoinテスト (where句内でjoinに使われる列が一部(1個)又はすべて(2個)含まれる)
# --boolean検索有り
# 複索引
# --T1索引無し, T2索引無し
# --同種テスト 11[1-4]54

Begin;
Initialize;

InitializeSession "";
Command "create database TESTDB";
TerminateSession;

InitializeSession "TESTDB";

# テーブルT1
Command  "create table T1(C1 int, C2 varchar(2), C3 nvarchar(4), C4 nvarchar(448))";
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [111,  "1",  "ほげ", textsjisfile "..\\..\\doc\\lab.txt"   ];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [222,  "2",  "ホゲ", textsjisfile "..\\..\\doc\\ricoh.txt"];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [222,  "3",  "ホゲ", textsjisfile "..\\..\\doc\\ricoh.txt"];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [222,  "4",  "ホゲ", textsjisfile "..\\..\\doc\\ricoh.txt"];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [null,  1,   "ぴよ", textsjisfile "..\\..\\doc\\hello.txt"];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [333,  null, "ぴよ", textsjisfile "..\\..\\doc\\hello.txt"];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [333,  "3",   null,  textsjisfile "..\\..\\doc\\hello.txt"];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [333,  "4",  "ぴよ", null                                 ];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [null, null, "ぴよ", textsjisfile "..\\..\\doc\\in_lab.txt"];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [444,  "2",   null,  null                                 ];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [444,  null, "ホゲ", null                                 ];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [null, "4",  "null", textsjisfile "..\\..\\doc\\in_lab.txt"];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [444,  null, "ホゲ", textsjisfile "..\\..\\doc\\lab.txt"   ];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [111,  null,  null,  null                                 ];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [null, "1",   null,  null                                 ];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [null, null, "ほげ", null                                 ];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [null, null,  null,  textsjisfile "..\\..\\doc\\lab.txt"   ];
Command  "insert into T1 (C1, C2, C3, C4) values (?, ?, ?, ?)" [null, null,  null,  null                                 ];


# テーブルT2
Command  "create table T2(C1 int, C2 varchar(2), C3 nvarchar(4), C4 nvarchar(448))";
Command  "insert into T2 (C1, C2, C3, C4) values (?, ?, ?, ?)" [111,  "1",  "ほげ", textsjisfile "..\\..\\doc\\in_lab.txt"   ];
Command  "insert into T2 (C1, C2, C3, C4) values (?, ?, ?, ?)" [222,  "2",  "ほげ", textsjisfile "..\\..\\doc\\ricoh.txt"];
Command  "insert into T2 (C1, C2, C3, C4) values (?, ?, ?, ?)" [333,  "2",  "ホゲ", textsjisfile "..\\..\\doc\\ricoh.txt"];
Command  "insert into T2 (C1, C2, C3, C4) values (?, ?, ?, ?)" [444,  "2",  "ホゲ", textsjisfile "..\\..\\doc\\in_lab.txt"   ];
Command  "insert into T2 (C1, C2, C3, C4) values (?, ?, ?, ?)" [null,  3,   "ぴよ", textsjisfile "..\\..\\doc\\hello.txt"];
Command  "insert into T2 (C1, C2, C3, C4) values (?, ?, ?, ?)" [222,  null, "ぴよ", textsjisfile "..\\..\\doc\\hello.txt"];
Command  "insert into T2 (C1, C2, C3, C4) values (?, ?, ?, ?)" [333,  "3",   null,  textsjisfile "..\\..\\doc\\in_lab.txt"   ];
Command  "insert into T2 (C1, C2, C3, C4) values (?, ?, ?, ?)" [444,  "3",  "ぷう", null                                 ];


#両方含む
# inner
Command  "select * from T1 inner join T2 using (C1, C1) where C1 is null and C1 is null";
Command  "select * from T1 inner join T2 using (C1, C2) where C1 is null and C2 is null";
Command  "select * from T1 inner join T2 using (C1, C3) where C1 is null and C3 is null";
Command  "select * from T1 inner join T2 using (C1, C4) where C1 is null and C4 is null";
Command  "select * from T1 inner join T2 using (C2, C2) where C2 is null and C2 is null";
Command  "select * from T1 inner join T2 using (C2, C3) where C2 is null and C3 is null";
Command  "select * from T1 inner join T2 using (C2, C4) where C2 is null and C4 is null";
Command  "select * from T1 inner join T2 using (C3, C3) where C3 is null and C3 is null";
Command  "select * from T1 inner join T2 using (C3, C4) where C3 is null and C4 is null";
Command  "select * from T1 inner join T2 using (C4, C4) where C4 is null and C4 is null";

Command  "select * from T1 inner join T2 using (C1, C1) where C1 >= (?) and C1 >= (?)"   [222, 222];
Command  "select * from T1 inner join T2 using (C1, C2) where C1 >= (?) and C2 >= (?)"   [222, "2"];
Command  "select * from T1 inner join T2 using (C1, C3) where C1 >= (?) and C3 >= (?)"   [222, "ほげ"];
Command  "select * from T1 inner join T2 using (C1, C4) where C1 >= (?) and C4 like (?)" [222, "株式会社リコー%"];
Command  "select * from T1 inner join T2 using (C2, C2) where C2 >= (?) and C2 >= (?)"   ["2", "2"];
Command  "select * from T1 inner join T2 using (C2, C3) where C2 >= (?) and C3 >= (?)"   ["2", "ほげ"];
Command  "select * from T1 inner join T2 using (C2, C4) where C2 >= (?) and C4 like (?)" ["2", "株式会社リコー%"];
Command  "select * from T1 inner join T2 using (C3, C3) where C3 >= (?) and C3 >= (?)"   ["ほげ", "ほげ"];
Command  "select * from T1 inner join T2 using (C3, C4) where C3 >= (?) and C4 like (?)" ["ほげ", "株式会社リコー%"];
Command  "select * from T1 inner join T2 using (C4, C4) where C4 like (?) and C4 like (?)" ["株式会社リコー%", "株式会社リコー%"];

# left outer
Command  "select * from T1 left outer join T2 using (C1, C1) where C1 is null and C1 is null";
Command  "select * from T1 left outer join T2 using (C1, C2) where C1 is null and C2 is null";
Command  "select * from T1 left outer join T2 using (C1, C3) where C1 is null and C3 is null";
Command  "select * from T1 left outer join T2 using (C1, C4) where C1 is null and C4 is null";
Command  "select * from T1 left outer join T2 using (C2, C2) where C2 is null and C2 is null";
Command  "select * from T1 left outer join T2 using (C2, C3) where C2 is null and C3 is null";
Command  "select * from T1 left outer join T2 using (C2, C4) where C2 is null and C4 is null";
Command  "select * from T1 left outer join T2 using (C3, C3) where C3 is null and C3 is null";
Command  "select * from T1 left outer join T2 using (C3, C4) where C3 is null and C4 is null";
Command  "select * from T1 left outer join T2 using (C4, C4) where C4 is null and C4 is null";

Command  "select * from T1 left outer join T2 using (C1, C1) where C1 >= (?) and C1 >= (?)"   [222, 222];
Command  "select * from T1 left outer join T2 using (C1, C2) where C1 >= (?) and C2 >= (?)"   [222, "2"];
Command  "select * from T1 left outer join T2 using (C1, C3) where C1 >= (?) and C3 >= (?)"   [222, "ほげ"];
Command  "select * from T1 left outer join T2 using (C1, C4) where C1 >= (?) and C4 like (?)" [222, "株式会社リコー%"];
Command  "select * from T1 left outer join T2 using (C2, C2) where C2 >= (?) and C2 >= (?)"   ["2", "2"];
Command  "select * from T1 left outer join T2 using (C2, C3) where C2 >= (?) and C3 >= (?)"   ["2", "ほげ"];
Command  "select * from T1 left outer join T2 using (C2, C4) where C2 >= (?) and C4 like (?)" ["2", "株式会社リコー%"];
Command  "select * from T1 left outer join T2 using (C3, C3) where C3 >= (?) and C3 >= (?)"   ["ほげ", "ほげ"];
Command  "select * from T1 left outer join T2 using (C3, C4) where C3 >= (?) and C4 like (?)" ["ほげ", "株式会社リコー%"];
Command  "select * from T1 left outer join T2 using (C4, C4) where C4 like (?) and C4 like (?)" ["株式会社リコー%", "株式会社リコー%"];

# right outer
Command  "select * from T1 right outer join T2 using (C1, C1) where C1 is null and C1 is null";
Command  "select * from T1 right outer join T2 using (C1, C2) where C1 is null and C2 is null";
Command  "select * from T1 right outer join T2 using (C1, C3) where C1 is null and C3 is null";
Command  "select * from T1 right outer join T2 using (C1, C4) where C1 is null and C4 is null";
Command  "select * from T1 right outer join T2 using (C2, C2) where C2 is null and C2 is null";
Command  "select * from T1 right outer join T2 using (C2, C3) where C2 is null and C3 is null";
Command  "select * from T1 right outer join T2 using (C2, C4) where C2 is null and C4 is null";
Command  "select * from T1 right outer join T2 using (C3, C3) where C3 is null and C3 is null";
Command  "select * from T1 right outer join T2 using (C3, C4) where C3 is null and C4 is null";
Command  "select * from T1 right outer join T2 using (C4, C4) where C4 is null and C4 is null";

Command  "select * from T1 right outer join T2 using (C1, C1) where C1 >= (?) and C1 >= (?)"   [222, 222];
Command  "select * from T1 right outer join T2 using (C1, C2) where C1 >= (?) and C2 >= (?)"   [222, "2"];
Command  "select * from T1 right outer join T2 using (C1, C3) where C1 >= (?) and C3 >= (?)"   [222, "ほげ"];
Command  "select * from T1 right outer join T2 using (C1, C4) where C1 >= (?) and C4 like (?)" [222, "株式会社リコー%"];
Command  "select * from T1 right outer join T2 using (C2, C2) where C2 >= (?) and C2 >= (?)"   ["2", "2"];
Command  "select * from T1 right outer join T2 using (C2, C3) where C2 >= (?) and C3 >= (?)"   ["2", "ほげ"];
Command  "select * from T1 right outer join T2 using (C2, C4) where C2 >= (?) and C4 like (?)" ["2", "株式会社リコー%"];
Command  "select * from T1 right outer join T2 using (C3, C3) where C3 >= (?) and C3 >= (?)"   ["ほげ", "ほげ"];
Command  "select * from T1 right outer join T2 using (C3, C4) where C3 >= (?) and C4 like (?)" ["ほげ", "株式会社リコー%"];
Command  "select * from T1 right outer join T2 using (C4, C4) where C4 like (?) and C4 like (?)" ["株式会社リコー%", "株式会社リコー%"];


#片方含む
# inner
Command  "select * from T1 inner join T2 using (C1, C2) where C1 >= (?) and T1.C3 >= (?)"   [222, "ほげ"];
Command  "select * from T1 inner join T2 using (C1, C2) where C1 >= (?) and T1.C4 like (?)" [222, "株式会社リコー%"];
Command  "select * from T1 inner join T2 using (C1, C2) where C2 >= (?) and T2.C3 >= (?)"   ["2", "ほげ"];
Command  "select * from T1 inner join T2 using (C1, C2) where C2 >= (?) and T2.C4 like (?)" ["2", "株式会社リコー%"];

Command  "select * from T1 inner join T2 using (C1, C3) where C1 >= (?) and T1.C2 >= (?)"   [222, "2"];
Command  "select * from T1 inner join T2 using (C1, C3) where C1 >= (?) and T1.C4 like (?)" [222, "株式会社リコー%"];
Command  "select * from T1 inner join T2 using (C1, C3) where C3 >= (?) and T2.C2 >= (?)"   ["ほげ", "2"];
Command  "select * from T1 inner join T2 using (C1, C3) where C3 >= (?) and T2.C4 like (?)" ["ほげ", "株式会社リコー%"];

Command  "select * from T1 inner join T2 using (C1, C4) where C1 >= (?) and T1.C2 >= (?)"   [222, "2"];
Command  "select * from T1 inner join T2 using (C1, C4) where C1 >= (?) and T1.C3 >= (?)"   [222, "ほげ"];
Command  "select * from T1 inner join T2 using (C1, C4) where C4 like (?) and T2.C2 >= (?)" ["株式会社リコー%", "2"];
Command  "select * from T1 inner join T2 using (C1, C4) where C4 like (?) and T2.C3 >= (?)" ["株式会社リコー%", "ほげ"];

Command  "select * from T1 inner join T2 using (C2, C3) where C2 >= (?) and T1.C1 >= (?)"   ["2", 222];
Command  "select * from T1 inner join T2 using (C2, C3) where C2 >= (?) and T1.C4 like (?)" ["2", "株式会社リコー%"];
Command  "select * from T1 inner join T2 using (C2, C3) where C3 >= (?) and T2.C1 >= (?)"   ["ほげ", 222];
Command  "select * from T1 inner join T2 using (C2, C3) where C3 >= (?) and T2.C4 like (?)" ["ほげ", "株式会社リコー%"];

Command  "select * from T1 inner join T2 using (C2, C4) where C2 >= (?) and T1.C1 >= (?)"   ["2", 222];
Command  "select * from T1 inner join T2 using (C2, C4) where C2 >= (?) and T1.C3 >= (?)"   ["2", "ほげ"];
Command  "select * from T1 inner join T2 using (C2, C4) where C4 like (?) and T2.C1 >= (?)" ["株式会社リコー%", 222];
Command  "select * from T1 inner join T2 using (C2, C4) where C4 like (?) and T2.C3 >= (?)" ["株式会社リコー%", "ほげ"];

Command  "select * from T1 inner join T2 using (C3, C4) where C3 >= (?) and T1.C1 >= (?)"   ["ほげ", 222];
Command  "select * from T1 inner join T2 using (C3, C4) where C3 >= (?) and T1.C2 >= (?)"   ["ほげ", "2"];
Command  "select * from T1 inner join T2 using (C3, C4) where C4 like (?) and T2.C1 >= (?)" ["株式会社リコー%", 222];
Command  "select * from T1 inner join T2 using (C3, C4) where C4 like (?) and T2.C2 >= (?)" ["株式会社リコー%", "2"];

# left outer
Command  "select * from T1 left outer join T2 using (C1, C2) where C1 >= (?) and T1.C3 >= (?)"   [222, "ほげ"];
Command  "select * from T1 left outer join T2 using (C1, C2) where C1 >= (?) and T1.C4 like (?)" [222, "株式会社リコー%"];
Command  "select * from T1 left outer join T2 using (C1, C2) where C2 >= (?) and T2.C3 >= (?)"   ["2", "ほげ"];
Command  "select * from T1 left outer join T2 using (C1, C2) where C2 >= (?) and T2.C4 like (?)" ["2", "株式会社リコー%"];

Command  "select * from T1 left outer join T2 using (C1, C3) where C1 >= (?) and T1.C2 >= (?)"   [222, "2"];
Command  "select * from T1 left outer join T2 using (C1, C3) where C1 >= (?) and T1.C4 like (?)" [222, "株式会社リコー%"];
Command  "select * from T1 left outer join T2 using (C1, C3) where C3 >= (?) and T2.C2 >= (?)"   ["ほげ", "2"];
Command  "select * from T1 left outer join T2 using (C1, C3) where C3 >= (?) and T2.C4 like (?)" ["ほげ", "株式会社リコー%"];

Command  "select * from T1 left outer join T2 using (C1, C4) where C1 >= (?) and T1.C2 >= (?)"   [222, "2"];
Command  "select * from T1 left outer join T2 using (C1, C4) where C1 >= (?) and T1.C3 >= (?)"   [222, "ほげ"];
Command  "select * from T1 left outer join T2 using (C1, C4) where C4 like (?) and T2.C2 >= (?)" ["株式会社リコー%", "2"];
Command  "select * from T1 left outer join T2 using (C1, C4) where C4 like (?) and T2.C3 >= (?)" ["株式会社リコー%", "ほげ"];

Command  "select * from T1 left outer join T2 using (C2, C3) where C2 >= (?) and T1.C1 >= (?)"   ["2", 222];
Command  "select * from T1 left outer join T2 using (C2, C3) where C2 >= (?) and T1.C4 like (?)" ["2", "株式会社リコー%"];
Command  "select * from T1 left outer join T2 using (C2, C3) where C3 >= (?) and T2.C1 >= (?)"   ["ほげ", 222];
Command  "select * from T1 left outer join T2 using (C2, C3) where C3 >= (?) and T2.C4 like (?)" ["ほげ", "株式会社リコー%"];

Command  "select * from T1 left outer join T2 using (C2, C4) where C2 >= (?) and T1.C1 >= (?)"   ["2", 222];
Command  "select * from T1 left outer join T2 using (C2, C4) where C2 >= (?) and T1.C3 >= (?)"   ["2", "ほげ"];
Command  "select * from T1 left outer join T2 using (C2, C4) where C4 like (?) and T2.C1 >= (?)" ["株式会社リコー%", 222];
Command  "select * from T1 left outer join T2 using (C2, C4) where C4 like (?) and T2.C3 >= (?)" ["株式会社リコー%", "ほげ"];

Command  "select * from T1 left outer join T2 using (C3, C4) where C3 >= (?) and T1.C1 >= (?)"   ["ほげ", 222];
Command  "select * from T1 left outer join T2 using (C3, C4) where C3 >= (?) and T1.C2 >= (?)"   ["ほげ", "2"];
Command  "select * from T1 left outer join T2 using (C3, C4) where C4 like (?) and T2.C1 >= (?)" ["株式会社リコー%", 222];
Command  "select * from T1 left outer join T2 using (C3, C4) where C4 like (?) and T2.C2 >= (?)" ["株式会社リコー%", "2"];

# right outer
Command  "select * from T1 right outer join T2 using (C1, C2) where C1 >= (?) and T1.C3 >= (?)"   [222, "ほげ"];
Command  "select * from T1 right outer join T2 using (C1, C2) where C1 >= (?) and T1.C4 like (?)" [222, "株式会社リコー%"];
Command  "select * from T1 right outer join T2 using (C1, C2) where C2 >= (?) and T2.C3 >= (?)"   ["2", "ほげ"];
Command  "select * from T1 right outer join T2 using (C1, C2) where C2 >= (?) and T2.C4 like (?)" ["2", "株式会社リコー%"];

Command  "select * from T1 right outer join T2 using (C1, C3) where C1 >= (?) and T1.C2 >= (?)"   [222, "2"];
Command  "select * from T1 right outer join T2 using (C1, C3) where C1 >= (?) and T1.C4 like (?)" [222, "株式会社リコー%"];
Command  "select * from T1 right outer join T2 using (C1, C3) where C3 >= (?) and T2.C2 >= (?)"   ["ほげ", "2"];
Command  "select * from T1 right outer join T2 using (C1, C3) where C3 >= (?) and T2.C4 like (?)" ["ほげ", "株式会社リコー%"];

Command  "select * from T1 right outer join T2 using (C1, C4) where C1 >= (?) and T1.C2 >= (?)"   [222, "2"];
Command  "select * from T1 right outer join T2 using (C1, C4) where C1 >= (?) and T1.C3 >= (?)"   [222, "ほげ"];
Command  "select * from T1 right outer join T2 using (C1, C4) where C4 like (?) and T2.C2 >= (?)" ["株式会社リコー%", "2"];
Command  "select * from T1 right outer join T2 using (C1, C4) where C4 like (?) and T2.C3 >= (?)" ["株式会社リコー%", "ほげ"];

Command  "select * from T1 right outer join T2 using (C2, C3) where C2 >= (?) and T1.C1 >= (?)"   ["2", 222];
Command  "select * from T1 right outer join T2 using (C2, C3) where C2 >= (?) and T1.C4 like (?)" ["2", "株式会社リコー%"];
Command  "select * from T1 right outer join T2 using (C2, C3) where C3 >= (?) and T2.C1 >= (?)"   ["ほげ", 222];
Command  "select * from T1 right outer join T2 using (C2, C3) where C3 >= (?) and T2.C4 like (?)" ["ほげ", "株式会社リコー%"];

Command  "select * from T1 right outer join T2 using (C2, C4) where C2 >= (?) and T1.C1 >= (?)"   ["2", 222];
Command  "select * from T1 right outer join T2 using (C2, C4) where C2 >= (?) and T1.C3 >= (?)"   ["2", "ほげ"];
Command  "select * from T1 right outer join T2 using (C2, C4) where C4 like (?) and T2.C1 >= (?)" ["株式会社リコー%", 222];
Command  "select * from T1 right outer join T2 using (C2, C4) where C4 like (?) and T2.C3 >= (?)" ["株式会社リコー%", "ほげ"];

Command  "select * from T1 right outer join T2 using (C3, C4) where C3 >= (?) and T1.C1 >= (?)"   ["ほげ", 222];
Command  "select * from T1 right outer join T2 using (C3, C4) where C3 >= (?) and T1.C2 >= (?)"   ["ほげ", "2"];
Command  "select * from T1 right outer join T2 using (C3, C4) where C4 like (?) and T2.C1 >= (?)" ["株式会社リコー%", 222];
Command  "select * from T1 right outer join T2 using (C3, C4) where C4 like (?) and T2.C2 >= (?)" ["株式会社リコー%", "2"];

Command  "drop table T2";

Command  "drop table T1";


TerminateSession;
# DBの後始末
InitializeSession "";
Command  "drop database TESTDB";
TerminateSession;
Terminate;
End;
