Home | Previous Page | Next Page   Function Descriptions >

mi_fetch_statement( )

The mi_fetch_statement( ) function fetches specified rows from the database server into a cursor that is associated with an opened prepared statement.

Syntax

mi_integer mi_fetch_statement(stmt_desc, cursor_action, jump, num_rows)
   MI_STATEMENT *stmt_desc;
   MI_CURSOR_ACTION cursor_action;
   mi_integer jump;
   mi_integer num_rows;
stmt_desc
is a pointer to the statement descriptor for the prepared statement that the mi_open_prepared_statement( ) function has opened.
cursor_action
determines the orientation of the fetch. When a cursor opens, the current cursor position is before the first element. Possible values for cursor_action follow:
MI_CURSOR_NEXT
Fetches the next num_rows rows.
MI_CURSOR_PRIOR
Fetches the previous num_rows rows.
MI_CURSOR_FIRST
Fetches the first num_rows rows.
MI_CURSOR_LAST
Fetches the last num_rows rows.
MI_CURSOR_ABSOLUTE
Moves jump rows into the retrieved rows and fetches num_rows rows.
MI_CURSOR_RELATIVE
Moves jump rows from the current position in the retrieved rows and fetches num_rows rows.
jump
is the relative or absolute offset of the fetch.
num_rows
is the number of rows to fetch. Use zero (0) to fetch all rows.
Valid in Client LIBMI Application? Valid in User-Defined Routine?
Yes Yes

Usage

The mi_fetch_statement( ) function fetches num_rows rows from the cursor_action orientation into an explicit cursor, which mi_open_prepared_statement( ) has opened. The mi_fetch_statement( ) function does not return any rows to the DataBlade API module but copies retrieved rows from the database server into the row cursor that is associated with the stmt_desc statement descriptor. To access a row, use the mi_next_row( ) function, which retrieves the row from the cursor. After you access all rows in the cursor, mi_next_row( ) returns the NULL-valued pointer and sets its error argument to MI_NO_MORE_RESULTS.

To specify the number of rows to fetch, use the num_rows argument.

num_rows Value
Description
zero (0)
mi_fetch_statement( ) fetches all resulting rows into the cursor.
>0
mi_fetch_statement( ) fetches only num_rows rows into the cursor.

Return Values

MI_OK
indicates that the function was successful.
MI_ERROR
indicates that the function was not successful; the cursor could not be fetched or the statement is invalid.

Related Topics

See also the descriptions of mi_get_result( ), mi_next_row( ), mi_open_prepared_statement( ), mi_prepare( ), and mi_result_row_count( ).

Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]