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

# 補足 (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, 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+en", "ja+en"]];
PreparedCommand "ins" [2, [textsjisfile "..\\..\\doc\\rasyoumon.txt", null], 
		      ["ja+en", "ja+en"]];
PreparedCommand "ins" [3, [null, null], ["ja+en", "ja+en"]];

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 N=?";
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\introduction.txt", null], 0];
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\kenpou.txt",
		         textsjisfile "..\\..\\doc\\RainyNight.txt",], 1];
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\KINGARTHURS_ROUNDTABLE.txt",
		         textsjisfile "..\\..\\doc\\rasyoumon.txt",], 2];
PreparedCommand "upd1" [[null, textsjisfile "..\\..\\doc\\introduction.txt"], 3];
Command "select N from T where C like ?" ["%の%"];

#update(2)
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\KINGARTHURS_ROUNDTABLE.txt", null], 3];
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\rasyoumon.txt", null], 2];
PreparedCommand "upd1" [[null, textsjisfile "..\\..\\doc\\RainyNight.txt"], 1];
PreparedCommand "upd1" [[null, textsjisfile "..\\..\\doc\\kenpou.txt"], 0];
Command "select N from T where C like ?" ["%の%"];

#update(3)
CreatePreparedCommand "upd2" "update T set C=? where C like ?";
PreparedCommand "upd2" [[null, null], "%最高裁判所%"];
PreparedCommand "upd2" [[null, null], "%打率%"];
PreparedCommand "upd2" [[textsjisfile "..\\..\\doc\\rasyoumon.txt",
			 textsjisfile "..\\..\\doc\\KINGARTHURS_ROUNDTABLE.txt"], "%老婆%"];
PreparedCommand "upd2" [[textsjisfile "..\\..\\doc\\kenpou.txt",
			 textsjisfile "..\\..\\doc\\RainyNight.txt"], "%ディレクトリ%"];
ErasePreparedCommand "upd2";
Command "select N from T where C like ?" ["%の%"];

CreatePreparedCommand "upd3" "update T set C=? where C like ? and C like ?";
PreparedCommand "upd3" [[textsjisfile "..\\..\\doc\\kenpou.txt",
			 textsjisfile "..\\..\\doc\\rasyoumon.txt"],
			 "%国会%", "%ファイル名%"];
PreparedCommand "upd3" [[textsjisfile "..\\..\\doc\\RainyNight.txt",
			 textsjisfile "..\\..\\doc\\KINGARTHURS_ROUNDTABLE.txt"],
			 "%下人%", "%防御率%"];
ErasePreparedCommand "upd3";
Command "select N from T where C like ?" ["%の%"];
Command "verify index FTIndex cascade continue";

#update(4)
Command "update T set C=? where C is not null" [[null, null]];
Command "select N from T where C like ?" ["%の%"];
Command "verify index FTIndex cascade continue";

#delete(1)
Command "delete from T where N=3";
#update(5)
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\introduction.txt",
		         textsjisfile "..\\..\\doc\\ricoh.txt",], 2];
# SQL文修正【注意】補足を参照のこと
Command "update T set C=? where C=?" [[textsjisfile "..\\..\\doc\\kenpou.txt",
					     textsjisfile "..\\..\\doc\\KINGARTHURS_ROUNDTABLE.txt"], [null,null]];
Command "select N from T where C like ?" ["%の%"];

#delete(2)
Command "delete from T where C like ?" ["%電話帳%"];
#update(6)
PreparedCommand "upd1" [[textsjisfile "..\\..\\doc\\introduction.txt",
		         textsjisfile "..\\..\\doc\\ricoh.txt",], 1];
Command "select N from T where C like ?" ["%の%"];
ErasePreparedCommand "upd1";

#delete(3)
Command "delete from T where L=?" [["en+ja", "ja+en"]];
Command "select count(*) from T";
Command "verify index FTIndex cascade continue";

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

TerminateSession;
Terminate;
End;

