Execute SQL statements
To execute an SQL statement, a DataBlade® API module must send the SQL statement to the database server, where the statement is executed.
The DataBlade®
API provides
the following statement-execution functions for use in a DataBlade®
API module:
- mi_exec()
- mi_exec_prepared_statement()
- mi_open_prepared_statement()
All of these functions perform the same basic task: they send a string representation of an SQL statement to the database server, which executes it and returns statement results. The mi_exec() function is the simplest way to execute an SQL statement.
Server only: A C user-defined routine
(UDR) that executes SQL statements must be registered as a variant
function; that is, its CREATE FUNCTION statement must either include
the VARIANT routine modifier or omit both the NOT VARIANT and VARIANT
routine modifiers (VARIANT is the default).
This section provides a summary of factors to consider when choosing
the DataBlade®
API statement-execution
function to use. It then describes the two methods for statement execution.
- Parse, optimize, and execute the statement in one step.
- Parse and optimize the statement to create a prepared statement. Execute the prepared statement.
Tip: Before you use a DataBlade®
API function
that sends an SQL statement to the database server, make sure you
obtain a valid connection descriptor.