SQL Programming Manual for Pascal
Using Dynamic SQL
HP NonStop SQL Programming Manual for Pascal—528614-001
7-11
Overview of a Dynamic SQL Program
If NULL_INFO is 0, it is good practice to set IND_PTR to an invalid address. A
recommended invalid address is %HFFFC0000%D, as shown in the detailed
dynamic SQL program in Appendix C, Examples of Dynamic NonStop SQL
Programs.
6. Loop through the names buffer to read the corresponding name for each
parameter and prompt the user for each value. Read each value into the data
buffer you have allocated for the corresponding parameter, according to the data
type of the value. If the parameter can be null (SQLVAR.NULL_INFO is -1) and the
value entered was null, set the indicator variable at the location in IND_PTR to -1.
Handling the Output Variables
Perform the following steps if SQLSA.PREPARE.OUTPUT_NUM > 0.
1. Get the length of the output names buffer from the field in the SQLSA,
SQLSA.PREPARE.OUTPUT_NAMES_LEN.
2. Call ALLOCATE_SQLDA to allocate memory for the output SQLDA (and output
names buffer, if needed).
3. Initialize the SQLDA header fields (if you explicitly declared the SQLDA, you will
have declared a constant SQLDA_EYE_CATCHER = 'D1'):
OUTPUT_SQLDA_PTR^.EYE_CATCHER := SQLDA_EYE_CATCHER;
OUTPUT_SQLDA_PTR^.NUM_ENTRIES := SQLSA.OUTPUT_NUM;
4. Specify the DESCRIBE statement to access output variables:
Using a statement name:
EXEC SQL DESCRIBE S1
INTO :OUTPUT_SQLDA_PTR^
NAMES INTO :OUTPUT_NAMESBUF_PTR^;
Using a statement host variable:
EXEC SQL DESCRIBE :STATEMENT_HOSTVAR
INTO :OUTPUT_SQLDA_PTR^
NAMES INTO :OUTPUT_NAMESBUF_PTR^;
5. Loop through the SQLVAR array in the output SQLDA (loop n times, where n is the
number of columns from SQLSA.PREPARE.OUTPUT_NUM). On each iteration:
•
Check SQLVAR.DATA_TYPE. If necessary, adjust the data type and reset
SQLVAR.DATA_LEN and SQLVAR.PRECISION accordingly.
•
Allocate a data buffer with size equal to SQLVAR.DATA_LEN for the output
column.
•
Set SQLVAR.VAR_PTR to point to the memory.
If you are not allocating memory dynamically, you will have declared a variable
for each possible column value, and put the address of the variable in
VAR_PTR by using the XADDR function.