From: Benjamin Riefenstahl <Benjamin.Riefenstahl@epost.de>
To: Lucas Sultanum <lucas.sultanum@gcf.com.br>
Cc: pgsql-odbc@postgresql.org
Subject: Re: 22021: invalid byte sequence for encoding \"UNICODE\":
Date: Sun, 31 Oct 2004 15:18:04 +0100
Message-ID: <m3lldnhsyr.fsf@seneca.benny.turtle-trading.net> (raw)
In-Reply-To: <003501c4bc66$156b82f0$0101a8c0@gcfsistemas>
References: <003501c4bc66$156b82f0$0101a8c0@gcfsistemas>
Hi Lucas,
"Lucas Sultanum" writes:
> When I execute the following command (insert into a_cadclias values
> ('6542','65465','amaro','ámaro')) on pgAdmin III Query it works
> pretty well, but when I try to do the same through a C# App
> connecting to the database through an ODBC driver I get the
> following error:
>
> "ERROR: 22021: invalid byte sequence for encoding \"UNICODE\": 0xe16d61"
>
> I know that it has something to do with the word ámaro because when
> I take the letter á off and replace it with the letter a it works
> fine.
A user-level application like pgAdmin does (or should do) automatic
handling of encodings. OTOH lots of programming languages don't
handle encodings automatically, the programmer is responsible there.
I don't know C#, but in C, C++ and Java you can not use non-ASCII
characters like 'á' literally without either some amount of luck or
doing a conversion before saving your file and before compiling the
code.
Your choices are
a) avoid non-ASCII in source code (the preferred choice)
b) make sure that all the encodings match (in the long run this only
works with lots of luck)
c) hardcode byte values (this only removes one of several failure
points in comparison to b))
d) use c) and additionally make sure that the encodings used in
those byte values is matched to the encodings used in the target
system (the database in this case) and in all transition systems
(the database drivers in this case)
Option c) works out to using '\xC3\xA1' instead of a literal 'á' (in
the UTF-8 encoding). Option d) with PostgreSQL means that in addition
you issue the command
SET client_encoding TO UNICODE;
once for each database connection to instruct the driver to expect
UTF-8.
You can of course use some other encoding like e.g. Latin-1, if you
prefer that. See the PostgreSQL documentation for your choices.
benny
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-odbc@postgresql.org
Cc: Benjamin.Riefenstahl@epost.de, lucas.sultanum@gcf.com.br
Subject: Re: 22021: invalid byte sequence for encoding \"UNICODE\":
In-Reply-To: <m3lldnhsyr.fsf@seneca.benny.turtle-trading.net>
References: <003501c4bc66$156b82f0$0101a8c0@gcfsistemas> <m3lldnhsyr.fsf@seneca.benny.turtle-trading.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox