mi_integer mi_open_prepared_statement(stmt_desc, control, params_are_binary, n_params, values, lengths, nulls, types, cursor_name,retlen, rettypes) MI_STATEMENT *stmt_desc; mi_integer control; mi_integer params_are_binary; mi_integer n_params; MI_DATUM values[]; mi_integer lengths[]; mi_integer nulls[]; mi_string *types[]; mi_string *cursor_name; mi_integer retlen; mi_string *rettypes[];
Whether the returned rows are returned in their binary (internal) or text (external) representation
The type of cursor to create and open
Valid in Client LIBMI Application? | Valid in User-Defined Routine? |
---|---|
Yes | Yes |
The mi_open_prepared_statement( ) performs the following tasks:
For any input parameters specified in the statement text of the SQL statement, you must initialize the values, lengths, and nulls arrays. If the prepared statement has input parameters and is not an INSERT statement, you must use the types array to supply the data types of the input parameters. You can provide the input-parameter values in either of the representations that correspond with the params_are_binary flag.
For information on how to bind input-parameter values, see the IBM Informix: DataBlade API Programmer's Guide.
The cursor is stored as part of the statement descriptor. Only one cursor per statement descriptor is current.
The control argument also determines the representation of any returned values.
Data Representation | Control-Flag Value |
---|---|
External (text) representation | None (default) |
Internal (binary) representation | MI_BINARY |
The mi_open_prepared_statement( ) function allocates type descriptors for each of the data types of the input parameters in the types array. If the calls to mi_open_prepared_statement( ) are in a loop in which these data types do not vary between loop iterations, mi_open_prepared_statement( ) can reuse the type descriptors. On the first call to mi_open_prepared_statement( ), specify in the types array the correct data type names for the input parameters. On subsequent calls to mi_open_prepared_statement( ), replace the array of data type names with a NULL-valued pointer.
You can set the data types of the selected columns by setting a pointer to type name for each returned column in the rettypes array. If the pointer is NULL, the type is not modified. It will either be the return type of the column or the type set by a previous mi_open_prepared_statement( ) call. You cannot set the return types of subcolumns of columns of a complex type.
You can use the cursor_name argument to specify the name of the cursor that holds the fetched rows. This name must be unique within the client session.
When you specify a non-NULL value as the cursor_name argument for mi_open_prepared_statement( ), make sure that you specify a NULL-valued pointer as the name argument for the mi_prepare( ) function. If you specify a non-NULL cursor name for mi_prepare( ), use a NULL-valued pointer as the cursor_name value for mi_open_prepared_statement( ). If you specify a cursor name in both mi_prepare( ) and mi_open_prepared_statement( ), the DataBlade API uses the cursor name that mi_open_prepared_statement( ) provides.
To use an internally-generated unique name for the cursor, specify a NULL-valued pointer.
To use an internally generated unique name for the cursor, specify a NULL-valued pointer for the cursor_name argument of mi_open_prepared_statement( ).
Once opened, you can set up rows in the cursor for fetching with the mi_fetch_statement( ) function.
A successful return indicates only that the connection is valid and a cursor was successfully opened. It does not indicate the success of the SQL statement. Use mi_get_result( ) to determine the success of the SQL statement.
See also the descriptions of mi_close_statement( ), mi_exec_prepared_statement( ), mi_fetch_statement( ), mi_get_cursor_table( ), and mi_prepare( ).