Prepares a statement to be executed later or used for a cursor.
PREPARE statement-name FROM statement [ FOR { READ ONLY | UPDATE [ OF column-name-list ] } ] ... [ DESCRIBE describe-type INTO [ [ SQL ] DESCRIPTOR ] descriptor ] ... [ WITH EXECUTE ] describe-type { ALL | BIND VARIABLES | INPUT | OUTPUT | SELECT LIST } ... { LONG NAMES [ [ OWNER.]TABLE.]COLUMN ] | WITH VARIABLE RESULT }
The DESCRIBE INTO DESCRIPTOR clause might improve performance, as it decrease the required client/server communication.
The WITH EXECUTE clause might improve performance, as it decrease the required client/server communication.
EXEC SQL PREPARE employee_statement FROM 'SELECT Surname FROM Employees';
The PREPARE statement prepares an SQL statement from the statement and associates the prepared statement with statement-name.
If a host variable is used for statement-name, it must have the type short int. There is a typedef for this type in sqlca.h called a_sql_statement_number. This type is recognized by the SQL preprocessor and can be used in a DECLARE section. The host variable is filled in by the database during the PREPARE statement and need not be initialized by the programmer.
Preparing COMMIT, PREPARE TO COMMIT, and ROLLBACK statements is still supported for compatibility. However, perform all transaction management operations with static Embedded SQL, because certain application environments may require it. Also, other Embedded SQL systems do not support dynamic transaction management operations.