[omniORB] wstring handling in omniORB4

Mike Mascari mascarm@mascari.com
Fri Jun 7 01:47:01 2002


Thomas Amsler wrote:
> 
> Part of the application I am writing has a client/server chat module.
> All the chat messages are logged in a PostgreSQL DB.  The chat messages
> are in UNICODE, wstrings.  I am having problems with  handling the
> wstring holding the chat message during the process where the server
> should insert the chat message into the DB.  In the non UNICODE version,
> I just composed the DB insertion string and everything worked fine. In
> the UNICODE version, I cannot just compose the query string because I
> would have to compose a string consisting of char*s and CORBA:WChar*s. I
> can only pass query strings of type char* to the DB module. So the
> question is, how can I convert the data from a CORBA::WChar* string in
> to a regular char* string so that I can form a DB query string.

I *believe*, without testing myself you need to:

1. Ensure the PostgreSQL server was built with --enable-multibyte

pg_config --configure 

should verify this.

2. Ensure the database was created with UTF-8 encoding:

Example: createdb -E UNICODE omniORBdb

psql -l should verify this.

3. Ensure PostgreSQL knows the client will be sending it UTF-8
characters by one of the following methods:

A. Using the libpq function PQsetClientEndcoding():

Example: PQsetClientEncoding(myconnection, "UNICODE");

B. Sending the command SET CLIENT_ENCODING to the database
C. Setting the environmental variable PGCLIENTENCODING

See:

http://www.postgresql.org/idocs/index.php?multibyte.html

for details.

4. Set the locale so the C library's wcstombcs() will generate the
correct string:

Example: result = setlocale(LC_CTYPE, "en_US.UTF-8");

result should not be NULL. Otherwise UTF-8 support is not installed.

5. Call wcstombs() to convert the Unicode wide string to multibyte
UTF-8. Use that multibyte string when building your INSERT statement.

6. Call mbstowcs() when reading text data from the database. This is
probably working for you now only because you haven't been able to
successfully insert a non-ASCII character sequence into the database.

Again, I *believe* that should do it for you. Hope that helps,

Mike Mascari
mascarm@mascari.com