Nonstop Database, HiRDB Version 9 UAP Development Guide

[Contents][Index][Back][Next]

4.2.3 Tables using character sets

If you define character sets, you can store character string data using a different character set in each table column.

Organization of this subsection
(1) Transferring character string data for which a character set is specified
(2) Character code conversion

(1) Transferring character string data for which a character set is specified

This subsection describes an example that transfers character string data for which a character set is specified.

Example:
This example searches column C2 (character set EBCDIK) in table T1. The following shows table T1 and the retrieval SQL statement.
  • Table T1 is defined as follows (underline indicates the character set specification):
     
    CREATE TABLE T1
      (C1 INT, C2 CHAR(30) CHARACTER SET EBCDIK)
     
  • The example uses the following retrieval SQL statement:
    <Declaration of embedded variable>
     
    char DATA[31];
        :
    SELECT C2 FROM T1
      WHERE C2 = :DATA
     
The following figure shows how data is transferred.

Figure 4-8 Transfer of character string data specifying a character set

[Figure]
Explanation:
  1. Acquires character set information for column C2 from the data dictionary table and stores it in the SQL object.
  2. Sets the character set name for C2 in the character set descriptor area#.
  3. If the character set in the input variable differs from the character set in the character set descriptor area, the character set is converted and then assigned.
    If the character set in the output variable differs from the character set in the character set descriptor area, the character set is converted and then stored.
#
This area contains the character set name in a variable (DATA) that was determined dynamically during UAP execution. The contents of the character set descriptor area are used to perform the following processing:
  • The character set name specified by the client is sent to the HiRDB server.
  • The client receives the items retrieved by the SQL statement preprocessed by the HiRDB server and the character set name in the ? parameter.
For details about the character set descriptor area, see Appendix E. Character Set Descriptor Area.

(2) Character code conversion

If the client and server use different character sets, the server converts the character codes. If the client and server both use a predefined character set, character codes are not converted. However, if PDCLTCNVMODE is specified in the client environment definition, character codes are converted according to the specification.

The following table shows character code conversion between client and server, depending on whether character sets are defined.

Table 4-2 Character code conversion between client and server

Character codes used on the client Character codes used on the server
SJIS UJIS UTF-8 LANG-C CHINESE CHINESE-GB18030
UD EK UD UD U16 UD UD UD
SJIS UD -- SVR CLT CLT C-S UN N N
EK SVR -- N N N N N N
UJIS UD N N -- N N UN N N
UTF-8 UD N N N -- SVR UN N N
U16C N N N SVR --# N N N
UCS-2 UD N N CLT CLT C-S N N N
LANG-C UD -- SVR -- -- SVR -- -- --
CHINESE UD N N N N N UN -- N
CHINESE-GB18030 UD N N N N N N N --

Legend:
UD: No character set is defined.
EK: EBCDIK is defined as the character set.
U16: UTF16 is defined as the character set.
U16C: UTF16, UTF-16LE, or UTF-16BE is defined as the character set.
SVR: The server converts character codes.
CLT: The client converts character codes (conversion is specified by using PDCLTCNVMODE in the client environment definition).
C-S: The client performs the server's character code conversion (specified by using PDCLTCNVMODE in the client environment definition) and the server converts the character codes for the character set.
--: Character code conversion is not needed.
UN: Character code conversion is not needed. However, if NOUSE is specified in PDCLTCNVMODE in the client environment definition, character code conversion is performed (double-byte characters are not converted).
N: Character code conversion cannot be performed.

#
If the client and server use different endians for the character codes, endian conversion is performed.
(a) Access from ODBC and ADO.NET application programs

The conversion rules shown in Table 4-2 also apply to access from ODBC and ADO.NET application programs.

Note that the following client versions assume the character set descriptor area as follows:

Client version earlier than 08-05
The client observes the conversion rules shown in Table 4-2, assuming that there is no character set descriptor area.

Client version 08-05 or later
If the client's character encoding is UCS-2 and the server's character encoding is UTF-8, the client observes the conversion rules shown in Table 4-2, assuming UTF-16LE in the character set descriptor area.
(b) Access from OLE DB application programs and JDBC application programs that use a Type2 JDBC driver

These application programs observe the conversion rules shown in Table 4-2, assuming that there is no character set descriptor area.

(c) Access from JDBC application programs that uses a Type4 JDBC driver

If the client version is earlier than 08-05 or the server uses a character encoding that is not UTF-8
The JDBC driver converts character codes to those used by the server by using the encoder provided by Java Virtual Machine (JVM). If the server specifies a character set, then the server converts the character codes.

If the client version is 08-05 or later and the server uses UTF-8 character encoding
If the server specifies the UTF16 character set, UTF-16BE is used to transfer data with the server. If the server does not specify the UTF16 character set, the encoder provided by JVM is used to convert character codes to UTF-8.