DB2 10.5 for Linux, UNIX, and Windows

WCHARTYPE precompiler option for graphic data in C and C++ embedded SQL applications

You can use the WCHARTYPE precompiler option to specify whether you want to use multibyte format or wide-character format for your graphic data.
There are two possible values for the WCHARTYPE option:
CONVERT
If you select the WCHARTYPE CONVERT option in Linux or UNIX operating systems, character codes are converted between the graphic host variable and the database manager. For graphic input host variables, the character code is converted from wide-character format to multibyte DBCS character format with the ANSI C function wcstombs() before the data is sent to the database manager. For graphic output host variables, the character code is converted from multibyte DBCS character format to wide-character format with the ANSI C function mbstowcs() before the data received from the database manager is stored in the host variable.

For Windows operating systems, if a conversion failure is encountered for graphic host variables, user can set the SkipLocalCPConversionForWcharConvert keyword to ON in the IBM® data server driver configuration file (db2dsdriver.cfg) to avoid the failure.

The advantage to using the WCHARTYPE CONVERT option is that it allows your application to use the ANSI C mechanisms for dealing with wide-character strings (L-literals, 'wc' string functions, and others) without having to explicitly convert the data to multibyte format before data is sent to the database manager. The disadvantage is that the implicit conversion can have an impact on the performance of your application at run time, and it can increase memory requirements.

If you select the WCHARTYPE CONVERT option, declare all graphic host variables with wchar_t instead of sqldbchar.

If you want the WCHARTYPE CONVERT option behavior, but your application does not need to be precompiled (for example, a CLI application), then define the C preprocessor macro SQL_WCHART_CONVERT at compile time. This ensures that certain definitions in the DB2® header files use the data type wchar_t instead of sqldbchar.

NOCONVERT (default)
If you choose the WCHARTYPE NOCONVERT option, or do not specify any WCHARTYPE option, no implicit character code conversion occurs between the application and the database manager. Data in a graphic host variable is sent to and received from the database manager as unaltered DBCS characters. This has the advantage of improved performance, but the disadvantage that your application must either refrain from using wide-character data in wchar_t host variables, or must explicitly call the wcstombs() and mbstowcs() functions to convert the data to and from multibyte format when interfacing with the database manager.

If you select the WCHARTYPE NOCONVERT option, declare all graphic host variables with the sqldbchar type for maximum portability to other DB2 client/server environments.

You must consider the guidelines include in the following list:
Note:
  1. For DB2 for Windows operating systems, the WCHARTYPE CONVERT option is supported for applications that are compiled with the Microsoft Visual C++ compiler. However, do not use the CONVERT option with this compiler if your application inserts data into a DB2 database in a code page that is different from the database code page. DB2 server normally converts the code page in this situation; however, the Microsoft C runtime environment does not handle substitution characters for certain double byte character and it can result in run time conversion errors.
  2. If you precompile C applications with the WCHARTYPE CONVERT option, DB2 validates the applications' graphic data on both input and output as the data is passed through the conversion functions. If you do not use the CONVERT option, no conversion of graphic data, and hence no validation occurs. In an environment with mixed CONVERT and NOCONVERT applications, you can encounter errors if invalid graphic data is inserted by a NOCONVERT application and then fetched by a CONVERT application.