Retrieving query data

About this task

When mi_get_result() returns the MI_ROWS statement status, the query has executed and a cursor is open, as follows:
  • For SQL statements sent with mi_exec() or mi_exec_prepared_statement(), the database server opens an implicit cursor. This cursor contains the retrieved rows, with the database server controlling the rows that are fetched.
  • For SQL statements sent with mi_open_prepared_statement(), the database server opens an explicit cursor. This cursor is empty, with the mi_fetch_statement() controlling the rows that are fetched.
The DataBlade® API module receives the query data on a row-by-row basis. To handle the rows that the current statement has retrieved, the DataBlade® API creates the following data type structures:
  • The row descriptor is the data-description portion, which contains information such as row size and column data types.
  • The row structure is the data portion, which holds one row of data that the query returns.

A one-to-one correspondence occurs between row descriptors and rows. Each row descriptor has an associated row structure.

In a C UDR, the row structure and row descriptor are part of the same data type structure. The row structure is just a data buffer in the row descriptor that holds copies of the column values of a row.

The row descriptor and row structure are valid until the next row is fetched. A row descriptor might need to change on a row-to-row basis for jagged rows. A row structure holds each row, one row at a time.

To retrieve the row of query data:

Procedure

  1. Get a copy of the row descriptor for a query row.
  2. Get the number of columns from the row descriptor.
  3. Retrieve query rows, one row at a time.
  4. For every query row, get the value of any desired column.