Re: Knowing the length(convert(username using windows_1251_to_utf8))

From: "Alexander Farber" <alexander(dot)farber(at)gmail(dot)com>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: Knowing the length(convert(username using windows_1251_to_utf8))
Date: 2007-01-11 11:37:32
Message-ID: 943abd910701110337j4106cd6bt25a13ea9dec9a1b7@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hi Martijn,

On 1/11/07, Martijn van Oosterhout <kleptog(at)svana(dot)org> wrote:
> If you need the string in UTF-8, why not just set the "client_encoding"
> to "utf8" and then the server will only send you strings in utf8, not
> conversion necessary.

actually you are right, because I need all my data in UTF8 anyway
(for a web flash client). So I've followed your advice and added:

PQsetClientEncoding(conn, "UTF8")

and now my program works same, but without that convert().

> > Is there please a way to know the length of the utf8 data?
> > (I'm using a fixed char array in my C program)
>
> UTF-8 always variable length, I think up to 4 bytes per character.
> Maybe you should n't be using a fixed-length array?

Ok I'll go for the 4 times bigger fixed array for now,
because I'd like to keep my webchat-like app quick.

> In your next email you ask:
> > Can I still be sure that the data returned in the
> > convert(username using windows_1251_to_utf8)
> > column will be 0-terminated or should I fetch
> > the data length using PQgetlength and maintain
> > that value in my C-program?
>
> In the client end (as long you're not doing binary transfers) the
> strings are always null terminated.

May I ask you an off-topic question? I've read several
docs on Unicode, but they are difficult to understand.

Do you think that an UTF8 string will ever have a 0 byte
inside of it? Or is it safe to continue using strlen/strlcpy/strcmp
on the UTF8 values I'll be fetching from my database?

Regards
Alex

PS: Using postgresql-server-8.1.4 on OpenBSD 4.0-stable

--
http://preferans.de

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Rafal Pietrak 2007-01-11 12:01:24 Re: TRIGGER BEFORE INSERT
Previous Message Richard Huxton 2007-01-11 11:34:06 Re: Optimize expresiions.