pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields
17+ messages / 5 participants
[nested] [flat]

* Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields
@ 2006-03-30 19:41 Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-30 21:36 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Bart Samwel <bart@samwel.tk>
  0 siblings, 2 replies; 17+ messages in thread

From: Johann Zuschlag @ 2006-03-30 19:41 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; +Cc: Hiroshi Inoue <inoue@tpf.co.jp>; pgsql-odbc

Dave Page schrieb:
> If 'ö' is 'ö', then isn't the query above mixing single and a multibyte encoding? Ie. It should all be single byte - e.g.
>
> select name from kunde where name >= 'ö' order by name asc;
>
> Or all multibyte (displayed byte by byte) whatever that results in:
>
> s*e*l*e*c*t* *n*a*m*e* *f*r*o*m* *k*u*n*d*e* *w*h*e*r*e* *n*a*m*e* *>*=* *'*ö'*;*
>
> Of course, we all know how well I grok encoding issues :-)
>   
Hi Dave,

I can understand you. This encoding issues drive me also crazy some 
times. :-)

The problem with UTF-8 is that all ASCII characters are represented by 
one byte and all non ASCII characters, e.g. German Umlauts, are 
represented by two bytes. That's why UTF-8 is called a "variable-length 
multibyte encoding". In a pure Unicode world, e.g. U+xxxx with two 
bytes, every character is represented by two bytes (fixed-length 
multibyte encoding). So Unicode is not equal to UTF-8, even though the 
PostgreSQL documentation is stating that.

If you like, see: http://www.utf8-chartable.de/ or some explanation at 
http://czyborra.com/utf/

Windows XP supports ANSI, UTF-8, Unicode and Unicode Big Endian. 
Unfortunately (or fortunately?) Windows seems to use UTF-8 for European 
languages. Hiroshi can you explain that? I guess the Japanese edition of 
Windows XP is using pure 2 byte Unicode.

I can't say anything about psql. But the new  psqlodbc driver 7.03.26X 
seems to handle that situation very well.

So I suppose the test was valid to a certain extend, since the 
characters are handled in this mixed way in Win XP. I still have some 
funny behaviour with Unicode in psql (even after setting LC_COLLATE 
correctly :-) ).

For my production machines I will anyway use ISO-8859-1 (or 
ISO-8859-15). Then the driver will convert all characters to single byte 
avoiding all kind of problems.

But feel free to ask me for tests... ;-)

Regards,
Johann




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
@ 2006-03-30 21:35 ` Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  1 sibling, 1 reply; 17+ messages in thread

From: Hiroshi Inoue @ 2006-03-30 21:35 UTC (permalink / raw)
  To: Johann Zuschlag <zuschlag2@online.de>; +Cc: Dave Page <dpage@vale-housing.co.uk>; pgsql-odbc

Johann Zuschlag wrote:

> Dave Page schrieb:
>
>> If 'ö' is 'ö', then isn't the query above mixing single and a 
>> multibyte encoding? Ie. It should all be single byte - e.g.
>>
>> select name from kunde where name >= 'ö' order by name asc;
>>
>> Or all multibyte (displayed byte by byte) whatever that results in:
>>
>> s*e*l*e*c*t* *n*a*m*e* *f*r*o*m* *k*u*n*d*e* *w*h*e*r*e* *n*a*m*e* 
>> *>*=* *'*ö'*;*
>>
>> Of course, we all know how well I grok encoding issues :-)
>>   
>
> Hi Dave,
>
> I can understand you. This encoding issues drive me also crazy some 
> times. :-)
>
> The problem with UTF-8 is that all ASCII characters are represented by 
> one byte and all non ASCII characters, e.g. German Umlauts, are 
> represented by two bytes. That's why UTF-8 is called a 
> "variable-length multibyte encoding". In a pure Unicode world, e.g. 
> U+xxxx with two bytes, every character is represented by two bytes 
> (fixed-length multibyte encoding). So Unicode is not equal to UTF-8, 
> even though the PostgreSQL documentation is stating that.
>
> If you like, see: http://www.utf8-chartable.de/ or some explanation at 
> http://czyborra.com/utf/
>
> Windows XP supports ANSI, UTF-8, Unicode and Unicode Big Endian. 
> Unfortunately (or fortunately?) Windows seems to use UTF-8 for 
> European languages. Hiroshi can you explain that? I guess the Japanese 
> edition of Windows XP is using pure 2 byte Unicode.


Unicode ODBC drivers handle UCS-2 not UTF-8 even in European environemt. 
Unfortunately PostgreSQL doesn't handle UCS-2
directly(because it could contain NULL bytes in the string), the unicode 
driver sets the client_encoding to UTF-8 automatically and
converts from UCS-2 data to UTF-8 data which  the PostgreSQL  backend 
can understands when sending  queries. So what you
can see in the backend log  is UTF-8. Then the backend converts from 
UTF-8 data to the server encoding data. After all,  the locale
(especially LC_COLLATE) setting you need is the one which matches the 
backend encoding.

>
> I can't say anything about psql. But the new  psqlodbc driver 7.03.26X 
> seems to handle that situation very well.
>
> So I suppose the test was valid to a certain extend, 


Yes thanks. I can't test the LATINxx encoding by myself.

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
@ 2006-03-31 16:51   ` Johann Zuschlag <zuschlag2@online.de>
  2006-03-31 16:58     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  2006-03-31 18:47     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
  2006-03-31 19:02     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
  2006-03-31 19:12     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
  0 siblings, 4 replies; 17+ messages in thread

From: Johann Zuschlag @ 2006-03-31 16:51 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; Dave Page <dpage@vale-housing.co.uk>; pgsql-odbc

Hiroshi Inoue schrieb:
>
> Unicode ODBC drivers handle UCS-2 not UTF-8 even in European 
> environemt. Unfortunately PostgreSQL doesn't handle UCS-2
> directly(because it could contain NULL bytes in the string), the 
> unicode driver sets the client_encoding to UTF-8 automatically and
> converts from UCS-2 data to UTF-8 data which  the PostgreSQL  backend 
> can understands when sending  queries. So what you
> can see in the backend log  is UTF-8. Then the backend converts from 
> UTF-8 data to the server encoding data. After all,  the locale
> (especially LC_COLLATE) setting you need is the one which matches the 
> backend encoding.
>
Hmm..., so Windows  XP uses UCS-2 or do be more correct (like Bart 
mentioned) UTF-16 (which is nearly the same, except for the surrogates). 
That is converted to UTF-8, sent to the backend and then converted to 
the proper locale and stored. I've read about the problems with the NULL 
bytes on Unix machines.

Let's have two examples:
1.
backend-1 = ISO8859-1
backend-2 = UTF-8

'A' = U+0041 (does windows use big-endian?)

Win UCS-2: U+0041
ODBC UTF-8: U+41
backend-1 stores = 0x41
backend-2 stores = U+41

2.
'Ä' = U+00C4 (german A-Umlaut)

Win UCS-2: U+00C4
ODBC UTF-8: U+C384
backend-1 stores = 0xC4
backend-2 stores = U+C384

Did I get that right? So I have to be really careful when testing.

Regards,
Johann




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
@ 2006-03-31 16:58     ` Johann Zuschlag <zuschlag2@online.de>
  2006-04-01 01:35       ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Hiroshi Inoue <inoue@tpf.co.jp>
  3 siblings, 1 reply; 17+ messages in thread

From: Johann Zuschlag @ 2006-03-31 16:58 UTC (permalink / raw)
  To: ; +Cc: Hiroshi Inoue <inoue@tpf.co.jp>; Dave Page <dpage@vale-housing.co.uk>; pgsql-odbc

Johann Zuschlag schrieb:
> Let's have two examples:
> 1.
> backend-1 = ISO8859-1
> backend-2 = UTF-8
>
> 'A' = U+0041 (does windows use big-endian?)
>
> Win UCS-2: U+0041
> ODBC UTF-8: U+41
> backend-1 stores = 0x41
> backend-2 stores = U+41
>
> 2.
> 'Ä' = U+00C4 (german A-Umlaut)
>
> Win UCS-2: U+00C4
> ODBC UTF-8: U+C384
> backend-1 stores = 0xC4
> backend-2 stores = U+C384
>
> Did I get that right? So I have to be really careful when testing.
>
No, again wrong. Or is it more like this:

1.
a) locale = ISO8859-1
    backend-1 = LATIN1

b) locale = UTF-8
    backend-2 = Unicode

'A' = U+0041 (does windows use big-endian?)

Win UCS-2: U+0041
ODBC UTF-8: U+41
backend-1 stores = U+41
backend-2 stores = U+0041

2.
'Ä' = U+00C4 (german A-Umlaut)

Win UCS-2: U+00C4
ODBC UTF-8: U+C384
backend-1 stores = 0xC4
backend-2 stores = U+00C4


Did I get that right?

Regards,
Johann




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  2006-03-31 16:58     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
@ 2006-04-01 01:35       ` Hiroshi Inoue <inoue@tpf.co.jp>
  2006-04-03 09:17         ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  0 siblings, 1 reply; 17+ messages in thread

From: Hiroshi Inoue @ 2006-04-01 01:35 UTC (permalink / raw)
  To: Johann Zuschlag <zuschlag2@online.de>; +Cc: Dave Page <dpage@vale-housing.co.uk>; pgsql-odbc

Johann Zuschlag wrote:
> Johann Zuschlag schrieb:
> 
>>
> No, again wrong. Or is it more like this:
> 
> 1.
> a) locale = ISO8859-1
>    backend-1 = LATIN1
> 
> b) locale = UTF-8
>    backend-2 = Unicode

What do you mean by the Unicode and are you really setting b)
as above ?

First note that in PostgreSQL the encoding has nothing to do
with the locale setting. Though PostgreSQL manages the encoding
settings by itself, as for the locale setting it completely relies
on the OS environment. There exists an essential flaw from the first.
Anyway you can change the encoding as you like per database at
createdb time but the locale setting LC_COLLATE and LC_CTYPE are
fixed at initdb time.

regards,
Hiroshi Inoue



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  2006-03-31 16:58     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  2006-04-01 01:35       ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Hiroshi Inoue <inoue@tpf.co.jp>
@ 2006-04-03 09:17         ` Johann Zuschlag <zuschlag2@online.de>
  2006-04-04 14:54           ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 1 reply; 17+ messages in thread

From: Johann Zuschlag @ 2006-04-03 09:17 UTC (permalink / raw)
  To: Hiroshi Inoue <inoue@tpf.co.jp>; +Cc: Dave Page <dpage@vale-housing.co.uk>; pgsql-odbc

Hiroshi Inoue schrieb:
> Johann Zuschlag wrote:
>> Johann Zuschlag schrieb:
>>
>>>
>> No, again wrong. Or is it more like this:
>>
>> 1.
>> a) locale = ISO8859-1
>>    backend-1 = LATIN1
>>
>> b) locale = UTF-8
>>    backend-2 = Unicode
>
> What do you mean by the Unicode and are you really setting b)
> as above ?
>
Oh, typo! On my system (Debian Sarge) it is in fact:

b) locale = de_DE.UTF-8
   backend-2 = Unicode

Regards,
Johann




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  2006-03-31 16:58     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  2006-04-01 01:35       ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Hiroshi Inoue <inoue@tpf.co.jp>
  2006-04-03 09:17         ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
@ 2006-04-04 14:54           ` Hiroshi Inoue <inoue@tpf.co.jp>
  0 siblings, 0 replies; 17+ messages in thread

From: Hiroshi Inoue @ 2006-04-04 14:54 UTC (permalink / raw)
  To: Johann Zuschlag <zuschlag2@online.de>; +Cc: Dave Page <dpage@vale-housing.co.uk>; pgsql-odbc

Johann Zuschlag wrote:

> Hiroshi Inoue schrieb:
>
>> Johann Zuschlag wrote:
>>
>>> Johann Zuschlag schrieb:
>>>
>>>>
>>> No, again wrong. Or is it more like this:
>>>
>>> 1.
>>> a) locale = ISO8859-1
>>>    backend-1 = LATIN1
>>>
>>> b) locale = UTF-8
>>>    backend-2 = Unicode
>>
>>
>> What do you mean by the Unicode and are you really setting b)
>> as above ?
>>
> Oh, typo! On my system (Debian Sarge) it is in fact:
>
> b) locale = de_DE.UTF-8
>   backend-2 = Unicode


What's the result of
    show server_encoding
?

regards,
Hiroshi Inoue




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
@ 2006-03-31 18:47     ` Marc Herbert <Marc.Herbert@continuent.com>
  3 siblings, 0 replies; 17+ messages in thread

From: Marc Herbert @ 2006-03-31 18:47 UTC (permalink / raw)
  To: pgsql-odbc

Johann Zuschlag <zuschlag2@online.de> writes:

> 'A' = U+0041 (does windows use big-endian?)

Argh, please do not make it even more complex than it needs to be!

Endianness is by chance an _independent_ issue. You just care about it
at the low-low level when dealing with files or network sockets, but
then it's over and you never want to hear about it anymore at a higher
level.

So U+0041 is an integer whose value is:

    zero thousand zero hundred forty one 

and this is always true, whatever is the byte ordering used by the
processor. You don't need to know more than this, even when converting
to UTF-8 or anything else.






^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
@ 2006-03-31 19:02     ` Marc Herbert <Marc.Herbert@continuent.com>
  3 siblings, 0 replies; 17+ messages in thread

From: Marc Herbert @ 2006-03-31 19:02 UTC (permalink / raw)
  To: pgsql-odbc

Johann Zuschlag <zuschlag2@online.de> writes:

> Hmm..., so Windows  XP uses UCS-2 or do be more correct (like Bart
> mentioned) UTF-16 (which is nearly the same, except for the
> surrogates). 

It's nearly the same... but that makes a huge difference.

The reason why you use fixed-character length encoding in memory is
speed. This saves you a lot of time when computing string lengths,
look for some characters (isalnum(),...), collating etc.

If don't care about all this speed then you better stay in a
variable-length encoding like UTF-8 which saves you A LOT of space,
especially with small occidental alphabets.

I think that by moving from UCS-2 to UTF-16 you lose on BOTH sides
[insert some missing benchmarks here]

And you can be sure that it brings a lot of bugs: one bug every
time some string code has been "forgotten" and not updated, still
assuming UCS-2.

Anyway those bugs are only for far-away and unknown countries out of
the BMP so who cares? :-/

So it really looks like a poor compatibility hack to me (java does it
too).







^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
@ 2006-03-31 19:12     ` Marc Herbert <Marc.Herbert@continuent.com>
  2006-04-01 01:26       ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Bart Samwel <bart@samwel.tk>
  3 siblings, 1 reply; 17+ messages in thread

From: Marc Herbert @ 2006-03-31 19:12 UTC (permalink / raw)
  To: pgsql-odbc

Johann Zuschlag <zuschlag2@online.de> writes:

> I've read about the problems with the NULL bytes on Unix machines.

This problem is not related to Unix at all but to the programming
language used. Most standard C functions use the zero byte convention
as a string terminator, so it becomes a forbidden character in C.

On the other hand String objects in C++ and Java use a separate length
field, and having NULLs inside a string is a no brainer there.

The ODBC API has been designed for C and Cobol. Cobol does not forbid
zero as a character either. When browsing the ODBC spec you'll notice
it carefully caters for the two ways.


Guess which programming language is used PostgreSQL.


I suspect unicode does not care at all about this. After all unicode
is just about characters not about strings.






^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  2006-03-31 19:12     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
@ 2006-04-01 01:26       ` Bart Samwel <bart@samwel.tk>
  2006-04-03 08:55         ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
  0 siblings, 1 reply; 17+ messages in thread

From: Bart Samwel @ 2006-04-01 01:26 UTC (permalink / raw)
  To: Marc Herbert <Marc.Herbert@continuent.com>; +Cc: pgsql-odbc

Marc Herbert wrote:
> Johann Zuschlag <zuschlag2@online.de> writes:
> 
>> I've read about the problems with the NULL bytes on Unix machines.
> 
> This problem is not related to Unix at all but to the programming
> language used. Most standard C functions use the zero byte convention
> as a string terminator, so it becomes a forbidden character in C.
> 
> On the other hand String objects in C++ and Java use a separate length
> field, and having NULLs inside a string is a no brainer there.
> 
> The ODBC API has been designed for C and Cobol. Cobol does not forbid
> zero as a character either. When browsing the ODBC spec you'll notice
> it carefully caters for the two ways.
> 
> 
> Guess which programming language is used PostgreSQL.

C++ even introduced a special alternative character type "wchar_t" for 
this, just so that people could handle both 8-bit char* and 16-bit 
wchar_t* strings. In wchar_t* strings, 8-bit NULs are not a problem 
because only 16-bit NULs count (and AFAIK the Unicode standard does 
allows this to be interpreted as a NUL aka end-of-string). The downside 
of this solution is that no application actually uses it, and everybody 
is stuck with 8-bit ASCII plus a random local codepage unless special 
support is added. Why didn't they just upgrade chars to 32 bits and be 
done with it... :-/

Cheers,
Bart



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  2006-03-31 19:12     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
  2006-04-01 01:26       ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Bart Samwel <bart@samwel.tk>
@ 2006-04-03 08:55         ` Marc Herbert <Marc.Herbert@continuent.com>
  2006-04-03 09:03           ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Bart Samwel <bart@samwel.tk>
  0 siblings, 1 reply; 17+ messages in thread

From: Marc Herbert @ 2006-04-03 08:55 UTC (permalink / raw)
  To: pgsql-odbc

Bart Samwel <bart@samwel.tk> writes:
>
> C++ even introduced a special alternative character type "wchar_t" for
> this, just so that people could handle both 8-bit char* and 16-bit
> wchar_t* strings. In wchar_t* strings, 8-bit NULs are not a problem
> because only 16-bit NULs count (and AFAIK the Unicode standard does
> allows this to be interpreted as a NUL aka end-of-string). The
> downside of this solution is that no application actually uses it, and
> everybody is stuck with 8-bit ASCII plus a random local codepage
> unless special support is added.

wchar_t is not defined as 16-bits, but as "wide enough to hold any
character of the platform". For instance if the platform uses UCS-4,
then wchar_t is 32 bits wide.

(UTF-16 wchar_t violates this)


I don't clearly see how you want to use a 8-bit NULL to terminate a
(wider) wchar_t array... ?


> Why didn't they just upgrade chars to 32 bits and be done with
> it... :-/

Because "char" was and is still used to store multibyte /
variable-length / encoded characters.





^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
  2006-03-30 21:35 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Hiroshi Inoue <inoue@tpf.co.jp>
  2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
  2006-03-31 19:12     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
  2006-04-01 01:26       ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Bart Samwel <bart@samwel.tk>
  2006-04-03 08:55         ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
@ 2006-04-03 09:03           ` Bart Samwel <bart@samwel.tk>
  0 siblings, 0 replies; 17+ messages in thread

From: Bart Samwel @ 2006-04-03 09:03 UTC (permalink / raw)
  To: Marc Herbert <Marc.Herbert@continuent.com>; +Cc: pgsql-odbc

Marc Herbert wrote:
> Bart Samwel <bart@samwel.tk> writes:
> wchar_t is not defined as 16-bits, but as "wide enough to hold any
> character of the platform". For instance if the platform uses UCS-4,
> then wchar_t is 32 bits wide.
> 
> (UTF-16 wchar_t violates this)

Ahhh, this explains a lot. The same assumption used to be true for char 
until they came up with UTF-8 char. And they couldn't just upgrade char 
because too much code assumed that char was one byte. Then platforms 
started to use UCS-2 wchar_t, then upgraded those to UTF-16 because they 
couldn't just upgrade wchar_t because too much code assumed that wchar_t 
was two bytes. Same pattern. Time to introduce wwchar_t_t. :-)

> I don't clearly see how you want to use a 8-bit NULL to terminate a
> (wider) wchar_t array... ?

This was a backreference to a situation mentioned earlier in the 
discussion, where wchar_t buffers couldn't be "tunneled through" a layer 
that used char*, as the wider wchar_t characters may contain NUL bytes.

Cheers,
Bart



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text
  2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
@ 2006-03-30 21:36 ` Bart Samwel <bart@samwel.tk>
  1 sibling, 0 replies; 17+ messages in thread

From: Bart Samwel @ 2006-03-30 21:36 UTC (permalink / raw)
  To: Johann Zuschlag <zuschlag2@online.de>; +Cc: Dave Page <dpage@vale-housing.co.uk>; Hiroshi Inoue <inoue@tpf.co.jp>; pgsql-odbc

Johann Zuschlag wrote:
> The problem with UTF-8 is that all ASCII characters are represented by 
> one byte and all non ASCII characters, e.g. German Umlauts, are 
> represented by two bytes. That's why UTF-8 is called a "variable-length 
> multibyte encoding". In a pure Unicode world, e.g. U+xxxx with two 
> bytes, every character is represented by two bytes (fixed-length 
> multibyte encoding). So Unicode is not equal to UTF-8, even though the 
> PostgreSQL documentation is stating that.

Well, it's actually even more complicated, because Unicode is actually a 
32-bit character set. There is actually UTF8 (variable-length multibyte, 
8 bits per unit), UTF16 (variable-length multibyte) and UTF32 
(fixed-length multibyte). There is also UCS2 (fixed-length 16-bit), 
which is limited to the 16 bits of the Basic Multilingual Plane, and 
UCS4, which is functionally identical to UTF32. UTF-8 actually supports 
up to 4 bytes per character, so it is more complete than the purely 
16-bit UCS-2. Any of the variable-length encodings, and the 32-bit 
UTF-32 and UCS-4 encodings can represent the whole of the character set. 
A pure Unicode world can use any of those encodings, so it's a tradeoff. 
If you want a direct relationship between the number of characters in a 
string and the number of bytes taken, use a fixed-length encoding. If 
you want to be able to encode everything, use a variable-length encoding 
or a 32-bit encoding. If you want to use little space, use an 8-bit 
encoding. That's it.

 > Windows XP supports ANSI, UTF-8, Unicode and Unicode Big Endian.
 > Unfortunately (or fortunately?) Windows seems to use UTF-8 for European
 > languages. Hiroshi can you explain that? I guess the Japanese edition of
 > Windows XP is using pure 2 byte Unicode.

In fact, the Win32 API is UTF-16 even in European languages(started out 
as UCS-2 but became UTF-16 when Unicode went 32-bit :-) ), but it 
provides an 8-bit compatibility interface. Don't know if te 8-bit 
encoding is UTF-8 or plain 8-bit code pages though.

Reference: http://en.wikipedia.org/wiki/Unicode

Cheers,
Bart



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields
@ 2006-03-30 19:45 Dave Page <dpage@vale-housing.co.uk>
  2006-03-31 09:22 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Marc Herbert <Marc.Herbert@continuent.com>
  0 siblings, 1 reply; 17+ messages in thread

From: Dave Page @ 2006-03-30 19:45 UTC (permalink / raw)
  To: Johann Zuschlag <zuschlag2@online.de>; +Cc: Hiroshi Inoue <inoue@tpf.co.jp>; pgsql-odbc

 

> -----Original Message-----
> From: Johann Zuschlag [mailto:zuschlag2@online.de] 
> Sent: 30 March 2006 20:41
> To: Dave Page
> Cc: Hiroshi Inoue; pgsql-odbc@postgresql.org
> Subject: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields
> 
> Dave Page schrieb:
> > If 'ö' is 'ö', then isn't the query above mixing single 
> and a multibyte encoding? Ie. It should all be single byte - e.g.
> >
> > select name from kunde where name >= 'ö' order by name asc;
> >
> > Or all multibyte (displayed byte by byte) whatever that results in:
> >
> > s*e*l*e*c*t* *n*a*m*e* *f*r*o*m* *k*u*n*d*e* *w*h*e*r*e* *n*a*m*e* 
> > *>*=* *'*ö'*;*
> >
> > Of course, we all know how well I grok encoding issues :-)
> >   
> Hi Dave,
> 
> I can understand you. This encoding issues drive me also 
> crazy some times. :-)
> 
> The problem with UTF-8 is that all ASCII characters are 
> represented by one byte and all non ASCII characters, e.g. 
> German Umlauts, are represented by two bytes. That's why 
> UTF-8 is called a "variable-length multibyte encoding". In a 
> pure Unicode world, e.g. U+xxxx with two bytes, every 
> character is represented by two bytes (fixed-length multibyte 
> encoding). So Unicode is not equal to UTF-8, even though the 
> PostgreSQL documentation is stating that.
> 
> If you like, see: http://www.utf8-chartable.de/ or some 
> explanation at http://czyborra.com/utf/

Ahh, thanks for the explanation.

> Windows XP supports ANSI, UTF-8, Unicode and Unicode Big Endian. 
> Unfortunately (or fortunately?) Windows seems to use UTF-8 
> for European languages. Hiroshi can you explain that? I guess 
> the Japanese edition of Windows XP is using pure 2 byte Unicode.

Ahh, now I do know that Windows does not fully support UTF-8. That's the very reason why it is not supported in PostgreSQL 8.0 on Windows, and in 8.1 and above requires conversion routines that were added to the server by Magnus Hagander to convert to UCS2(?) before doing any sorting etc.

> I can't say anything about psql. But the new  psqlodbc driver 
> 7.03.26X seems to handle that situation very well.
> 
> So I suppose the test was valid to a certain extend, since 
> the characters are handled in this mixed way in Win XP. I 
> still have some funny behaviour with Unicode in psql (even 
> after setting LC_COLLATE correctly :-) ).
> 
> For my production machines I will anyway use ISO-8859-1 (or 
> ISO-8859-15). Then the driver will convert all characters to 
> single byte avoiding all kind of problems.
> 
> But feel free to ask me for tests... ;-)

I'll need to leave that to Hiroshi - we already know we're past my knowledge on the subject :-)

Regards, Dave.



^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields
  2006-03-30 19:45 Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Dave Page <dpage@vale-housing.co.uk>
@ 2006-03-31 09:22 ` Marc Herbert <Marc.Herbert@continuent.com>
  0 siblings, 0 replies; 17+ messages in thread

From: Marc Herbert @ 2006-03-31 09:22 UTC (permalink / raw)
  To: pgsql-odbc

"Dave Page" <dpage@vale-housing.co.uk> writes:

>
>> Windows XP supports ANSI, UTF-8, Unicode and Unicode Big Endian. 
>> Unfortunately (or fortunately?) Windows seems to use UTF-8 
>> for European languages. Hiroshi can you explain that? I guess 
>> the Japanese edition of Windows XP is using pure 2 byte Unicode.

> Ahh, now I do know that Windows does not fully support UTF-8. That's
> the very reason why it is not supported in PostgreSQL 8.0 on
> Windows, and in 8.1 and above requires conversion routines that were
> added to the server by Magnus Hagander to convert to UCS2(?) before
> doing any sorting etc.


Do you mean CP_UTF8 does not exist on some asian releases of Windows?



Thanks in advance.

Cheers,

Marc.




^ permalink  raw  reply  [nested|flat] 17+ messages in thread

* Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields
@ 2006-03-31 09:28 Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 0 replies; 17+ messages in thread

From: Dave Page @ 2006-03-31 09:28 UTC (permalink / raw)
  To: Marc Herbert <Marc.Herbert@continuent.com>; pgsql-odbc

 

> -----Original Message-----
> From: pgsql-odbc-owner@postgresql.org 
> [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Marc Herbert
> Sent: 31 March 2006 10:23
> To: pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Unicode is not UTF-8. was 
> :psqlODBC-Driver Test / text fields
> 
> "Dave Page" <dpage@vale-housing.co.uk> writes:
> 
> >
> >> Windows XP supports ANSI, UTF-8, Unicode and Unicode Big Endian. 
> >> Unfortunately (or fortunately?) Windows seems to use UTF-8 for 
> >> European languages. Hiroshi can you explain that? I guess the 
> >> Japanese edition of Windows XP is using pure 2 byte Unicode.
> 
> > Ahh, now I do know that Windows does not fully support 
> UTF-8. That's 
> > the very reason why it is not supported in PostgreSQL 8.0 
> on Windows, 
> > and in 8.1 and above requires conversion routines that were 
> added to 
> > the server by Magnus Hagander to convert to UCS2(?) before 
> doing any 
> > sorting etc.
> 
> 
> Do you mean CP_UTF8 does not exist on some asian releases of Windows?

I believe the problem is that the code pages exist, but there are no
corresponding NLS files - see the notes here:
http://pginstaller.projects.postgresql.org/faq/FAQ_windows.html#2.6

I don't know that that actually affects us from an ODBC point of view
though - but regardless, the ODBC API uses UCS-2 as Hiroshi reminded us.

Regards, Dave.



^ permalink  raw  reply  [nested|flat] 17+ messages in thread


end of thread, other threads:[~2006-04-04 14:54 UTC | newest]

Thread overview: 17+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2006-03-30 19:41 Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Johann Zuschlag <zuschlag2@online.de>
2006-03-30 21:35 ` Hiroshi Inoue <inoue@tpf.co.jp>
2006-03-31 16:51   ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
2006-03-31 16:58     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
2006-04-01 01:35       ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Hiroshi Inoue <inoue@tpf.co.jp>
2006-04-03 09:17         ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Johann Zuschlag <zuschlag2@online.de>
2006-04-04 14:54           ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Hiroshi Inoue <inoue@tpf.co.jp>
2006-03-31 18:47     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
2006-03-31 19:02     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
2006-03-31 19:12     ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
2006-04-01 01:26       ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Bart Samwel <bart@samwel.tk>
2006-04-03 08:55         ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Marc Herbert <Marc.Herbert@continuent.com>
2006-04-03 09:03           ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Bart Samwel <bart@samwel.tk>
2006-03-30 21:36 ` Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text Bart Samwel <bart@samwel.tk>
2006-03-30 19:45 Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Dave Page <dpage@vale-housing.co.uk>
2006-03-31 09:22 ` Marc Herbert <Marc.Herbert@continuent.com>
2006-03-31 09:28 Re: Unicode is not UTF-8. was :psqlODBC-Driver Test / text fields Dave Page <dpage@vale-housing.co.uk>

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