Process statement results
After a DataBlade® API statement-execution function (see Statement-execution functions of the DataBlade API) executes, the SQL statement that it sent to the database server is the most recent SQL statement on the connection. This most recent SQL statement is called the current statement. Information about the current statement is associated with a connection. Only one statement is current at a time.
After you send the current statement to the database server for
execution, your DataBlade®
API module
must process the statement results by:
- Determining the status of the current statement, including whether results are available
- Retrieving any results
Retrieving the results of an SQL statement is a multiphase process
that involves several levels of nested iteration, as the following
table shows.
Statement-processing loop | Description | More information |
---|---|---|
mi_get_result() loop | Outermost loop of the row-retrieval code iterates through each current statement. | Execute the mi_get_result() loop |
mi_next_row() loop | Middle loop of the row-retrieval code iterates through each row that the current statement has retrieved. | Execute the mi_next_row() loop |
Column-value loop | Innermost loop of the row-retrieval code iterates through each column value of a query row. This loop uses the mi_value() or mi_value_by_name() function to obtain the column values. | Execute the column-value loop |
The first step in processing statement results is to determine
the status of the current statement with the mi_get_result() function,
as follows:
- Execute the mi_get_result() function in a loop that iterates for each current statement.
- Interpret the statement status that mi_get_result() returns for each current statement.
For a sample function that shows one way to use mi_get_result() to process statement results, see Example: The get_data() function.