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

C Sample Programs
HP NonStop SQL/MX Programming Manual for C and COBOL523627-004
A-17
Using a Dynamic SQL Cursor With Descriptor Area
Using a Dynamic SQL Cursor With Descriptor Area
Example A-7 on page A-18 executes the steps shown in Figure 11-1 on page 11-2 but
without using the host variable argument lists for the FETCH INTO statement. Instead
of argument lists, the values of the output parameters are stored in the descriptor area,
retrieved by using the GET DESCRIPTOR statement, and assigned to a compatible
host variable by testing on the data type.
You would probably choose this program to enter a general cursor specification of the
form: SELECT * FROM catalog.schema.table.
if (strcmp(SQLSTATE, SQLSTATE_OK) == 0)
printf("\nThe program completed successfully. \n\n");
else {
EXEC SQL GET DIAGNOSTICS
:hv_num = NUMBER;
for (i = 1; i <= hv_num; i++) {
EXEC SQL GET DIAGNOSTICS EXCEPTION :i
:hv_tabname = TABLE_NAME,
:hv_colname = COLUMN_NAME,
:hv_sqlstate = RETURNED_SQLSTATE,
:hv_msgtxt = MESSAGE_TEXT;
hv_tabname[128]='\0'; hv_colname[128]='\0';
hv_sqlstate[5]='\0'; hv_msgtxt[128]='\0';
printf("Table : %s\n", hv_tabname);
printf("Column : %s\n", hv_colname);
printf("SQLSTATE: %s\n", hv_sqlstate);
printf("Message : %s\n", hv_msgtxt);
} /* end for */
} /* end else */
return 0;
} /* end main */
Example A-6. Using a Dynamic SQL Cursor (page 3 of 3)