Send an SQL statement

The mi_exec() function is for the execution of basic SQL statements, both queries and other valid SQL statements.

In a DataBlade® API module, use the following DataBlade API functions to execute a basic SQL statement.
Step in execution of basic sql statement DataBlade API function
Send the basic SQL statement to the database server for execution and open any cursor required mi_exec()
Release statement resources mi_query_finish(), mi_query_interrupt()

After the database server executes the statement that mi_exec() sends, the statement becomes the current statement. The current statement is the most recent SQL statement on the connection. Only one statement per connection is current. The database server sends back the results of the current statement, including whether the current statement was successful.

The mi_exec() function creates an implicit statement descriptor to hold the information about the current statement. The following table summarizes the memory operations for an implicit statement descriptor.
Memory duration Memory operation Function name
Not allocated from memory-duration pools Constructor mi_exec()
Not allocated from memory-duration pools Destructor mi_query_finish()
The following table lists the DataBlade API accessor functions for the implicit statement descriptor that mi_exec() creates.
Table 1. Accessor functions for an implicit statement descriptor
Statement-descriptor information DataBlade API accessor function
The name of the SQL statement that is the current statement mi_result_command_name()
A row descriptor for the columns in the current statement mi_get_row_desc_without_row()

From the row descriptor, you can use the row-descriptor accessor functions to obtain information about a particular column (see Field and column information in the row descriptor).

You obtain the status of the current statement with the mi_get_result() function.
Tip: The return value that the mi_exec() function returns does not indicate the success of the current statement. It indicates if mi_exec() was able to successfully send the statement to the database server.
When mi_exec() executes a query, it performs the following additional steps:
  1. Opens an implicit cursor to hold the query rows
  2. Reads the query rows into the open cursor