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-33
Using SQL Descriptor Areas to Select SQL/MP
KANJI and KSC5601 Data
if ( strcmp(charset_name, SQLCHARSETSTRING_KSC5601) == 0 )
{
wchar_t temp[21];
//0123456789012345678901234567890123456789
strcpy((char*)temp, "Korea ");
temp[20] = 0; // add the wide-char NULL for wcscpy
wcscpy(hv_input_in_KSC5601, (wchar_t*)temp);
EXEC SQL SET DESCRIPTOR :in_sqlda VALUE :j
VARIABLE_DATA = :hv_input_in_KSC5601;
} else
return;
}
// Execute the statement using the SQLDAs
EXEC SQL EXECUTE sqlstmt USING SQL DESCRIPTOR :in_sqlda
INTO SQL DESCRIPTOR :out_sqlda;
// Get the count of the number of output values
EXEC SQL GET DESCRIPTOR :out_sqlda :degree = COUNT;
// Get the ith output value
for (i=1; i<=degree; i++ ) {
// Get the info about the output value
EXEC SQL GET DESCRIPTOR :out_sqlda VALUE :i
:data_type = TYPE,
:charset_name = CHARACTER_SET_NAME,
:return_len = RETURNED_LENGTH,
:return_oct_len = RETURNED_OCTET_LENGTH;
// Get and print out the output value based on the character set name
if ( strcmp(charset_name, SQLCHARSETSTRING_KANJI) == 0 ) {
EXEC SQL GET DESCRIPTOR :out_sqlda VALUE :i
:hv_output_in_KANJI = VARIABLE_DATA;
print_singlebyte_string((char*)hv_output_in_KANJI,
return_oct_len);
} else
if ( strcmp(charset_name, SQLCHARSETSTRING_KSC5601) == 0 )
{
EXEC SQL GET DESCRIPTOR :out_sqlda VALUE :i
:hv_output_in_KSC5601 = VARIABLE_DATA;
print_singlebyte_string((char*)hv_output_in_KSC5601, return_oct_len);
} else return;
}
// Deallocate the prepared statement and the SQLDAs
EXEC SQL DEALLOCATE prepare sqlstmt;
EXEC SQL DEALLOCATE DESCRIPTOR :in_sqlda;
EXEC SQL DEALLOCATE DESCRIPTOR :out_sqlda;
return;
EndOfProcessing:
handle_error();
}
void main()
Example A-10. Using SQL Descriptor Areas to Select SQL/MP KANJI and
KSC5601 Data (page4of5)