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-39
Using SQL Descriptors to Select UCS2 Data
// Get the ith output value
for (i=1; i<=degree; i++ ) {
// Get the info about the output value. Assume it is CHARACTER data.
EXEC SQL GET DESCRIPTOR :out_sqlda VALUE :i
:data_type = TYPE,
:charset_name = CHARACTER_SET_NAME;
// Get and print out the output values. Use the relaxation feature
// again to reuse the output host variable ":hv_output_in_UCS2" for
// ISO88591 columns.
if ( strcmp(charset_name, SQLCHARSETSTRING_UNICODE) == 0 ||
strcmp(charset_name, SQLCHARSETSTRING_ISO88591) == 0 )
{
EXEC SQL GET DESCRIPTOR :out_sqlda VALUE :i
:hv_output_in_UCS2 = VARIABLE_DATA,
:return_len = RETURNED_LENGTH;
print_UCS2_string(hv_output_in_UCS2, return_len);
if ( i < degree )
printf(", ");
}
}
printf("\n");
EXEC SQL FETCH cur_name INTO SQL DESCRIPTOR :out_sqlda;
}
// Deallocate the prepared statement and the SQLDAs
EXEC SQL close cur_name;
EXEC SQL DEALLOCATE prepare sqlstmt;
EXEC SQL DEALLOCATE DESCRIPTOR :in_sqlda;
EXEC SQL DEALLOCATE DESCRIPTOR :out_sqlda;
return;
EndOfProcessing:
handle_error();
}
void main()
{
/*test ISO88591 data.*/
strcpy(hv_sql_stmt, "select custname, street FROM usa_customer \
WHERE city = ? ;");
execute_one_statement();
/*test UCS2 data.*/
strcpy(hv_sql_stmt, "select custname, street FROM international_customer \
WHERE city = ? ;");
execute_one_statement();
}
Example A-11. Using SQL Descriptors to Select UCS2 Data (page 5 of 5)