The mi_fetch_statement() function
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
- A pointer to the statement descriptor for the prepared statement that the mi_open_prepared_statement() function has opened.
- cursor_action
- This value determines the orientation of the fetch. When a cursor
opens, the current cursor position is before the first element. Possible
values for cursor_action are:
- 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
- The relative or absolute offset of the fetch.
- num_rows
- The number of rows to fetch. Use zero 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 the mi_open_prepared_statement() function 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, the mi_next_row() function returns the NULL-valued pointer and sets its error argument to MI_NO_MORE_RESULTS.
- num_rows value
- Description
- zero
- 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
- The function was successful.
- MI_ERROR
- The function was not successful; the cursor cannot be fetched or the statement is invalid.