Preparing SQL Requests

The PREPARE statement permits you to submit parameterized SQL requests for subsequent execution using the EXECUTE verb. PREPARE contains a statement name and a statement prototype. A statement name must not conflict with any other user-defined object, and a statement prototype is an SQL request with possible parameter markers (question marks) coded in place of a literal.

The SQL Translator checks the prototype statement for correct syntax. If it finds no violations, it retains the statement for future use and returns an answer set description and a parameter count to the application (see the EDAPREPARE specification in the API Reference manual for a discussion of how to access this information). Prepared requests are not shareable, nor are they held permanently. Statement prototypes are removed from the environment at the close of an end user session or upon receipt of a COMMIT or ROLLBACK request. The server provides no other means for removing, retaining, or maintaining statement prototypes.

prepare-statement ::= PREPARE <stmt-name> FROM <prototype>
prototype ::= <query-exp> | <delete-statement> |
<insert-statement> | <update-statement>

Top of page

Example: Preparing an SQL Request

PREPARE MY_QUERY FROM
SELECT ENAME, DEPARTMENT
FROM EMPLOYEE
WHERE SALARY > ?
PREPARE NEW_CUST FROM
INSERT INTO CUST(COMPANY, CNBR, SALESREP)
VALUES (?, ?, ?)

iWay Software