Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX - |
Contents
Index
![]() ![]() |
Appendix I Sample C++ .NET Programs | > I.1 Searching Data |
Part of the data obtained as search results is sometimes used as additional conditions to perform the next search operation. In this case, it is common to obtain only part of the data as search results instead of the entire data.
The example below shows how to use the C++ .NET to find out how many hotels match the date and location specified as the search condition, as well as to get partial information.
'I want to know the names and rates of up to 30 hotels that have a vacancy on 2006/07/18.
Specify the date (2006/07/18) and the location (Sydney) as search conditions. Also specify the hotel name and rate for the search result, and execute the search.
The following is a sample program using the C++ .NET.
#using <mscorlib.dll> #using <system.dll> #using <Fujitsu.Shunsaku.dll> using namespace System; using namespace Fujitsu::Shunsaku; class SampleSearch { public: static void Main( String *args __gc[] ) { ShunService *service = 0; try { // Create ShunService service = new ShunService(); // Connect Shunsaku by specifying the host name and port number service->Host = "DirSvr1"; service->Port = 33101; service->Connect(); // Create ShunSearchRequirement ShunSearchRequirement *req = new ShunSearchRequirement(); // Set each type of search conditions req->QueryExpression = "/document {/base/city == 'Sydney' AND /information/date == '2006/07/18'}"; req->ReturnExpression = "/document/base/name, /document/base/price"; req->ReplyNumber = 1; req->RequestCount = 30; // Specify the search condition and execute the search ShunResultSet *rs = service->Search( req ); // Display the search results Console::WriteLine( "Number of hits = {0}", __box( rs->HitCount ) ); int i = 0; ShunRecordEnumerator *enumerator = rs->Records->GetEnumerator(); while ( enumerator->MoveNext() ) { ShunRecord *record = enumerator->Current; ++i; Console::WriteLine( "[Result] Item No. {0} = {1}", __box( i ), record->Data ); } // Close the connection to Shunsaku service->Disconnect(); } catch ( ShunContinuousException *e ) { // Processing to perform if ShunContinuousException occurs try { if( service != 0 && service->State == ShunConnectionState::Open ) { service->Disconnect(); } } catch ( ShunException *ex ) { Console::WriteLine( "Error message : {0}", ex->Message ); } Console::WriteLine( "Error message : {0}", e->Message ); } catch ( ShunConnectionTerminatedException *e ) { // Processing to perform if ShunConnectionTerminatedException occurs Console::WriteLine( "Error message : {0}", e->Message ); } } }; int main() { return SampleSearch::Main( Environment::GetCommandLineArgs() ); } |
Number of hits = 3 [Result] Item No. 1 = <document><name>Hotel 1</name><price>350</price></document> [Result] Item No. 2 = <document><name>Hotel 2</name><price>150</price></document> [Result] Item No. 3 = <document><name>Hotel 3</name><price>250</price></document> |
Contents
Index
![]() ![]() |