# select * from T1 natural       inner join T2
#                           left outer
#                          right outer
#
# 各々の型でjoinテスト (naturalで使用される列が1個)
# select文をstart transaction read write;とcommit;で囲んだもの
# 単索引
# --T1索引無し, T2索引無し
# --同種テスト 116[0,2,4,6]0

Begin;
Initialize;

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

InitializeSession "TESTDB";

# テーブルT1(int, varchar)
Command  "create table T1(C1 int, C2 varchar(2))";
Command  "insert into T1 (C1, C2) values (?, ?)" [111,  "1" ];
Command  "insert into T1 (C1, C2) values (?, ?)" [222,  "2" ];
Command  "insert into T1 (C1, C2) values (?, ?)" [333,  null];
Command  "insert into T1 (C1, C2) values (?, ?)" [null, "3" ];
Command  "insert into T1 (C1, C2) values (?, ?)" [666,  "4" ];
Command  "insert into T1 (C1, C2) values (?, ?)" [null, null];


# テーブルT2(nvarchar, text)
Command  "create table T2(C3 nvarchar(4), C4 nvarchar(448))";
Command  "insert into T2 (C3, C4) values (?, ?)" ["ほげ", textsjisfile "..\\..\\doc\\lab.txt"   ];
Command  "insert into T2 (C3, C4) values (?, ?)" ["ホゲ", textsjisfile "..\\..\\doc\\ricoh.txt"];
Command  "insert into T2 (C3, C4) values (?, ?)" ["ぴよ", null                                 ];
Command  "insert into T2 (C3, C4) values (?, ?)" [ null,  textsjisfile "..\\..\\doc\\hello.txt"];
Command  "insert into T2 (C3, C4) values (?, ?)" ["ぷう", textsjisfile "..\\..\\doc\\in_lab.txt"   ];
Command  "insert into T2 (C3, C4) values (?, ?)" [ null,  null                                 ];

Command  "start transaction read write";
Command  "select * from T1 natural inner join T2";
Command  "select * from T1 natural left outer join T2";
Command  "select * from T1 natural right outer join T2";
Command  "commit";

Command  "drop table T1";
Command  "drop table T2";


# テーブルT1(int, nvarchar)
Command  "create table T1(C1 int, C3 nvarchar(4))";
Command  "insert into T1 (C1, C3) values (?, ?)" [111,  "ほげ"];
Command  "insert into T1 (C1, C3) values (?, ?)" [222,  "ホゲ"];
Command  "insert into T1 (C1, C3) values (?, ?)" [333,   null ];
Command  "insert into T1 (C1, C3) values (?, ?)" [null, "ぴよ"];
Command  "insert into T1 (C1, C3) values (?, ?)" [666,  "ぷう"];
Command  "insert into T1 (C1, C3) values (?, ?)" [null,  null ];


# テーブルT2(varchar, text)
Command  "create table T2(C2 varchar(2), C4 nvarchar(448))";
Command  "insert into T2 (C2, C4) values (?, ?)" ["1",  textsjisfile "..\\..\\doc\\lab.txt"   ];
Command  "insert into T2 (C2, C4) values (?, ?)" ["2",  textsjisfile "..\\..\\doc\\ricoh.txt"];
Command  "insert into T2 (C2, C4) values (?, ?)" ["3",  null                                 ];
Command  "insert into T2 (C2, C4) values (?, ?)" [null, textsjisfile "..\\..\\doc\\hello.txt"];
Command  "insert into T2 (C2, C4) values (?, ?)" ["6",  textsjisfile "..\\..\\doc\\in_lab.txt"   ];
Command  "insert into T2 (C2, C4) values (?, ?)" [null, null                                 ];

Command  "start transaction read write";
Command  "select * from T1 natural inner join T2";
Command  "select * from T1 natural left outer join T2";
Command  "select * from T1 natural right outer join T2";
Command  "commit";

Command  "drop table T1";
Command  "drop table T2";


# テーブルT1(int, text)
Command  "create table T1(C1 int, C4 nvarchar(448))";
Command  "insert into T1 (C1, C4) values (?, ?)" [111,  textsjisfile "..\\..\\doc\\lab.txt"   ];
Command  "insert into T1 (C1, C4) values (?, ?)" [222,  textsjisfile "..\\..\\doc\\ricoh.txt"];
Command  "insert into T1 (C1, C4) values (?, ?)" [333,  null                                 ];
Command  "insert into T1 (C1, C4) values (?, ?)" [null, textsjisfile "..\\..\\doc\\hello.txt"];
Command  "insert into T1 (C1, C4) values (?, ?)" [666,  textsjisfile "..\\..\\doc\\in_lab.txt"   ];
Command  "insert into T1 (C1, C4) values (?, ?)" [null, null                                 ];


# テーブルT2(varchar, nvarchar)
Command  "create table T2(C2 varchar(2), C3 nvarchar(4))";
Command  "insert into T2 (C2, C3) values (?, ?)" ["1",  "ほげ"];
Command  "insert into T2 (C2, C3) values (?, ?)" ["2",  "ホゲ"];
Command  "insert into T2 (C2, C3) values (?, ?)" ["3",   null ];
Command  "insert into T2 (C2, C3) values (?, ?)" [null, "ぴよ"];
Command  "insert into T2 (C2, C3) values (?, ?)" ["6",  "ぷう"];
Command  "insert into T2 (C2, C3) values (?, ?)" [null,  null ];

Command  "start transaction read write";
Command  "select * from T1 natural inner join T2";
Command  "select * from T1 natural left outer join T2";
Command  "select * from T1 natural right outer join T2";
Command  "commit";

Command  "drop table T1";
Command  "drop table T2";


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