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

Part 2 Developing Applications by APIs> Chapter 11 Developing C Applications> 11.2 How to Use C APIs> 11.2.2 Data Searches

11.2.2.7 Obtaining Consecutive Groups of XML Documents that Match Conditions

It is often desirable for a Web application to be able to divide up search results into a fixed number of items and to obtain these as consecutive groups.

XML documents can be obtained consecutively by specifying the last position information or the first position information obtained by the preceding search process as the acquisition start position or acquisition end position argument of the ShunSearch function.

The following diagram shows the process for consecutively obtaining XML documents that match conditions.

[Figure 11-20 Process for Obtaining XML Documents that Match Conditions Consecutively]

mark1Sample Code

SHUNHSTMT StmtH;
SHUNPOS *First_Pos, *Last_Pos;
int iDirection, Direction;
SHUNPOS *sFirst_Pos, *sLast_Pos, Reply_Pos;

/* Allocate data manipulation handle */                                    (1)
ShunAllocHandle(ConH, &StmtH);

// Change the settings for the third and fourth parameters of the ShunSearch function according to the page to be displayed
// To display the next page, set iDirection to "NEXT". To display the previous page, set iDirection to "PREV"
if(iDirection == NEXT) {
  // Display the next page                                                 (3)
  Reply_Pos = sLast_Pos;
  Direction = SHUN_DIRECTION_FORWARD_EXCLUSIVE;
}else if(iDirection == PREV) {
  // Display the previous page                                             (4)
  Reply_Pos = sFirst_Pos;
  Direction = SHUN_DIRECTION_BACKWARD_EXCLUSIVE;
}else{
  // Display the first page                                                (2)
  Reply_Pos = NULL;
  Direction = 0;
}

/* Execute the search */                                                   (5)
ShunSearch(StmtH, 1, Reply_Pos, Direction, 30,
           Search_Exp, Return_Exp, Sort_Exp,
           &Hit_Cnt, &Return_Cnt, &Returnable_Cnt,
           &Rec_Id_Out,
           &Data, &First_Pos, &Last_Pos); 

/* Extract search results */                                               (6)
printf("Number of hits              = %d\n", Hit_Cnt);
if(Hit_Cnt != 0) { 
  for (i = 0; i < Return_Cnt; i++) {
    printf("[Result] %s\n", Data[i].Data);
  } 
}

/* Store first position information and last position information */             (7)
sLast_Pos = Last_Pos;
sFirst_Pos = First_Pos;

/* Release data manipulation handle */                                      (8)
ShunFreeHandle(StmtH);

mark2(1) Allocate Data Manipulation Handle

Allocate the data manipulation handle in advance by specifying the connection handle to be used as the parent handle in the ShunAllocHandle function.

mark2(2) Display the First Page

For search processing that displays the first page, specify NULL for the data acquisition position (acquisition start position or acquisition end position) in order to start extracting data from the first item. When NULL is specified as the acquisition position, data extraction will commence from the position specified by the reply start number.

mark2(3) Display the Next Page

For search processing that displays the next page, specify the last position from the previous search as the acquisition start position. This makes it possible to obtain the data on the page that follows the previously acquired data.

mark2(4) Display the Previous Page

For search processing that displays the previous page, specify the first position from the previous search as the acquisition end position. This makes it possible to obtain the data that precedes the previously acquired data.

mark2(5) Execute the Search

Execute the search by specifying the data manipulation handle, the data acquisition position (acquisition start position or acquisition end position), the maximum number of data items, the search expression, the return expression, and the areas for receiving start and end position information as parameters of the ShunSearch function.

The area for receiving start or end position information can be the same as the area specified for the acquisition start position or the acquisition end position. In this case, the old position information will be destroyed after it is used to locate the acquisition start position, and new position information will be set in this area by the current search.

mark2(6) Extract Search Results

The ShunSearch function returns the address of the search results. Search results consist of structure arrays, so data is extracted based on this structure form.

mark2(7) Store the First Position Information and Last Position Information

Store the first position information and last position information.

mark2(8) Release Data Manipulation Handle

After the data search has been performed and the results have been extracted, use the ShunFreeHandle function to release the data manipulation handle.


Contents Index PreviousNext

All Rights Reserved, Copyright(C) FUJITSU LIMITED 2006