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-20
Using a Dynamic SQL Cursor With Descriptor Area
while (!strcmp (SQLSTATE, "00000") && strcmp(SQLSTATE,"02000")) {
/* Process values in the fetched row. */
assign_to_hv();
/* Fetch the next row of the result table. */
EXEC SQL FETCH get_row
INTO SQL DESCRIPTOR 'out_sqlda';
}
/* Close the cursor. */
EXEC SQL CLOSE get_row;
/* Deallocate the prepared statement and the SQLDAs. */
EXEC SQL DEALLOCATE PREPARE cursor_spec;
EXEC SQL DEALLOCATE DESCRIPTOR 'out_sqlda';
} /* end run_dynTest */
void assign_to_hv() {
EXEC SQL BEGIN DECLARE SECTION;
unsigned short hv_num; /* Descriptor fields */
unsigned short i;
VARCHAR hv_name[129];
long hv_type;
long hv_datetime;
long hv_lead_precision;
long hv_precision;
long hv_scale;
long hv_length;
long hv_indicator;
char hv_char[256]; /* Value variables */
VARCHAR hv_varchar[256];
_int64 hv_longval;
int hv_short;
float hv_real;
double hv_double;
date hv_date[11];
time hv_time[16];
timestamp hv_timestamp[27];
INTERVAL YEAR TO MONTH hv_y22mo;
INTERVAL DAY TO SECOND hv_d2s4;
EXEC SQL END DECLARE SECTION;
/* Get the count of the number of output values. */
EXEC SQL GET DESCRIPTOR 'out_sqlda' :hv_num = COUNT;
/* Get the ith output value and save. */
for (i = 1; i <= hv_num; i++) {
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:hv_name = NAME,
:hv_type = TYPE_ANSI,
:hv_datetime = DATETIME_CODE,
:hv_lead_precision = LEADING_PRECISION,
:hv_precision = PRECISION,
:hv_scale = SCALE,
Example A-7. Using a Dynamic SQL Cursor With Descriptor Areas (page 3 of 8)