SQL/MX Programming Manual for C and COBOL (G06.24+, H06.03+)
Host Variables in C/C++ Programs
HP NonStop SQL/MX Programming Manual for C and COBOL—523627-004
3-14
Fixed-Length Character Data
Guidelines for Revising KANJI/KSC5601 Character Set Host
Variables
•
Use the character set clause CHARACTER SET IS KANJI or CHARACTER SET
IS KSC5601.
•
The encoding for KANJI is the double-byte subset of the Shift-JIS, with no check
on code points performed by NonStop SQL/MX. For the best results, use the big-
endian byte order to denote a KANJI character.
•
The encoding for KSC5601 is the double-byte subset (Code set 1) of EUC-KR,
with no check on code points performed by NonStop SQL/MX. For the best results,
use the big-endian byte order to denote a KSC5601 character.
•
In C/C++ embedded applications, the data type for each KANJI/KSC5601
character is wchar_t. Use wide-character C functions instead of single-byte C
functions on the host variables.
Fixed-Length Character Data
The C/C++ language uses a character array plus a null terminator (\0) to store a string
literal. Most C string-handling routines (for example, strlen and printf and wide
character string handling routines wcslen and wprintf) require the null terminator.
Follow these guidelines for handling the null terminator when you declare and use
character arrays as host variables for string literals.
Declaring a Fixed-Length Character Host Variable
When you declare a character array as a host variable, the C/C++ preprocessor
reserves the last character of the array as a placeholder for a null terminator. To allow
for the extra character, declare a character array one character longer than the actual
number of required characters. The INVOKE directive automatically appends an extra
character to a character array. You can also use the preprocessor option of -n, which
null terminates host variable character strings before they are fetched into.
Example
This example uses a declaration for an SQL column up to 20 characters in length:
EXEC SQL BEGIN DECLARE SECTION;
char last_name[21]; /* 20-character last name */
EXEC SQL END DECLARE SECTION;
...
Selecting Character Data
In a C/C++ program, when selecting character data from a database to return to a host
variable array, NonStop SQL/MX does not append a null terminator to the data.
Therefore, before using the array in a C string-handling routine that requires a null
terminator, you must append a null terminator to the array.
C