Release statement resources
The mi_query_finish() function releases implicitly allocated resources associated with the current statement.
The following table summarizes the implicitly allocated resources
for different query executions.
DataBlade® API function that allocated statement resource | Resources that mi_query_finish() releases |
---|---|
mi_exec() |
|
mi_exec_prepared_statement(), mi_open_prepared_statement() | None Use mi_close_statement() and mi_drop_prepared_statement(). |
mi_next_row() | Release the row structure for the current row. |
mi_get_row_desc_without_row() | Release the row descriptor for the current row. |
The mi_exec() function creates an implicit statement
descriptor and opens an implicit cursor for the SQL statement it executes.
These structures have as their scope from the time they are allocated
with mi_exec() until whichever of the following
events occurs first:
- The mi_query_finish() function finishes execution of the current statement.
- The mi_query_interrupt() function interrupts execution of the current statement.
- The mi_close() function closes the connection.
- The SQL statement that invoked the C UDR ends. (Server only)
To conserve resources, use the mi_query_finish() function to explicitly close the implicit cursor and free the implicit statement descriptor when your DataBlade® API module no longer needs access to the current statement. The mi_query_finish() function is the destructor function for the implicit cursor and its associated implicit statement descriptor.
The mi_query_finish() and mi_query_interrupt() functions
also free the implicit row structure and row descriptor that hold
each row as it is fetched from a cursor. A general rule of DataBlade®
API programming
is that you do not explicitly free a data type structure that you
have not explicitly allocated. This rule applies to the row structure
and row descriptor of the current statement, in particular:
- Do not explicitly free the row structure for the current statement (which the mi_next_row() function returns).
- Do not explicitly free the row descriptor for the current statement (which the mi_get_row_desc_without_row() function returns).
These data type structures are freed when the connection closes.