PREPARE
Function
The PREPARE statement prepares an SQL statement for later execution.
Invocation
Embedded Mode P Dynamic Mode Interactive Mode
Syntax

statement_identifier | A single identifier used to identify the statement for preparation.
host_variable_identifier_1 | A single host variable identifier of type character string. It receives the unique value which is either generated by CONNX Embedded SQL or is defined in the application program. This value identifies the statement to for preparation.
OUTPUT hvu | The definition of the SQL descriptor area used to describe the expected output of the identified statement.
INPUT hvu | The definition of the SQL descriptor area used to describe the expected input of the identified statement.
character_string_constant | Explicitly contains the source statement for preparation.
host_variable_identifier_2 | A single host variable identifier which contains the character-string representation of the statement for preparation.
host_variable_specification | A single host variable identifier. It must be defined in the application program according to the host language rules. The value of the host variable must be the address of an SQL descriptor area (SQLDA).

Description
The PREPARE statement performs the following actions:
COMPILATION: An SQL statement in a character-string representation is compiled into an executable SQL statement which is called the prepared statement. If an error which prevents the successful compilation of the SQL statement is encountered by CONNX Embedded SQL, an error is passed back to the application program in the SQLCODE field of the SQLCA. In this case no prepared statement is created.
IDENTIFICATION: The prepared statement is kept for later execution. It is identified by the statement identifier provided by the application program or is generated by CONNX Embedded SQL and passed back into host variable 1. If your intention is to have CONNX Embedded SQL generate the statement identifier, it is necessary to initialize the variable with blanks, or an empty string prior to execution. Otherwise, CONNX Embedded SQL will use the actual (non-blank) value of the variable. This identification will be used to refer to the prepared statement in a DESCRIBE, DECLARE CURSOR, or an EXECUTE statement.
DEALLOCATE PREPARE can be used to explicitly delete a prepared statement.
DESCRIPTION: The nature of the prepared statement can be determined and conveyed to the user by supplying appropriate SQL descriptor area variables. The functionality of a DESCRIBE statement can be incorporated into the PREPARE statement. For a full description of this functionality, please refer to the relevant passages of the DESCRIBE statement section.
Limitations
The character-string must contain one of the following statements:
COMMIT, CREATE, DELETE, DROP, INSERT, ROLLBACK, SELECT, or UPDATE.
The statement string cannot contain host variables. Instead, it can contain host variable markers. A host variable marker is represented by a question mark (?). Host variable markers mark those places where values have to be inserted at the time the prepared statement is executed. For a description of how host variable markers are replaced by real values, see EXECUTE. In general, a host variable marker can be used in an SQL statement wherever a host variable can normally appear with the restriction that it must be possible to determine the resulting data type from the expressions contained in this statement.
ANSI Specifics
None.
CONNX Embedded SQL Specifics
This statement can be mixed with any other DML, DDL and/or DCL statements in the same transaction.
Here is an example that prepares the SQL statement with id "identifier1" to remove all rows from the table "cruise".
PREPARE identifier1 FROM
'delete from cruise';
Here is an example that prepares an SQL statement to delete a single row from the table "cruise", where the row for deletion is identified by it's cruise identifier given in a host variable. Note the use of the host variable marker "?".
PREPARE statement_identifier FROM
'delete from cruise where cruise_identifier = ?';
The following example prepares a dynamic SELECT statement where the format of the derived columns is not known until runtime, and hence, the SQLDA needs to be used.
PREPARE statement_identifier INTO OUTPUT :sqlda
FROM :dyn_select_identifier ;