SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
C Sample Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
A-21
Using a Dynamic SQL Cursor With Descriptor Area
:hv_length = RETURNED_LENGTH,
:hv_indicator = INDICATOR_DATA;
switch (hv_type) {
case 1:
printf ("Char : %s, Type: %d, Length: %d, Null: %d",
hv_name, hv_type, hv_length, hv_indicator);
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:hv_char = VARIABLE_DATA;
hv_char[hv_length] = '\0';
printf (" Value: %s\n", hv_char);
break;
case -601:
printf ("MPvarchar: %s, Type: %d, Length: %d, Null: %d",
hv_name, hv_type, hv_length, hv_indicator);
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:hv_char = VARIABLE_DATA;
hv_char[hv_length] = '\0';
printf (" Value: %s\n", hv_char);
break;
case 2:
printf ("Numeric: %s, Type: %d, Precision: %d,"
" Scale: %d, Length: %d, Null: %d",
hv_name, hv_type, hv_precision,
hv_scale, hv_length, hv_indicator);
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:hv_double = VARIABLE_DATA;
if (hv_scale > 0) {
hv_double = hv_double/pow(10,hv_scale);
printf (" Value: %f\n", hv_double);
} else printf (" Value: %.f\n", hv_double);
break;
case 3:
printf ("Decimal: %s, Type: %d, Precision: %d,"
" Scale: %d,\n Length: %d, Null: %d",
hv_name, hv_type, hv_precision,
hv_scale, hv_length, hv_indicator);
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:hv_double = VARIABLE_DATA;
if (hv_scale > 0) {
hv_double = hv_double/pow(10,hv_scale);
printf (" Value: %f\n", hv_double);
} else printf (" Value: %.f\n", hv_double);
break;
case 4:
printf ("Integer: %s, Type: %d, Precision: %d,"
" Scale: %d,\n Length: %d, Null: %d",
hv_name, hv_type, hv_precision,
hv_scale, hv_length, hv_indicator);
EXEC SQL GET DESCRIPTOR 'out_sqlda' VALUE :i
:hv_double = VARIABLE_DATA;
if (hv_scale > 0) {
hv_double = hv_double/pow(10,hv_scale);
Example A-7. Using a Dynamic SQL Cursor With Descriptor Areas (page 4 of 8)