Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX -
Contents Index PreviousNext

Appendix I Sample C++ .NET Programs> I.2 Updating Data

I.2.2 Deleting Data

The following example shows how the C++ .NET are used to delete data.

'I want to delete the data relating to Hotel 9 from the hotels in Adelaide that have a vacancy on 2006/07/18.'

Perform a search using the date (2006/07/18) and location (Adelaide) as conditions, then delete data whose name matches "Hotel 9".

mark1An Example of Using the APIs

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 SampleDelete {
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 == 'Adelaide' AND /document/information/date == '2006/07/18'";
      req->ReturnExpression = "/document/base/name/text()";
      req->ReplyNumber = 1;
      req->RequestCount = 30;

      // Specify the search condition and execute the search
      ShunResultSet *rs = service->Search( req );

      // Create ShunRecordCollection for deleting data
      ShunRecordCollection *deleteRecords = new ShunRecordCollection();

      // Obtain the record of Hotel 9
      ShunRecordEnumerator *enumerator = rs->Records->GetEnumerator();
      while ( enumerator->MoveNext() ) {
        ShunRecord *record = enumerator->Current;
        if ( record->Data->Equals( "Hotel 9" ) ) {
          deleteRecords->Add( record );
        }
      }

      // Delete the data if acquisition of the corresponding record is successful
      if ( deleteRecords->Count > 0 ) {
        service->Delete( deleteRecords );
        Console::WriteLine( "Deletion complete" );
      }

      // 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 SampleDelete::Main( Environment::GetCommandLineArgs() );
}

mark1Execution Results

Deletion complete

Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006