SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)

Dynamic SQL With Descriptor Areas
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
10-15
Prepare the SQL Statement
Example
desc_max = 1;
EXEC SQL ALLOCATE DESCRIPTOR 'in_sqlda' WITH MAX :desc_max;
This descriptor area can hold only one dynamic input parameter in the prepared
statement.
Allocating the Output SQL Descriptor Area
The number of item descriptor areas for the output SQL descriptor area must be large
enough to hold all the columns of the table referred to in the prepared statement.
Example
desc_max = 6;
EXEC SQL ALLOCATE DESCRIPTOR 'out_sqlda' WITH MAX :desc_max;
This descriptor area can hold up to six columns selected from the table referred to in
the prepared statement.
Prepare the SQL Statement
To execute the dynamic SQL statement, first prepare the statement you have
constructed from user input and stored in a host variable. The PREPARE statement
checks the statement syntax, determines the data types of any parameters, and
compiles the statement. The PREPARE statement also associates the prepared
statement with a name you can use in subsequent EXECUTE statements.
Use this general syntax:
For complete syntax, see the PREPARE statement in the SQL/MX Reference Manual.
Example
EXEC SQL PREPARE sqlstmt FROM :hv_sql_statement;
The SQL identifier sqlstmt is the name of the prepared statement to be used in a
subsequent EXECUTE statement. The host variable hv_sql_statement contains
the dynamic SQL statement you have constructed from user input.
Describe the Input Parameters and the Output Variables
To provide information necessary for the execution of the dynamic SQL statement, you
must describe the dynamic input parameters and the output variables in the prepared
statement. See Describing Input Parameters on page 10-4 and Describing Output
Variables on page 10-7.
PREPARE SQL-statement-name FROM :SQL-statement-variable
C
C
C