SQL_PREPARE_STMT¶

Applies to: ORAFlex SQLFlex MYSQLFlex PGFlex DB2Flex

Prepares a statement and opens a cursor to be executed by SQL_EXECUTE_STMT. This command tells the server to parse the SQL statement created by the respective SQL_SET_STMT and all subsequent SQL_APPEND_STMT statements and to allocate cursor handles to be used to fetch the data. A cursor can be thought of as a pointer to a record set. The CURSOR_TYPE argument is only supported by SQLFlex and by default SQLFLex is using a TYPE_SERVER cursor type to all embedded SQL. TYPE_CLIENT should be used only for the statements that are querying LOB columns i.e. TEXT, NVARCHAR(MAX), VARCHAR(MAX), IMAGE, VARBINARY(MAX), XML. If the cursor type is TYPE_SERVER and a LOB type column is selected, MS SQL Server will not be able to get into a transaction, either explicitly or implicitly through a REREAD, LOCK, SAVERECORD, etc.

Syntax

SQL_PREPARE_STMT [of {file}] CURSOR_TYPE {TYPE_NONE/TYPE_CLIENT/TYPE_SERVER}

Parameter

Description

file

The name or number of the file (optional)

CURSOR_TYPE

Used if the cursor type is being set, do not include otherwise

TYPE_NONE

Default cursor will be used

TYPE_CLIENT

A client side cursor should be used

TYPE_SERVER

A server side cursor should be used (Default)

Usage

SQL_PREPARE_STMT
SQL_PREPARE_STMT of Customer
SQL_PREPARE_STMT CURSOR_TYPE TYPE_SERVER
SQL_PREPARE_STMT of Customer CURSOR_TYPE TYPE_CLIENT

Example

Open Customer

String sID sFirstName

SQL_SET_STMT to "SELECT * FROM CUSTOMER WHERE STATUS = 'Active'"
SQL_PREPARE_STMT
SQL_EXECUTE_STMT
SQL_FETCH_NEXT_ROW into sID sFirstName