INFORMIX
DataBlade API Programmer's Manual
Chapter 7: Processing Results
Home Contents Index Master Index New Book

Using Supporting Functions

In addition to mi_get_result(), other functions report information about the results of the current statement.

The mi_result_command_name() function reports the kind of statement (such as SELECT, INSERT, UPDATE, CREATE, or DROP) as a null-terminated character string. This function might be useful in an interactive application in which the statement sent is not determined until runtime. This function should be used only when mi_get_result() reports that a DML statement completed.

The mi_result_row_count() function returns the number of rows affected by a statement. It is applicable only when mi_get_result() reports that a DML statement completed.

Important: If you want a count of the number of rows that satisfy a given query but you do not want the data in the rows, you can run a query that uses the count aggregate more efficiently than you can run a query that returns the actual rows. For example, the following query counts the number of rows in mytable:

Example: get_results()

The following user-defined function, get_results(), demonstrates an mi_get_result() loop. It also demonstrates the mi_result_command_name() function to get the name of the statement and the mi_result_row_count() function to get the number of rows affected by the statement.

When a query returns rows of data, the get_results() example routine calls another user-defined function, get_data(), to iterate over the rows. For information on how to process the returned rows, see "Fetching Data".

Following the mi_exec() function for a typical SELECT query, mi_get_result() first returns MI_ROWS to indicate that row data is available. The example get_data() function then iterates over all the rows and returns control to the top of the loop. The next call to mi_get_result() returns MI_DML because a data manipulation statement was completed (the iteration in get_data() completed it). A final call to mi_get_result() returns MI_NO_MORE_RESULTS, and the loop terminates.




DataBlade API Programmer's Manual, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.