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

# 補足 (040818 horibe)
# No.132「v15から配列要素にnullが含まれていても挿入できるように変更しました。」
# とのことなので、updateに成功するようになった。

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, [textucsfile "..\\..\\doc\\takekurabe.txt",
		      textucsfile "..\\..\\doc\\takekurabe.txt"],
		      ["ja+en", "ja+en"]];
PreparedCommand "ins" [1, [null, textucsfile "..\\..\\doc\\takekurabe.txt"],
		      ["ja+en", "ja+en"]];
PreparedCommand "ins" [2, [textucsfile "..\\..\\doc\\takekurabe.txt", null], 
		      ["ja+en", "ja+en"]];
PreparedCommand "ins" [3, [null, null], ["ja+en", "ja+en"]];

CreatePreparedCommand "langs" "select (N, L) from T";
PreparedCommand "langs";
CreatePreparedCommand "sel" "select N from T where C like ? or C like ?";
PreparedCommand "sel" ["%Google%", "%google%"];

CreatePreparedCommand "upd1" "update T set L=?";
PreparedCommand "upd1" [["ja", "en"]]; #これを省くと再現しない
PreparedCommand "upd1" [["ko", "pt"]]; 
Command "verify index FTIndex cascade continue";

#update(1)
# 下の2つは失敗するはず【注意】補足を参照のこと
PreparedCommand "upd1" [["ja+en", null]];
PreparedCommand "upd1" [[null, "en+ja"]];

PreparedCommand "langs";
PreparedCommand "sel" ["%Google%", "%google%"];

# これは通る
PreparedCommand "upd1" [[null, null]];
Command "verify index FTIndex cascade continue";
ErasePreparedCommand "upd1";

#update(2)
CreatePreparedCommand "upd2" "update T set L=? where N=?";

# 将来韓国語(ko)やポルトガル語(pt)をサポートすることが
# あった場合、"ko"や"pt"は適宜差し替えること
PreparedCommand "upd2" [["pt", "ko"], 2];
PreparedCommand "upd2" [["ja+pt", "ko+nl"], 3];
PreparedCommand "langs";
PreparedCommand "sel" ["%Google%", "%google%"];
Command "verify index FTIndex cascade continue";

ErasePreparedCommand "ins";
ErasePreparedCommand "upd2";
ErasePreparedCommand "langs";
ErasePreparedCommand "sel";

# 二つの配列を一つのカラムに入れようとしている。意図は不明。(040824 horibe)
Command "update T set C=? where N=3" 
	[[textucsfile "..\\..\\doc\\takekurabe.txt"],
	 [textucsfile "..\\..\\doc\\takekurabe.txt"]];

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

TerminateSession;
Terminate;
End;

