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 COBOL—523627-004
10-19
Get the Count and Descriptions of the Output
Variables
Example
This statement uses both an input and output SQL descriptor area:
EXEC SQL EXECUTE sqlstmt USING SQL DESCRIPTOR 'in_sqlda'
INTO SQL DESCRIPTOR 'out_sqlda';
Get the Count and Descriptions of the Output Variables
When you have executed the prepared SQL statement, use the GET DESCRIPTOR
statement to retrieve the output values from the output SQL descriptor area. See
Getting the Values of Output Variables on page 10-7.
Retrieving the Count
Use the GET DESCRIPTOR statement to retrieve the COUNT of the SQL item
descriptor areas.
Example
EXEC SQL GET DESCRIPTOR 'out_sqlda' :num = COUNT;
Looping Through the Item Descriptor Areas
Use the COUNT to loop through the item descriptor areas. Test on TYPE or NAME to
assign the value in VARIABLE_DATA to a compatible variable. You can use other
descriptor fields, such as PRECISION, to modify this value. If a selected column is
nullable, you must test the value in the INDICATOR_DATA field to determine whether
an actual value for the column is retrieved in the VARIABLE_DATA field.
Example
/* First, get the count of the number of output values. */
EXEC SQL GET DESCRIPTOR 'out_sqlda' :num = COUNT;
* Second, get the i-th output values and save. */
for (i = 1; i <= num; i++) {
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:sqlda_type = TYPE,
:sqlda_name = NAME;
...
/* Test type or name to determine the host variable. */
/* Assign data value to a compatible host variable. */
...
if (strncmp(sqlda_name,"LAST_NAME",strlen("LAST_NAME"))==0){
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:hv_last_name = VARIABLE_DATA;
hv_last_name[20]='\0';
printf("\nLast name is: %s", hv_last_name);
}
...
else
if (strncmp(sqlda_name,"JOBCODE",strlen("JOBCODE"))==0){
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
C
C
C