Processing the results of the command

Almost all Client-Library programs process results by using a loop controlled by ct_results. Inside the loop, one of several actions takes place on the current type of result. Different types of results require different types of processing.

For row results, typically the number of columns in the result set is determined and then used to control a loop in which result items are bound to program variables. An application can call ct_res_info to get the number of result columns. After the result items are bound using ct_bind, the application calls ct_fetch to fetch data rows until end-of-data.

The results-processing model used in the example is as follows:

ct_results sets up results for processing. The ct_results return parameter RESULT_TYPE indicates the type of result data that is available for processing.

Note that the example program calls ct_results in a loop that continues as long as ct_results returns CS_SUCCEED, indicating that result sets are available for processing. Although this type of program structure is not strictly necessary in the case of a simple language command, it is highly recommended. In more complex programs, it is not possible to predict the number and type of result sets that an application will receive in response to a command.

ct_bind binds a result item to a program variable. Binding creates an association between a result item and a program data space.

ct_fetch fetches result data. In the example, since binding has been specified and the count field in the DATAFMT structure for each column is set to 1, each ct_fetch call copies one row of data into program data space. As each row is fetched, the example program prints it.

After the ct_fetch loop terminates, the example program checks its final return code to find out whether it dropped out because of end-of-data, or because of failure.