Обсуждение: Please help - libpq API

Поиск
Список
Период
Сортировка

Please help - libpq API

От
"Pradeepkumar, Pyatalo (IE10)"
Дата:

Hi all,

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.

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 help !!

Regs,
Pradeep

    This e-mail and any attachments thereto, are intended only for use by the addressee(s) named herein and contain Honeywell confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying which amounts to misappropriation of this e-mail and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof."

Re: Please help - libpq API

От
Guido Barosio
Дата:
Hi,

I think that this is the wrong list for your problem. My suggestions:

contact pgsql-hackers or check the lists in the postgresql.org page, you will prolly find one list to suit with this.
or
irc.freenode.net, join #postgresql . Good boys lurking there, you will have to fight, but help will be given if you have good maners and offer a pizza.

Good luck.

G.-

On 9/8/05, Pradeepkumar, Pyatalo (IE10) <Pradeepkumar.Pyatalo@honeywell.com> wrote:

Hi all,

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.

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 help !!

Regs,
Pradeep

    This e-mail and any attachments thereto, are intended only for use by the addressee(s) named herein and contain Honeywell confidential information. If you are not the intended recipient of this e-mail, you are hereby notified that any dissemination, distribution or copying which amounts to misappropriation of this e-mail and any attachments thereto, is strictly prohibited. If you have received this e-mail in error, please immediately notify me and permanently delete the original and any copy of any e-mail and any printout thereof."




--
"Adopting the position that you are smarter than an automatic
optimization algorithm is generally a good way to achieve less
performance, not more" - Tom Lane.

Re: Please help - libpq API

От
Alvaro Herrera
Дата:
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)

Re: Please help - libpq API

От
Tom Lane
Дата:
Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> On Wed, Sep 07, 2005 at 11:40:57PM -0700, Pradeepkumar, Pyatalo (IE10) wrote:
>> 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.

I think his problem is that his data is represented in UCS2 or UCS4
(or some other fixed-width representation) and we don't support those
as client_encoding values AFAIK.  He'll need to do an encoding
conversion to some representation we do support, such as UTF8.

            regards, tom lane

Re: Please help - libpq API

От
"Pradeepkumar, Pyatalo (IE10)"
Дата:
Hi all,

Thanks for all your patience and help. I really appreciate this group as I
have always found someone or the other replying to my questions. For my
problem, I set the client and server encoding to UNICODE. The problem that
libpq functions does not support wide characters still remains. I am
converting the wide character strings to proper UTF-8 format and passing it
to the libpq functions. But I still feel that libpq functions should support
wide character datatypes also.

Regs,
Pradeep

-----Original Message-----
From: Tom Lane [mailto:tgl@sss.pgh.pa.us]
Sent: Thursday, September 08, 2005 10:17 PM
To: Alvaro Herrera
Cc: Pradeepkumar, Pyatalo (IE10); pgsql-admin@postgresql.org;
pgsql-novice@postgresql.org
Subject: Re: [ADMIN] Please help - libpq API

Alvaro Herrera <alvherre@alvh.no-ip.org> writes:
> On Wed, Sep 07, 2005 at 11:40:57PM -0700, Pradeepkumar, Pyatalo (IE10)
wrote:
>> 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.

I think his problem is that his data is represented in UCS2 or UCS4 (or some
other fixed-width representation) and we don't support those as
client_encoding values AFAIK.  He'll need to do an encoding conversion to
some representation we do support, such as UTF8.

            regards, tom lane