# lang情報のついた全文索引のテスト(sectionized, delayed, update both)

# 補足 (040825 horibe)
# 「where C is null」はnullの配列にヒットしない(4120で確認)ので、
# where C=?, [null, null] で置き換えた。

Begin;
Initialize;
InitializeSession "DefaultDB";

# 表を作成
Command "create table T (N int, C ntext array [no limit], L language array [no limit])";
Command "create index T_I on T(N)";

# 索引作成
Command "create fulltext index FTIndex on T(C) language column L hint 'sectionized, delayed, inverted=(normalized=true, indexing=dual, tokenizer=DUAL:JAP:ALL:1 @NORMRSCID:1 @UNARSCID:1)'";

#insert
CreatePreparedCommand "ins" "insert into T (N, C, L) values (?, ?, ?)";
PreparedCommand "ins" [0, [textsjisfile "..\\..\\doc\\introduction.txt",
		      textsjisfile "..\\..\\doc\\RainyNight.txt"], ["ja+en", "ja+en"]];
PreparedCommand "ins" [1, [null, textsjisfile "..\\..\\doc\\kenpou.txt"],
		      ["ja", "ja+en"]];
PreparedCommand "ins" [2, [textsjisfile "..\\..\\doc\\rasyoumon.txt", null], 
		      ["ja+en", "ja"]];
PreparedCommand "ins" [3, [null, null], ["ja", "ja"]];
ErasePreparedCommand "ins";

Command "select N from T where L=?" [["ja+en", "ja+en"]];
Command "select N from T where C like ?" ["%の%"];
# verify
Command "verify index FTIndex cascade continue";

#update(1)
CreatePreparedCommand "upd1" "update T set C=? where L=?";
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\introduction.txt", null], ["ja+en", "ja+en"]];
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\kenpou.txt",
		         textsjisfile "..\\..\\doc\\RainyNight.txt",], ["ja", "ja+en"]];
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\KINGARTHURS_ROUNDTABLE.txt",
		         textsjisfile "..\\..\\doc\\rasyoumon.txt",], ["ja+en", "ja"]];
PreparedCommand "upd1" [[null, textsjisfile "..\\..\\doc\\introduction.txt"], ["ja", "ja"]];
ErasePreparedCommand "upd1";
Command "select N, sectionized(C) from T where C like ?" ["%の%"];

#update(2)
CreatePreparedCommand "upd2" "update T set (C,L)=(?,?) where L=?";
PreparedCommand "upd2" [[textsjisfile "..\\..\\doc\\KINGARTHURS_ROUNDTABLE.txt", null],
		       ["en", "en"], ["ja+en", "ja+en"]];
PreparedCommand "upd2" [[textsjisfile "..\\..\\doc\\rasyoumon.txt", null],
		       ["ja+en", "en"], ["ja", "ja+en"]];
PreparedCommand "upd2" [[null, textsjisfile "..\\..\\doc\\RainyNight.txt"],
		       ["en", "ja+en"], ["ja+en", "ja"]];
PreparedCommand "upd2" [[null, textsjisfile "..\\..\\doc\\kenpou.txt"],
		       ["ja+en", "ja+en"], ["ja", "ja"]];
Command "select N, sectionized(C) from T where C like ?" ["%の%"];

#update(3)
PreparedCommand "upd2" [[null, null], ["ja", "ja"], ["ja+en", "ja+en"]]; #3
PreparedCommand "upd2" [[null, null], ["ja+en", "ja+en"], ["en", "en"]]; #0
PreparedCommand "upd2" [[textsjisfile "..\\..\\doc\\kenpou.txt",
			 textsjisfile "..\\..\\doc\\rasyoumon.txt"],
			["ja", "ja"], ["ja+en", "en"]]; #1
PreparedCommand "upd2" [[textsjisfile "..\\..\\doc\\kenpou.txt",
			 textsjisfile "..\\..\\doc\\rasyoumon.txt"],
			["ja+en", "ja+en"], ["en", "ja+en"]]; #2
ErasePreparedCommand "upd2";
Command "select N, L from T";
Command "select N, sectionized(C) from T where C like ?" ["%の%"];

#update(4)
Command "update T set C=? where C like ? and L=?" [[null, null], "%天皇%", ["ja", "ja"]];
Command "update T set L=? where C like ? and L=?" [["en", "en"], "%行方%", ["ja+en", "ja+en"]];
Command "select N, L from T";
Command "select N, sectionized(C) from T where C like ?" ["%の%"];
Command "update T set (C,L)=(?,?) where C like ? and L=?" 
	[[null, null], ["ja", "ja"], "%天皇%", ["en", "en"]];
# SQL文修正【注意】補足を参照のこと
Command "update T set L=? where C=? and L<>?"
	[["ja+en", "ja+en"], [null, null], ["ja+en", "ja+en"]];
Command "select N, sectionized(C) from T where C like ?" ["%の%"];
Command "verify index FTIndex cascade continue";

#delete(1)
Command "delete from T where N>=2";
#update(5)
Command "update T set C=? where N=0" [[textsjisfile "..\\..\\doc\\introduction.txt",
				       textsjisfile "..\\..\\doc\\ricoh.txt"]];
Command "update T set L=? where C is not null" [["ja", "ja"]];
# SQL文修正【注意】補足を参照のこと
Command "update T set L=? where C=?" [["en", "en"],[null, null]];
Command "select N, sectionized(C) from T where C like ?" ["%の%"];

#update(6)
Command "update T set C=? where L=?" 
	[[textsjisfile "..\\..\\doc\\RainyNight.txt", textsjisfile "..\\..\\doc\\KINGARTHURS_ROUNDTABLE.txt",],
	 ["en", "en"]];			         
Command "select N, sectionized(C) from T where C like ?" ["%の%"];

#delete(2)
Command "delete from T where C like ? or L<>?" ["%リコー%", ["ja", "ja"]];
Command "select count(*) from T";
Command "verify index FTIndex cascade continue";

# 全文ファイルテスト用の表を消去
Command "drop table T";

TerminateSession;
Terminate;
End;

