Skip site navigation (1) Skip section navigation (2)

Re: Please help - libpq API

From: Alvaro Herrera <alvherre(at)alvh(dot)no-ip(dot)org>
To: "Pradeepkumar, Pyatalo (IE10)" <Pradeepkumar(dot)Pyatalo(at)honeywell(dot)com>
Cc: pgsql-admin(at)postgresql(dot)org, pgsql-novice(at)postgresql(dot)org
Subject: Re: Please help - libpq API
Date: 2005-09-08 13:25:44
Message-ID: 20050908132544.GC12971@surnet.cl (view raw or flat)
Thread:
Lists: pgsql-adminpgsql-novice
On Wed, Sep 07, 2005 at 11:40:57PM -0700, Pradeepkumar, Pyatalo (IE10) wrote:

> I have already posted my query regarding libpq functions and wide character
> support. Pls somebody help me. I am using libpq API functions in my C code
> to do operations on the database. But the problem I m facing is API
> functions like PQexec() etc....accept only char * .... but as part of
> localization, the queries I want to executed contain chinese characters
> which are multibytes. So the queries I want to execute are in wchar_t *
> format and PQ exec() accepts only char *. Is there any alternate way to
> execute queries having wide characters. 

I think you could be using PQexecParams() and passing your wide-char
strings as binary parameters somehow.  I don't really know if this will
work or not, but it may give you an idea.  But note below:

> Even if somehow if I convert wchar_t *  to char * and provide it to
> Postgres, how will it differentiate between chinese characters and normal
> characters ??

Please note that any string you pass from the client will be interpreted
using the client_encoding setting.  So maybe what you have to do is just
set client_encoding to the encoding that the strings are encoded in.  If
you choose the wrong client_encoding, the server may recode the
characters inappropiately, or not at all, and thus insert wrong data.

Please see the documentation.

-- 
Alvaro Herrera -- Valdivia, Chile         Architect, www.EnterpriseDB.com
"When the proper man does nothing (wu-wei),
his thought is felt ten thousand miles." (Lao Tse)

In response to

Responses

pgsql-novice by date

Next:From: Chris BrowneDate: 2005-09-08 15:01:01
Subject: Re: Execute external program
Previous:From: Guido BarosioDate: 2005-09-08 10:22:52
Subject: Re: Please help - libpq API

pgsql-admin by date

Next:From: Alvaro HerreraDate: 2005-09-08 13:38:17
Subject: Re: pg_dump error... Follow up
Previous:From: Michael FuhrDate: 2005-09-08 12:42:48
Subject: Re: Relationship beween sequences (serial) and tables

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group