Table 53 shows the functions that the DataBlade API provides to send SQL statements to the database server for execution.
As the preceding table shows, you need to consider the following factors when deciding which DataBlade API statement-execution function to use:
Choose the DataBlade API statement-execution function that is appropriate for the needs of your DataBlade API application.
The DataBlade API statement-execution functions can execute the following types of SQL statements:
Most SQL statements do not return rows. For example, all data definition (DDL) statements and most data manipulation (DML) statements return only a status to indicate the statement's success.
The following SQL statements return rows:
An SQL statement that returns rows is often called a query because it asks the database server to answer a question: which rows match?
The following table shows how to choose a DataBlade API statement-execution function based on the type of SQL statement.
Type of Statement | DataBlade API Function |
---|---|
Query,
Other valid statements |
mi_exec( ),
mi_exec_prepared_statement( ) |
Query only | mi_open_prepared_statement( ) |
A prepared SQL statement is the parsed version of an SQL statement. The database server prepares an SQL statement for execution at a later time. Preparing a statement enables you to separate the parsing and execution phases of the statement execution. When you prepare a statement, you send the statement to the database server to be parsed. The database server checks the statement for syntax errors and creates an optimized version of the statement for execution.
You need to prepare an SQL statement only once. You can then execute the statement multiple times. Each time you execute the statement, you avoid the parsing phase. Prepared statements are useful for SQL statements that execute often in your DataBlade API module.
SQL statements that have missing column or expression values are called parameterized statements because you use input parameters as placeholders for missing column or expression values. An input parameter is a placeholder in an SQL statement that indicates that the actual column value is provided at runtime. You can specify input parameters in the statement text representation of an SQL statement for either of the following reasons:
For a parameterized SQL statement, your DataBlade API module must provide the following information to the database server for each of its input parameters.
Input-Parameter Information | More Information |
---|---|
Specify the input parameter in the text of the SQL statement | Assembling a Prepared Statement |
Specify the value for the input parameter when the statement executes | Assigning Values to Input Parameters |
You can also obtain information about the input parameters after the parameterized statement is prepared. For more information, see Obtaining Input-Parameter Information.
A DataBlade API module can prepare an SQL statement for the following reasons:
The following table shows how to choose a DataBlade API statement-execution function based on whether the SQL statement needs to be prepared.
Statement Needs To Be Prepared? | DataBlade API Function |
---|---|
No | mi_exec( ) |
Yes | mi_exec_prepared_statement( ),
mi_open_prepared_statement( ) |
The mi_exec_prepared_statement( ) or mi_open_prepared_statement( ) function provides argument values for specifying the input-parameter values when the function executes the statement. You can also use these functions to execute prepared statements that do not have input parameters.
When a DataBlade API statement-execution function executes a query, the function must create a place to hold the resulting rows. Each of these functions (mi_exec( ), mi_exec_prepared_statement( ), or mi_open_prepared_statement( )) automatically creates a row cursor (often called simply a cursor). The row cursor is an area of memory that serves as a holding place for rows that the database server has retrieved.
The simplest way to hold the rows of a query is to use an implicit cursor, which is defined with the following characteristics.
Most DataBlade API modules can use an implicit cursor for accessing rows. However, if the cursor characteristics of the implicit cursor are not adequate for the needs of your DataBlade API module, you can define an explicit cursor with any of the following cursor characteristics.
For more information on these cursor characteristics, see Defining an Explicit Cursor.
The following table shows how to choose a DataBlade API statement-execution function based on the type of cursor that the query requires.
Can Query Use Implicit Cursor? | DataBlade API Function |
---|---|
Yes | mi_exec( ),
mi_exec_prepared_statement( ) |
No | mi_open_prepared_statement( ) |
With the mi_open_prepared_statement( ) function, you can specify an explicit cursor to hold the query rows. In addition, you can assign a name to the cursor that you can use in other SQL statements.
Enterprise Edition Home | Express Edition Home | [ Top of Page | Previous Page | Next Page | Contents | Index ]