The mi_exec() function

The mi_exec() function sends an SQL statement to the database server for parsing, optimization, and execution.

Syntax

mi_integer mi_exec(conn, stmt_strng, control)
   MI_CONNECTION *conn;
   const mi_string *stmt_strng;
   mi_integer control;
conn
A pointer to a connection descriptor established by a previous call to mi_open(), mi_server_connect(), or mi_server_reconnect().
stmt_strng
A pointer to the statement string that contains the text of the SQL statement to execute.
control
A bit mask of flags that determines the control mode for any results that the executed SQL statement returns. The valid control flags are:
MI_QUERY_BINARY
The query results are in binary representation rather than text strings.
MI_QUERY_NORMAL
The query results are in text representation (null-terminated strings).
Valid in client LIBMI application? Valid in user-defined routine?
Yes Yes

Usage

The mi_exec() function performs the following tasks:
  • Sends the statement string to the database server for parsing, optimization, and execution
  • If any rows are to be returned, creates and opens an implicit cursor, which is read only and sequential

    If the SQL statement is not a SELECT statement, the statement is executed. If it is SELECT, mi_exec() automatically creates and opens a cursor for the retrieved rows.

Tip: The mi_exec() function does not handle execution of prepared statements. To send prepared statements to the database server, use the mi_exec_prepared_statement() or mi_open_prepared_statement() function.

The mi_exec() function only sends the statement; it does not return results to the DataBlade® API module. To get results after the execution of mi_exec(), the DataBlade® API module needs to execute the mi_get_result() function in a loop.

The current statement must finish before the database server can process the next statement. The mi_query_finish() function can be used to force a statement to finish processing. It is strongly advised that you use either the mi_query_finish() function or a mi_get_result() loop after each mi_exec() function.
Restriction: Do not use a handle returned by the mi_get_session_connection() function in a call to the mi_exec() function. You need to use the mi_lo_open() function to obtain a handle.

For general information about how to send statements with mi_exec(), see the Informix® DataBlade® API Programmer's Guide.

Return values

MI_OK
The function was successful.
MI_ERROR
The function was not successful.

A successful return indicates only that the connection is valid and the statement was successfully executed (for statements other than SELECT) or a cursor was successfully opened (for SELECT). It does not indicate the success of the SQL statement. Use mi_get_result() to determine the success of the SQL statement.