INFORMIX
Informix Guide to GLS Functionality
Chapter 7: General SQL API Features
Home Contents Index Master Index New Book

Avoiding Partial Characters

When you use a locale that supports a multibyte code set, make sure that you define buffers large enough to avoid the generation of partial characters. Possible areas for consideration include:

For more detailed examples of partial characters, see "Partial Characters in Column Substrings".

Copying Character Data

When you copy data, you must ensure that the buffers are of adequate size to hold the data. If the destination buffer is not large enough for the multibyte data in the source buffer, the data might be truncated during the copy. For example, the following ESQL/C code fragment copies the multibyte data A1A2A3B1B2B3 from buf1 to buf2:

Because buf2 is not large enough to hold the multibyte string, the copy truncates the string to A1A2A3B1B2. To prevent this situation, ensure that the multibyte string fits into a buffer before the ESQL/C program performs the copy.

Using Code-Set Conversion

If you have a character buffer to hold character data from a database, you must ensure that this buffer is large enough to accommodate any expansion that might occur if the application uses code-set conversion. (For more information on code-set conversion, see "Performing Code-Set Conversion".)

If the client and database locales are different (and convertible), the application might need to expand this value. For example, if the fname column is defined as CHAR(8), the following ESQL/C code fragment selects an 8-byte character value into the 10-byte buf1 host variable:

You might expect that a 10-byte buffer would be adequate to hold an 8-byte character value from the database. However, if the client application expands this value to 12 bytes, the value no longer fits in the buf1 buffer. The fname value would be truncated to fit into buf1, possibly creating partial characters if fname contains multibyte characters. (For more information on partial characters, see "Partial Characters in Column Substrings".)

To avoid this situation, make sure that you define buffers to handle the maximum character-expansion possible, 4 bytes, in the conversion between your client and database code sets.




Informix Guide to GLS Functionality, version 9.1
Copyright © 1998, Informix Software, Inc. All rights reserved.