############################################################################
#C1 DEFAULT指定なしの列
#C2 DEFAULT <literal>の指定を持つ列
#C3 DEFAULT CURRENT_TIMESTAMPの指定を持つ列 #1
#C4 DEFAULT CURRENT_TIMESTAMPの指定を持つ列 #2	... 索引つき
#C5 DEFAULT CURRENT_TIMESTAMP USING ON UPDATEの指定を持つ列 #1
#C6 DEFAULT CURRENT_TIMESTAMP USING ON UPDATEの指定を持つ列 #2	... 索引つき
############################################################################
# default CURRENT_TIMESTAMP テスト
# 

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

InitializeSession "TESTDB";

Command "create table T
(
	C1 int,
	C2 int DEFAULT 1234,
	C3 datetime DEFAULT CURRENT_TIMESTAMP,
	C4 datetime DEFAULT CURRENT_TIMESTAMP,
	C5 datetime DEFAULT CURRENT_TIMESTAMP USING ON UPDATE,
	C6 datetime DEFAULT CURRENT_TIMESTAMP USING ON UPDATE
)";
Command "create index I4 on T(C4)";
Command "create index I6 on T(C6)";

### 1-2 , 2-2 の検査 ###
#単体
#C3のみ、C4のみに値を指定して挿入し、その値が入っていることを確認
Command "insert T(C3) values ('1987-06-05 04:32:10'), ('1234-05-06 07:08:09')";
Command "insert T(C4) values ('1987-06-05 04:32:10'), ('1234-05-06 07:08:09')";

#C1: null, C2: <literal>の値、C3: 指定した値
Command "select C1, C2, C3 from T where C3 <= '2000-01-01 00:00:00'";

#C1: null, C2: <literal>の値、C4: 指定した値
Command "select C1, C2, C4 from T where C4 <= '2000-01-01 00:00:00'";

#C5のみ、C6のみに値を指定して挿入し、その値が入っていることを確認
Command "insert T(C5) values ('1987-06-05 04:32:10'), ('1234-05-06 07:08:09')";
Command "insert T(C6) values ('1987-06-05 04:32:10'), ('1234-05-06 07:08:09')";

#C1: null, C2: <literal>の値、C5: 指定した値
Command "select C1, C2, C5 from T where C5 <= '2000-01-01 00:00:00'";

#C1: null, C2: <literal>の値、C6: 指定した値
Command "select C1, C2, C6 from T where C6 <= '2000-01-01 00:00:00'";


#DEFAULTなしと一緒
#C1とC3、C1とC4に値を指定して挿入し、その値が入っていることを確認
Command "insert T(C1, C3) values (3, '1987-06-05 04:32:10'), (3, '1234-05-06 07:08:09')";
Command "insert T(C1, C4) values (4, '1987-06-05 04:32:10'), (4, '1234-05-06 07:08:09')";

#C1: 指定した値, C2: <literal>の値、C3: 指定した値
Command "select C1, C2, C3 from T where C1 > 0 and C3 <= '2000-01-01 00:00:00'";

#C1: 指定した値, C2: <literal>の値、C4: 指定した値
Command "select C1, C2, C4 from T where C1 > 0 and C4 <= '2000-01-01 00:00:00'";

#C1とC5、C1とC6に値を指定して挿入し、その値が入っていることを確認
Command "insert T(C1, C5) values (5, '1987-06-05 04:32:10'), (5, '1234-05-06 07:08:09')";
Command "insert T(C1, C6) values (6, '1987-06-05 04:32:10'), (6, '1234-05-06 07:08:09')";

#C1: 指定した値, C2: <literal>の値、C5: 指定した値
Command "select C1, C2, C5 from T where C1 > 0 and C5 <= '2000-01-01 00:00:00'";

#C1: 指定した値, C2: <literal>の値、C6: 指定した値
Command "select C1, C2, C6 from T where C1 > 0 and C6 <= '2000-01-01 00:00:00'";


#DEFAULT <literal>と一緒
#C2とC3、C2とC4に値を指定して挿入し、その値が入っていることを確認
Command "insert T(C2, C3) values (3, '1987-06-05 04:32:10'), (3, '1234-05-06 07:08:09')";
Command "insert T(C2, C4) values (4, '1987-06-05 04:32:10'), (4, '1234-05-06 07:08:09')";

#C1: null, C2: 指定した値、C3: 指定した値
Command "select C1, C2, C3 from T where C2 < 10 and C3 <= '2000-01-01 00:00:00'";

#C1: null, C2: 指定した値、C4: 指定した値
Command "select C1, C2, C4 from T where C2 < 10 and C4 <= '2000-01-01 00:00:00'";


#DEFAULT CURRENT_TIMESTAMPと一緒
#C3とC4、C5とC6に値を指定して挿入し、その値が入っていることを確認
Command "insert T(C3, C4) values ('1987-06-05 04:32:10', '1234-05-06 07:08:09'), ('1234-05-06 07:08:09', '1987-06-05 04:32:10')";
Command "insert T(C5, C6) values ('1987-06-05 04:32:10', '1234-05-06 07:08:09'), ('1234-05-06 07:08:09', '1987-06-05 04:32:10')";

#C1: null, C2: 指定した値、C3〜C4: 指定した値
Command "select C1, C2, C3, C4 from T where C3 <= '2000-01-01 00:00:00' and C4 <= '2000-01-01 00:00:00'";

#C1: null, C2: 指定した値、C5〜C6: 指定した値
Command "select C1, C2, C5, C6 from T where C5 <= '2000-01-01 00:00:00' and C6 <= '2000-01-01 00:00:00'";

#C3とC5、C4とC6に値を指定して挿入し、その値が入っていることを確認
Command "insert T(C3, C5) values ('1987-06-05 04:32:10', '1234-05-06 07:08:09'), ('1234-05-06 07:08:09', '1987-06-05 04:32:10')";
Command "insert T(C4, C6) values ('1987-06-05 04:32:10', '1234-05-06 07:08:09'), ('1234-05-06 07:08:09', '1987-06-05 04:32:10')";

#C1: null, C2: 指定した値、C3,C5: 指定した値
Command "select C1, C2, C3, C5 from T where C3 <= '2000-01-01 00:00:00' and C5 <= '2000-01-01 00:00:00'";

#C1: null, C2: 指定した値、C4,C6: 指定した値
Command "select C1, C2, C4, C6 from T where C4 <= '2000-01-01 00:00:00' and C6 <= '2000-01-01 00:00:00'";

#############################
### 1-4 , 2-4 の検査 ########
#単体
#C3のみ、C4のみに値を指定して更新し、その値に変わっていることを確認
Command "update T set C3 = '0123-04-05 06:07:08' where C2 = 3";
Command "update T set C4 = '0123-04-05 06:07:08' where C2 = 4";

#C3: 指定した値
Command "select C3 from T where C3 <= '1000-01-01 00:00:00'";

#C4: 指定した値
Command "select C4 from T where C4 <= '1000-01-01 00:00:00'";

#C5のみ、C6のみに値を指定して挿入し、その値が入っていることを確認
Command "update T set C5 = '0123-04-05 06:07:08' where C2 = 5";
Command "update T set C6 = '0123-04-05 06:07:08' where C2 = 6";

Command "select C5 from T where C5 <= '1000-01-01 00:00:00'";
#	⇒ C5: 指定した値

Command "select C6 from T where C6 <= '1000-01-01 00:00:00'";
#	⇒ C6: 指定した値


#DEFAULTなしと一緒
#C1とC3、C1とC4に値を指定して更新し、その値に変わっていることを確認
Command "update T set C1 = 30, C3 = '0012-03-04 05:06:07' where C2 = 3";
Command "update T set C1 = 40, C4 = '0012-03-04 05:06:07' where C2 = 4";

Command "select C1, C3 from T where C1 > 0 and C3 <= '0100-01-01 00:00:00'";
#	⇒ C1: 指定した値、C3: 指定した値

Command "select C1, C4 from T where C1 > 0 and C4 <= '0100-01-01 00:00:00'";
#	⇒ C1: 指定した値、C4: 指定した値

#C1とC5、C1とC6に値を指定して更新し、その値に変わっていることを確認
Command "update T set C1 = 50, C5 = '0012-03-04 05:06:07' where C2 = 5";
Command "update T set C1 = 60, C6 = '0012-03-04 05:06:07' where C2 = 6";

Command "select C1, C5 from T where C1 > 0 and C5 <= '0100-01-01 00:00:00'";
#	⇒ C1: 指定した値、C5: 指定した値

Command "select C1, C6 from T where C1 > 0 and C6 <= '0100-01-01 00:00:00'";
#	⇒ C1: 指定した値、C6: 指定した値


#DEFAULT CURRENT_TIMESTAMPと一緒
#C3とC4、C5とC6に値を指定して更新し、その値に変わっていることを確認
Command "update T set C3 = '0012-03-04 05:06:07', C4 = '0024-06-08 10:12:14' where C2 in (3,4)";
Command "update T set C5 = '0012-03-04 05:06:07', C6 = '0024-06-08 10:12:14' where C2 in (5,6)";

Command "select C3, C4 from T where C3 <= '0100-01-01 00:00:00' and C4 <= '0100-01-01 00:00:00'";
#	⇒ C3〜C4: 指定した値

Command "select C5, C6 from T where C5 <= '0100-01-01 00:00:00' and C6 <= '0100-01-01 00:00:00'";
#	⇒ C5〜C6: 指定した値

#C3とC5、C4とC6に値を指定して挿入し、その値が入っていることを確認
Command "update T set C3 = '0036-09-12 15:18:21', C5 = '0048-12-16 20:24:28' where C2 in (3,5)";
Command "update T set C4 = '0050-01-05 20:25:30', C6 = '0061-02-18 02:43:03' where C2 in (4,6)";

Command "select C3, C5 from T where C3 <= '0100-01-01 00:00:00' and C5 <= '0100-01-01 00:00:00'";
#	⇒ C3,C5: 指定した値

Command "select C4, C6 from T where C4 <= '0100-01-01 00:00:00' and C6 <= '0100-01-01 00:00:00'";
#	⇒ C4,C6: 指定した値

######################################
### 1-5 の検査 #######################
#ON UPDATEなし同士
#C3の値をC4(およびその逆)に入れて更新し、値が同じになっていることを確認
Command "update T set C4 = C3 where C2 = 3";
Command "update T set C3 = C4 where C2 = 4";

Command "select C3, C4 from T where C2 = 3";
#	⇒ C3,C4: 同じ値

Command "select C3, C4 from T where C2 = 4";
#	⇒ C3,C4: 同じ値

######################################

# tableの後始末
Command  "drop table T";

TerminateSession;

InitializeSession "";
Command "drop database TESTDB";
TerminateSession;
Terminate;
End;