Interstage Shunsaku Data Manager Application Development Guide - Microsoft(R) Windows(R) 2000/ Microsoft(R) Windows Server(TM) 2003 - - UNIX - |
Contents
Index
![]() ![]() |
Part 2 Developing Applications by APIs | > Chapter 11 Developing C Applications | > 11.2 How to Use C APIs | > 11.2.2 Data Searches |
Sometimes it is useful to be able to aggregate the results of a search, using the values of particular elements.
Use the ShunSearch function to aggregate the content of the data. By specifying an aggregation function in the return expression used as an argument of the ShunSearch function, the results of the search will be aggregated before they are returned. The aggregation process can be used to calculate totals, averages, maximums, minimums, and the number of items.
The following diagram shows the process for aggregating the content of the data that matches conditions.
SHUNHSTMT StmtH; /* Allocate data manipulation handle */ ShunAllocHandle(ConH, &StmtH); (1) /* Execute aggregation */ ShunSearch(StmtH, 1, NULL, 0, 30, "/document/base/prefecture == 'Sydney'", "max(/document/base/price/text())", "/document/base/prefecture/text()", &Hit_Cnt, &Return_Cnt, &Returnable_Cnt, &Rec_Id_Out, &Data, &First_Pos, &Last_Pos); (2) /* Extract aggregated results */ printf("Number of hits = %d\n", Hit_Cnt); (3) if(Hit_Cnt > 0) { for (i = 0; i < Return_Cnt; i++) { printf("[Result] Item No. %d = %s\n", i+1, Data[i].Data); } } /* Release data manipulation handle */ ShunFreeHandle(StmtH); (4) |
Allocate the data manipulation handle in advance by specifying the connection handle to be used as the parent handle in the ShunAllocHandle function.
Specify the data manipulation handle, the data acquisition location (acquisition start position or acquisition end position), the maximum number of data items, the search expression, and the return expression as parameters of the ShunSearch function, and then execute the search. Specify the aggregation function in the return expression.
The total length of the keys specified in the sort expression determines the number of groups that can be returned. A maximum of 1,000 items can be returned. No more data can be returned even if a higher value is specified for the data acquisition position or the maximum number of data items.
The maximum number of data items that can be returned is returned to the output parameter of the ShunSearch function. Appendix C Allowable Values provides a guide to the key lengths and the number of groups that can be returned.
Consecutive data can be extracted by specifying a data acquisition position. This makes it possible to extract more than 1,000 items of data. Refer to 11.2.2.7 Obtaining Consecutive Groups of XML Documents that Match Conditions for details.
The ShunSearch function returns the address of the aggregated results.
Aggregated results consist of structure arrays, so data is extracted from these arrays.
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
![]() ![]() |