prepare()

variable.Prepare(statement [, isNative])

This method is used to initialize a variable of the PREPARED data type. It prepares an SQL statement for execution in the RDBMS, and allocates the necessary resources to the prepared statement.

After a statement is prepared, it can be executed using the Execute() method. An initialized PREPARED variable can also be used in the Declare() method to declare a cursor for the prepared statement

Usage

This method accepts two parameters and returns sqlca.sqlcode, if the statement was prepared without errors.

The statement argument is either a quoted character string or a variable of a character data type which contains the text of the SQL statement to be prepared. The isNative argument specifies whether the statement should be prepared natively or not, and is optional. It is a BOOLEAN argument and its default value is 0 (FALSE) which indicates that the statement is not prepared natively. If you set it to 1 (TRUE), the statement will be prepared natively bypassing the SQL translator. The value of this argument for an initialized PREPARED variable can be checked using the IsNative() method.

An example method call:

# Preparing and executing an SQL statement

DEFINE prep_v PREPARED

 

CALL prep_v.Prepare("EXECUTE PROCEDURE proc1", 1)

CALL prep_v.Execute()

...

#Using a prepared statement in a cursor

DEFINE prep_v PREPARED,

       cur_v  CURSOR

CALL prep_v.Prepare("SELECT * FROM customers WHERE cust_id>100")

CALL cur_v.Declare(prep_v)