データを追加する場合のC++ .NETの使用例を示します。
「神奈川のホテル情報(ホテル9の情報)を1件追加したい。」
追加したいデータを組み立て、データを追加します。
以下にC++ .NETを使用したプログラミング例を示します。
#using <mscorlib.dll> #using <system.dll> #using <Fujitsu.Shunsaku.dll> using namespace System; using namespace Fujitsu::Shunsaku; class SampleInsert { public: static void Main( String *args __gc[] ) { ShunService *service = 0; try { // ShunService の作成 service = new ShunService(); // ホスト名 ポート番号を指定して Shunsaku に接続 service->Host = "DirSvr1"; service->Port = 23101; service->Connect(); // 追加用 ShunRecordCollection を作成 ShunRecordCollection *insertRecords = new ShunRecordCollection(); // 追加用 ShunRecord を作成 ShunRecord *record = new ShunRecord(); // データを指定 record->Data = String::Concat( S"<document>", S" <base>", S" <name>ホテル9</name>", S" <prefecture>新横浜</prefecture>", S" <address>神奈川県横浜市神奈川区</address>", S" <detail>http://xxxxx.co.jp</detail>", S" <price>6000</price>", S" </base>", S" <information>", S" <date>2006年07月18日</date>", S" </information>", S"<note>バス付 トイレ付 禁煙ルーム選択可 地下鉄 △△駅徒歩05分</note>", S"</document>" ); // コレクションに追加 insertRecords->Add( record ); // データを追加 service->Insert( insertRecords ); Console::WriteLine( "追加終了" ); // Shunsaku から切断 service->Disconnect(); } catch ( ShunContinuousException *e ) { // ShunContinuousExceptionが発生した場合の処理を記述 try { if( service != 0 && service->State == ShunConnectionState::Open ) { service->Disconnect(); } } catch ( ShunException *ex ) { Console::WriteLine( "エラーメッセージ : {0}", ex->Message ); } Console::WriteLine( "エラーメッセージ : {0}", e->Message ); } catch ( ShunConnectionTerminatedException *e ) { // ShunConnectionTerminatedExceptionが発生した場合の処理を記述 Console::WriteLine( "エラーメッセージ : {0}", e->Message ); } } }; int main() { return SampleInsert::Main( Environment::GetCommandLineArgs() ); } |
追加終了