SQL Programming Manual for Pascal

Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal528614-001
7-13
Overview of a Dynamic SQL Program
Using a cursor host variable:
EXEC SQL OPEN :CURSOR_HOSTVAR
USING DESCRIPTOR :INPUT_SQLDA_PTR^;
5. Execute a loop to fetch the values and display them.
Using a cursor name:
EXEC SQL FETCH C1
USING DESCRIPTOR :OUTPUT_SQLDA_PTR^;
Using a cursor host variable:
EXEC SQL FETCH :CURSOR_HOSTVAR
USING DESCRIPTOR :OUTPUT_SQLDA_PTR^;
Display the values in a format according to data type.
(For a repetitive display of column names, use the output names buffer at this
point and omit Step 6 under Handling the Output Variables on page 7-11.)
To handle null values:
If SQLVAR.NULL_INFO is -1, then check the indicator variable pointed to by
SQLVAR.IND_PTR. If the indicator variable is also -1, display something
representing a null value (perhaps blanks or zeroes); otherwise, display the
value pointed to by SQLVAR.VAR_PTR.
If NULL_INFO is 0, display the value pointed to by VAR_PTR.
6. Close the cursor:
Using a cursor name:
EXEC SQL CLOSE C1;
Using a cursor host variable:
EXEC SQL CLOSE :CURSOR_HOSTVAR;
7. If the statement was not a SELECT statement, execute the statement:
If there were input parameters:
Using a statement name:
EXEC SQL EXECUTE S1
USING DESCRIPTOR :INPUT_SQLDA_PTR^;
Using a statement host variable:
EXEC SQL EXECUTE :STATEMENT_HOSTVAR
USING DESCRIPTOR :INPUT_SQLDA_PTR^;
If there were no input parameters:
Using a statement name:
EXEC SQL EXECUTE S1;