Обсуждение: Multibyte characters over the frontend/backend protocol

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

Multibyte characters over the frontend/backend protocol

От
Bruce Badger
Дата:
I am trying to add multi-byte character support to the Smalltalk 
PostgreSQL driver, and I would really apreciate a bit of help in 
inderstanding the form in which I need to send things to the backend.

I create a database using: "create database multibytetest with encoding 
= ''KOI8'';"

I can see that it has been created OK using "psql -l"; I see: " 
multibytetest | bbadger  | KOI8"

I create a table using: "create table test(string VARCHAR(3));"

Now, here's where I don't know what to do.  I want to insert into the 
new table using something like:   "insert into test values ("xyz");"
... but where "xyz" is really the KOI8 charaters  0x0422 0x0423 and 0x0416

The question is, what bytes should be sent in the String data type of 
the Query message I send to the back end?

If I make the whole string multi-byte, I get a sytax error at or near "i".

Pointers to documentation or functions in existing code would be much 
apreciated.  Thanks.



Re: Multibyte characters over the frontend/backend

От
Peter Eisentraut
Дата:
Bruce Badger writes:

> Now, here's where I don't know what to do.  I want to insert into the
> new table using something like:
>     "insert into test values ("xyz");"
> ... but where "xyz" is really the KOI8 charaters  0x0422 0x0423 and 0x0416

(I assume those are the equivalent Unicode codepoints.  KOI8 is a
single-byte encoding.)

> The question is, what bytes should be sent in the String data type of
> the Query message I send to the back end?

Whatever the string looks like when encoded using KOI8.  There is no magic
here.

> If I make the whole string multi-byte, I get a sytax error at or near "i".

That means you're probably not sending KOI8.  Also be sure to set the
client encoding to KOI8 as well.  (Unfortunately, this aspect is not
documented in the protocol documentation.  Check how libpq handles the
PGCLIENTENCODING environment variable.)

-- 
Peter Eisentraut   peter_e@gmx.net