pg.ddx.io  pgsql-odbc@postgresql.org mailing list archive  
help / color / mirror / Atom feed
Unicode support
32+ messages / 10 participants
[nested] [flat]

* Unicode support
@ 2002-02-03 20:26  Nhan Ngo Dinh <nngodinh@tiscali.it>
  0 siblings, 1 reply; 32+ messages in thread

From: Nhan Ngo Dinh @ 2002-02-03 20:26 UTC (permalink / raw)
  To: pgsql-odbc

Greetings,

I've been searching for long time for the way to convert a Microsoft SQL 
7.0 database into a database such as MySQL or PostgreSQL. The problem is 
that this database contains tables with both LATIN1 characters (English, 
French) and Arabic characters, so the only way to put all together is to 
use an unicode charset such as UTF-8.

PostgreSQL does support unicode characters (at least the documents say 
that) while MySQL doesn't. I enabled the multibyte support while compiling 
sources on a Linux platform and tried some ways to transfer the original 
database.

First of all, I tried using the PostgreSQL ODBC driver. I've exported the 
database to Microsoft Access to better handle the situation and I've 
installed the PostgreSQL ODBC driver taken from ftp.postgresql.org (version 
7.01.00.09). I've transferred a sample table containing both charsets and 
the result was that Arabic letters were replaced into the target PostgreSQL 
database by "?" characters.

In the psqlodbc_*.log files the Arabic entries were already replaced with 
quotation marks.

Then I tried many other methods, using pgAdmin II, or even trying to 
synchronize the databases with a PHP script that used the freetds library 
(first) or the Sybase library (then) to directly access the MSSQL database. 
The imported Arabic fields were always quotation marks, because the unicode 
support was not fully enabled into both sybase libraries.

The only solution that I've found is to import the database using ODBC in a 
PHP script with PHP on a Windows box, converting nvarchar values (with 
CONVERT in the query) into varbinary, setting the binary visualization to 
hex. So I can parse that string and store unicode strings into the database.

Well, may be there is a better solution directly using the PostgreSQL ODBC 
driver.
Any idea?

Thanks.

Nhan NGO DINH







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

* Re: Unicode support
@ 2002-02-11 17:22  Jean-Michel POURE <jm.poure@freesurf.fr>
  parent: Nhan Ngo Dinh <nngodinh@tiscali.it>
  0 siblings, 1 reply; 32+ messages in thread

From: Jean-Michel POURE @ 2002-02-11 17:22 UTC (permalink / raw)
  To: Nhan Ngo Dinh <nngodinh@tiscali.it>; pgsql-odbc

Le Dimanche 3 Février 2002 21:26, Nhan Ngo Dinh a écrit :
> Any idea?

The only problem is with Arabic, right? Export schema and data separately 
from MS SQL Server.

1) Import the schema file in PostgreSQL directly in Latin1.
2) Translate the data file to UFT-8 under Linux using recode or iconv:
- iconv -f arabic_enconding_name  -t utf-8 filename.txt
- recode arabic_enconding_name..u8 file_name.txt

A good manual can be found here : 
http://www.iro.umontreal.ca/contrib/recode/HTML/recode.html

3) Use pgAdmin2 or pgsql \copy statement to import the file.

Please note that Access2000 and PgAdmin 2 do not support Unicode. This was an 
issue for us at pgAdmin Team and the answer is "there is no unicode support 
although $M claims there is". You have to wait for Windows ZX 2439, which 
will take place in more than 300 years and 134 Windows upgrades. So prepare a 
cryogenic place and wait until UTF-8 is added to Access.

On the converse PHP supports unicode very well. Do not hesitate to write me 
back for further information.

Cheers,
Jean-Michel POURE



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

* Re: Unicode support
@ 2002-02-12 00:45  Hiroshi Inoue <Inoue@tpf.co.jp>
  parent: Jean-Michel POURE <jm.poure@freesurf.fr>
  0 siblings, 1 reply; 32+ messages in thread

From: Hiroshi Inoue @ 2002-02-12 00:45 UTC (permalink / raw)
  To: jm.poure@freesurf.fr; Nhan Ngo Dinh <nngodinh@tiscali.it>; +Cc: pgsql-odbc

Jean-Michel POURE wrote:
> 
> Le Dimanche 3 F$BqW(Brier 2002 21:26, Nhan Ngo Dinh a $BqD(Brit :
> > Any idea?
> 
> 3) Use pgAdmin2 or pgsql \copy statement to import the file.
> 
> Please note that Access2000 and PgAdmin 2 do not support Unicode. This was an
> issue for us at pgAdmin Team and the answer is "there is no unicode support
> although $M claims there is".

If our ODBC driver supports UNICODE (UCS-2 not utf-8)
it would probably be possible for Access2000, PgAdmin
or other VB apps etc to handle UNICODE data via ODBC
(ADO etc) under Windows NT/2000/XP because the OS's
are UNICODE(UCS-2) based. Though it's been on my TODO
list I've had no time to do it unfortunately.

regards,
Hiroshi Inoue



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

* Re: Unicode support
@ 2002-02-12 09:02  Jean-Michel POURE <jm.poure@freesurf.fr>
  parent: Hiroshi Inoue <Inoue@tpf.co.jp>
  0 siblings, 0 replies; 32+ messages in thread

From: Jean-Michel POURE @ 2002-02-12 09:02 UTC (permalink / raw)
  To: Hiroshi Inoue <Inoue@tpf.co.jp>; Nhan Ngo Dinh <nngodinh@tiscali.it>; +Cc: pgsql-odbc

Le Mardi 12 Février 2002 01:45, Hiroshi Inoue a écrit :
> If our ODBC driver supports UNICODE (UCS-2 not utf-8)
> it would probably be possible for Access2000, PgAdmin
> or other VB apps etc to handle UNICODE data via ODBC
> (ADO etc) under Windows NT/2000/XP because the OS's
> are UNICODE(UCS-2) based. Though it's been on my TODO
> list I've had no time to do it unfortunately.

OK, I understand.
Cheers, Jean-Michel POURE



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

* Re: [ODBC] Unicode support
@ 2002-02-18 11:14  Jean-Michel POURE <jm.poure@freesurf.fr>
  3 siblings, 0 replies; 32+ messages in thread

From: Jean-Michel POURE @ 2002-02-18 11:14 UTC (permalink / raw)
  To: pgadmin-hackers@postgresql.org; pgsql-odbc; +Cc: Nhan NGO DINH <n.ngodinh@tin.it>

Le Lundi 18 Février 2002 11:13, Nhan NGO DINH a écrit :
> Well, you said to export data from the SQL server splitted into structure
> and data. How to do that? I really don't have so much experience with
> Microsoft SQL Server...
>
> Then: I've tried to convert with iconv an UNICODE exported table but I
> don't see the expected results.

What is the encoding of your $MS SQL database? If Unicode, no recoding is 
needed.

I recommand you installed pgAdmin2 (http://pgadmi.postgresql.org) and 
followed the following steps:

1) Create a Unicode database.

2) Use the migration wizard to import $MS SQL Schema into PostgreSQL. It will 
handle type conversion from $MS SQL Server <-> PostgreSQL.

Alternatively, you may use $MS SQL Server GUI to export schema. You will need 
to adapt schema types and objects (convert money into float8, sequences, 
etc...). This can be quite difficult in a large schema.

Use pgAdmin2 graphical interface to make sure all objects are imported : 
keys, sequences, etc.. The best way is to run both GUIs at the same time to 
create the missing objects manually.

3) Export the data from SQL Server into a text file using $MS SQL Server GUI. 
Alternatively, you can attach files in Access2K and export them into a text 
file.

Recode the text file using : recode Latin1..u8 file_name.txt (assuming 
Latin1 is the source encoding). If the $MS SQL database is already Unicode, 
no recoding is required and you can use pgAdmin2 during the entire process.

4) Import the resulting data into PostgreSQL using pgAdmin2 or pgsql \Copy 
statement.

Do not hesitate to write me on pgadmin-hackers@postgresql.org for more 
support.

Cheers,
Jean-MIchel POURE



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

* Re: Unicode support
@ 2002-02-19 07:28  Jean-Michel POURE <jm.poure@freesurf.fr>
  3 siblings, 1 reply; 32+ messages in thread

From: Jean-Michel POURE @ 2002-02-19 07:28 UTC (permalink / raw)
  To: pgsql-odbc

Ok, I've tried to follow your steps: be sure I've already installed pgadmin 
II, that's obviously the best way to intercommunicate with postgresql from 
Microsoft platforms.

It was surprising that I've succeeded transferring arabic unicode to 
postgresql, at least it seems to have included multibyte characters. Then 
I've found two problems:

1) When I try to view tables from Access XP, the arabic letters are not 
correctly displayed: I can see only the multibyte to single byte 1:1 
conversion. This is not that important because I don't need to see it in 
Access because the database will be seen through PHP on the web.

2) The most critical problem is that I cannot convert a table with both 
french letters with accents and arabic letters. Pgadmin seems to refuse 
french characters. So I've erased french records (at least records with 
accents) and the database has been transferred.

As far as I can see the unicode text file from Microsoft SQL Server is not 
fully UTF-8 standard, but maybe I'm wrong.

On the postgresql server side there is the message:
ERROR:  Invalid UNICODE character sequence found (0xe974e9)
So E9 74 E9 is "été" ("société" field in the 5th record)

To better understand the situation I send you in attachment the unicode TXT 
file that I'm trying to import and the pgadmin log.

Thx a lot!
Bye.

At 12.14 18/02/2002 +0100, you wrote:
>Le Lundi 18 Février 2002 11:13, Nhan NGO DINH a écrit :
> > Well, you said to export data from the SQL server splitted into structure
> > and data. How to do that? I really don't have so much experience with
> > Microsoft SQL Server...
> >
> > Then: I've tried to convert with iconv an UNICODE exported table but I
> > don't see the expected results.
>
>What is the encoding of your $MS SQL database? If Unicode, no recoding is
>needed.
>
>I recommand you installed pgAdmin2 (http://pgadmi.postgresql.org) and
>followed the following steps:
>
>1) Create a Unicode database.
>
>2) Use the migration wizard to import $MS SQL Schema into PostgreSQL. It will
>handle type conversion from $MS SQL Server <-> PostgreSQL.
>
>Alternatively, you may use $MS SQL Server GUI to export schema. You will need
>to adapt schema types and objects (convert money into float8, sequences,
>etc...). This can be quite difficult in a large schema.
>
>Use pgAdmin2 graphical interface to make sure all objects are imported :
>keys, sequences, etc.. The best way is to run both GUIs at the same time to
>create the missing objects manually.
>
>3) Export the data from SQL Server into a text file using $MS SQL Server GUI.
>Alternatively, you can attach files in Access2K and export them into a text
>file.
>
>Recode the text file using : recode Latin1..u8 file_name.txt (assuming
>Latin1 is the source encoding). If the $MS SQL database is already Unicode,
>no recoding is required and you can use pgAdmin2 during the entire process.
>
>4) Import the resulting data into PostgreSQL using pgAdmin2 or pgsql \Copy
>statement.
>
>Do not hesitate to write me on pgadmin-hackers@postgresql.org for more
>support.
>
>Cheers,
>Jean-MIchel POURE
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: you can get off all lists at once with the unregister command
>     (send "unregister YourEmailAddressHere" to majordomo@postgresql.org)

Attachments:

berytos.txt (text/plain, 1.0K) download 168,"****","fre","","","","","",3 546,"Exposition","fre ","","710/711/712","111/711","1#","##",3 549,"Exposition(diff.langue)","fre","","710/711/712","111/711","1#","##",3 552,"Exposition(multilangue)","fre","","710/711/712","111/711","1#","##",3 544,"Société","fre","","700/701/702","100/700","##","##",3 547,"Personne(diff.langue)","fre","","700/701/702","100/700","##","##",3 550,"Personne(multilangue)","fre","","700/701/702","100/700","#3","#3",3 553,"'3E 'DE$DA","ara","","710/711/712","100/700","##","##",3
pgAdmin II_484.Log (application/octet-stream, 4.3K) download ^ permalink raw reply [nested|flat] 32+ messages in thread

* Re: [ODBC] Unicode support
@ 2002-02-19 07:34  Jean-Michel POURE <jm.poure@freesurf.fr>
  3 siblings, 1 reply; 32+ messages in thread

From: Jean-Michel POURE @ 2002-02-19 07:34 UTC (permalink / raw)
  To: Nhan Ngo Dinh <nngodinh@tiscali.it>; +Cc: pgadmin-hackers@postgresql.org; pgsql-odbc

> 1) When I try to view tables from Access XP, the arabic letters are not
> correctly displayed: I can see only the multibyte to single byte 1:1
> conversion. This is not that important because I don't need to see it in
> Access because the database will be seen through PHP on the web.

The odbc driver does not support UTF-8 yet.

> 2) The most critical problem is that I cannot convert a table with both
> french letters with accents and arabic letters. Pgadmin seems to refuse
> french characters. So I've erased french records (at least records with
> accents) and the database has been transferred.

The French letters are correctly stored in PostgreSQL. The problem comes from 
pgAdmin2 / odbc.

> As far as I can see the unicode text file from Microsoft SQL Server is not
> fully UTF-8 standard, but maybe I'm wrong.
>
> On the postgresql server side there is the message:
> ERROR:  Invalid UNICODE character sequence found (0xe974e9)
> So E9 74 E9 is "été" ("société" field in the 5th record)

Can you test displaying you data in Apache / Php. I tried displaying UTF-8 
data in Windows but never ***ever*** succedeed.

Please give us more details : 
- What is the encoding of you source data
- What is your platform (Win2000, XP),
- Do yo have Access 2K?
- Do you have access to an Apache/PHP platform?

Also, keep in mind pgAdmin2 and the odbc driver are not UTF-8 compliant yet. 
So if you plan to use Windows / odbc / PostgreSQL / UTF-8 it will not work. 
Windows can only be used during migration of UTF-8 data.

I can only help you if the data is to be used on an Apache/php platform.

Cheers,
Jean-Michel POURE



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

* Re: [ODBC] Unicode support
@ 2002-02-19 08:27  Jean-Michel POURE <jm.poure@freesurf.fr>
  3 siblings, 0 replies; 32+ messages in thread

From: Jean-Michel POURE @ 2002-02-19 08:27 UTC (permalink / raw)
  To: Nhan Ngo Dinh <nngodinh@tiscali.it>; +Cc: pgadmin-hackers@postgresql.org; pgsql-odbc

Dear Nhan Dgo,

Please CC pg-odbc and pgadmin lists so that anyone can participate.

> I'm currently running Microsoft SQL Server 2000 on a Windows 2000 Server
> platform, but this is only to read the source database. I don't know how to
> retrieve the source encoding... It should be UNICODE since it stores both
> LATIN1 and arabic chars.

I am not sure. There should be a way to run a select statement to know what 
encoding is used internally. Search the $W website.

> The target platform is Linux with PostgreSQL 7.2 and PHP/Apache of course
> and this shouldn't be a problem for me.

Don't try to view data in the Windows platform, this will not work because 
pgAdmin2 and the odbc driver are not utf-8 compatible.

Make sure to migrate the schema first using pgAdmin2. Then export text and 
convert it using iconv or recode (if not utf-8 yet). Maybe you can try to 
open the text files in Yudit, the multi-byte text editor, which will tell you 
what encoding is used.

Try to write a simple script under PHP. Please note the testing php page 1) 
should be saved in utf-8 format 2) and should carry utf-8 headers to tell the 
browser to switch to utf-8. Be sure your browser has the arabic fonts (go to 
an arabic web site to verify).

Good luck my friend.

Cheers,
Jean-Michel POURE



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

* Re: [ODBC] Unicode support
@ 2002-02-19 09:10  Hiroshi Inoue <Inoue@tpf.co.jp>
  parent: Jean-Michel POURE <jm.poure@freesurf.fr>
  0 siblings, 0 replies; 32+ messages in thread

From: Hiroshi Inoue @ 2002-02-19 09:10 UTC (permalink / raw)
  To: jm.poure@freesurf.fr; Nhan Ngo Dinh <nngodinh@tiscali.it>; +Cc: pgadmin-hackers@postgresql.org; pgsql-odbc

Jean-Michel POURE wrote:
> 
> > 1) When I try to view tables from Access XP, the arabic letters are not
> > correctly displayed: I can see only the multibyte to single byte 1:1
> > conversion. This is not that important because I don't need to see it in
> > Access because the database will be seen through PHP on the web.
> 
> The odbc driver does not support UTF-8 yet.

The odbc driver can support UTF-8.
What it doesn't support is UCS-2.
In most cases Unicode means UCS-2 under Windows.
Note that Unicode in PostgreSQL means UTF-8 and
it couldn't handle UCS-2.

regards,
Hiroshi Inoue



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

* Re: [ODBC] Unicode support
@ 2002-02-21 22:34  Jean-Michel POURE <jm.poure@freesurf.fr>
  parent: Jean-Michel POURE <jm.poure@freesurf.fr>
  0 siblings, 0 replies; 32+ messages in thread

From: Jean-Michel POURE @ 2002-02-21 22:34 UTC (permalink / raw)
  To: pgsql-odbc; +Cc: pgadmin-hackers@postgresql.org

> 1) When I try to view tables from Access XP, the arabic letters are not
> correctly displayed: I can see only the multibyte to single byte 1:1
> conversion. This is not that important because I don't need to see it in
> Access because the database will be seen through PHP on the web.

Dave Page wrote 30.000 lines of code for pgAdmin2... It is getting better 
every day.

Access2K/XP + PostgreSQL support Unicode. You can use them to display both 
French and Arabic. Althought I never tried, I know it is possible.


> 2) The most critical problem is that I cannot convert a table with both
> french letters with accents and arabic letters. Pgadmin seems to refuse
> french characters. So I've erased french records (at least records with
> accents) and the database has been transferred.

pgAdmin2 is not multi-byte safe for various ***serious*** reasons.

It means you cannot view Unicode data in pgAdmin2 grid. On the converse, you 
can manage your database (add tables, views, triggers, etc...)

Cheers,
Jean-Michel



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

* Unicode support
@ 2005-08-30 21:36  Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 3 replies; 32+ messages in thread

From: Dave Page @ 2005-08-30 21:36 UTC (permalink / raw)
  To: Anoop Kumar <anoopk@pervasive-postgres.com>; +Cc: pgsql-odbc

Hi Anoop and anyone else who might be interested,

I've been thinking about how the Unicode support might be improved to
allow the old 07.xx non-unicode style behaviour to work for those that
need it. At them moment, when we connect using on of the wide connect
functions, the CC->unicode flag is set to true. This only affects a few
options, such as pgtype_to_concise_type()'s mapping of PG types to SQL
types.

It seems to me that perhaps we should set CC->unicode = 1, only upon
connection to a Unicode database. Anything else, we leave it set to 0 so
that it always maps varchars etc to ANSI types, and handles other
encodings in single byte or non-unicode multibyte mode (which worked
fine in 07.xx where those encodings where appropriate, such as SJIS in
Japan). This should also help BDE based apps, which further research has
shown me are broken with Unicode columns in SQL Server and Oracle as
well as PostgreSQL (search unicode + BDE on Google Groups for more).

Am I seeing a possible improvement where in fact there isn't one, or
missing some obvious downside?

Regards, Dave.



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

* Re: Unicode support
@ 2005-08-31 01:55  Hiroshi Saito <saito@inetrt.skcapi.co.jp>
  parent: Dave Page <dpage@vale-housing.co.uk>
  2 siblings, 0 replies; 32+ messages in thread

From: Hiroshi Saito @ 2005-08-31 01:55 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; Anoop Kumar <anoopk@pervasive-postgres.com>; +Cc: pgsql-odbc

From: "Dave Page" 

> Hi Anoop and anyone else who might be interested,
> 
> I've been thinking about how the Unicode support might be improved to
> allow the old 07.xx non-unicode style behaviour to work for those that

Yea, I think that a libpq version is very great. However, Legacy environment 
is raising the scream for a rapid change. Then, I think that a multibyte needs 
to be supported.

Regards,
Hiroshi Saito




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

* Re: Unicode support
@ 2005-08-31 05:08  Anoop Kumar <anoopk@pervasive-postgres.com>
  0 siblings, 0 replies; 32+ messages in thread

From: Anoop Kumar @ 2005-08-31 05:08 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; +Cc: pgsql-odbc

Hi Dave,

Checking for the database encoding and calling the functions using the
appropriate flag seems to be fine.

Regards

Anoop

> -----Original Message-----
> From: Dave Page [mailto:dpage@vale-housing.co.uk]
> Sent: Wednesday, August 31, 2005 3:07 AM
> To: Anoop Kumar
> Cc: pgsql-odbc@postgresql.org
> Subject: Unicode support
> 
> Hi Anoop and anyone else who might be interested,
> 
> I've been thinking about how the Unicode support might be improved to
> allow the old 07.xx non-unicode style behaviour to work for those that
> need it. At them moment, when we connect using on of the wide connect
> functions, the CC->unicode flag is set to true. This only affects a
few
> options, such as pgtype_to_concise_type()'s mapping of PG types to SQL
> types.
> 
> It seems to me that perhaps we should set CC->unicode = 1, only upon
> connection to a Unicode database. Anything else, we leave it set to 0
so
> that it always maps varchars etc to ANSI types, and handles other
> encodings in single byte or non-unicode multibyte mode (which worked
> fine in 07.xx where those encodings where appropriate, such as SJIS in
> Japan). This should also help BDE based apps, which further research
has
> shown me are broken with Unicode columns in SQL Server and Oracle as
> well as PostgreSQL (search unicode + BDE on Google Groups for more).
> 
> Am I seeing a possible improvement where in fact there isn't one, or
> missing some obvious downside?
> 
> Regards, Dave.



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

* Re: Unicode support
@ 2005-08-31 07:19  Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 1 reply; 32+ messages in thread

From: Dave Page @ 2005-08-31 07:19 UTC (permalink / raw)
  To: Hiroshi Saito <saito@inetrt.skcapi.co.jp>; Anoop Kumar <anoopk@pervasive-postgres.com>; +Cc: pgsql-odbc

 

> -----Original Message-----
> From: Hiroshi Saito [mailto:saito@inetrt.skcapi.co.jp] 
> Sent: 31 August 2005 02:56
> To: Dave Page; Anoop Kumar
> Cc: pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Unicode support
> 
> From: "Dave Page" 
> 
> > Hi Anoop and anyone else who might be interested,
> > 
> > I've been thinking about how the Unicode support might be 
> improved to
> > allow the old 07.xx non-unicode style behaviour to work for 
> those that
> 
> Yea, I think that a libpq version is very great. However, 
> Legacy environment 
> is raising the scream for a rapid change. Then, I think that 
> a multibyte needs 
> to be supported.

OK, I'll prepare a patch, and because it's an odd problem, a test build
to go with it. Any voluteers to test? It really needs people with a
reproducable encoding error that doesn't existing in 07.xx, or people
using BDE (which barfs bigtime on SQL_C_Wxxx data).

Regards, Dave.



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

* Re: Unicode support
@ 2005-08-31 08:00  Johann Zuschlag <zuschlag2@online.de>
  parent: Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 0 replies; 32+ messages in thread

From: Johann Zuschlag @ 2005-08-31 08:00 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; pgsql-odbc

Dave Page schrieb:

>
>OK, I'll prepare a patch, and because it's an odd problem, a test build
>to go with it. Any voluteers to test? It really needs people with a
>reproducable encoding error that doesn't existing in 07.xx, or people
>using BDE (which barfs bigtime on SQL_C_Wxxx data).
>
>Regards, Dave.
>
>  
>
Hi Dave,

just send it to me (the windows dll). Even though I just switched my 
linux server to UTF-8. :-)
I'll test it with the old enviroment.

Regards,
Johann






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

* Re: Unicode support
@ 2005-08-31 11:31  Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 1 reply; 32+ messages in thread

From: Dave Page @ 2005-08-31 11:31 UTC (permalink / raw)
  To: Hiroshi Saito <saito@inetrt.skcapi.co.jp>; Anoop Kumar <anoopk@pervasive-postgres.com>; +Cc: pgsql-odbc

 

> -----Original Message-----
> From: pgsql-odbc-owner@postgresql.org 
> [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Dave Page
> Sent: 31 August 2005 08:20
> To: Hiroshi Saito; Anoop Kumar
> Cc: pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Unicode support
> 
>  
> OK, I'll prepare a patch, and because it's an odd problem, a 
> test build
> to go with it. Any voluteers to test? It really needs people with a
> reproducable encoding error that doesn't existing in 07.xx, or people
> using BDE (which barfs bigtime on SQL_C_Wxxx data).

OK, patch attached. This works slightly differently than I envisaged,
because simply switching off Unicode isn't that straight forward,
especially if the DM is using the *W functions.

Basically what this does is only offer wide character types if the
database is unicode, and, in that case, sets the client encoding to
unicode. For anything else, it will report non-wide character types as
per the 07 driver, and let the user set their own encoding as required.
From what I can tell of the BDE missing fields problem, this should
almost certainly fix it.

Please look at this carefully - as most of you know, MB/Unicode issues
aren't exactly my strong point!

I'll forward test DLLs to volunteer victims privately.

Regards, Dave.

Attachments:

widetypes.diff (application/octet-stream, 6.9K) download ? Release ? widetypes.diff ? installer/psqlodbc.msi ? installer/psqlodbc.msm ? installer/psqlodbc.wixobj ? installer/psqlodbcm.wixobj ? installer/Thumbs.db Index: connection.c =================================================================== RCS file: /usr/local/cvsroot/psqlodbc/psqlodbc/connection.c,v retrieving revision 1.108 diff -c -r1.108 connection.c *** connection.c 31 Aug 2005 07:31:44 -0000 1.108 --- connection.c 31 Aug 2005 11:28:04 -0000 *************** *** 2686,2691 **** --- 2686,2719 ---- CC_lookup_lo(self); /* a hack to get the oid of our large object oid type */ + /* + * Set/unset the use Unicode internal flag if required. + * If the database is Unicode, then we offer full Unicode support, + * otherwise, fall back to ANSI. + * This doesn't actually enable/disable Unicode support - it just + * turns on or off the SQL_C_Wxxx type mappings. + */ + if (!self->server_encoding) + { + QResultClass *res; + if (res = CC_send_query(self, "select getdatabaseencoding()", NULL, CLEAR_RESULT_ON_ABORT), res) + { + if (QR_get_num_total_tuples(res) > 0) + self->server_encoding = strdup(QR_get_value_backend_row(res, 0, 0)); + QR_Destructor(res); + } + if (strcmp(self->server_encoding, "UNICODE") == 0) + { + self->report_wide_types = 1; + mylog("Server encoding: %s. Wide types enabled.\n", self->server_encoding); + } + else + { + self->report_wide_types = 0; + mylog("Server encoding: %s. Wide types disabled.\n", self->server_encoding); + } + } + /* * Multibyte handling is available ? */ *************** *** 2695,2701 **** if (CC_get_errornumber(self) != 0) return 0; ! if (self->unicode) { if (!self->client_encoding || stricmp(self->client_encoding, "UNICODE")) --- 2723,2729 ---- if (CC_get_errornumber(self) != 0) return 0; ! if (self->unicode && self->report_wide_types) { if (!self->client_encoding || stricmp(self->client_encoding, "UNICODE")) *************** *** 3138,3144 **** CC_set_error(self,CONNECTION_COULD_NOT_ESTABLISH,PQerrorMessage(self->pgconn)); mylog("could not establish connection to the database %s \n",PQerrorMessage(self->pgconn)); PQfinish(self->pgconn); ! self->pgconn = NULL; free(conninfo); return 0; } --- 3166,3172 ---- CC_set_error(self,CONNECTION_COULD_NOT_ESTABLISH,PQerrorMessage(self->pgconn)); mylog("could not establish connection to the database %s \n",PQerrorMessage(self->pgconn)); PQfinish(self->pgconn); ! self->pgconn = NULL; free(conninfo); return 0; } Index: libpqconnection.h =================================================================== RCS file: /usr/local/cvsroot/psqlodbc/psqlodbc/libpqconnection.h,v retrieving revision 1.4 diff -c -r1.4 libpqconnection.h *** libpqconnection.h 30 Aug 2005 09:19:50 -0000 1.4 --- libpqconnection.h 31 Aug 2005 11:28:07 -0000 *************** *** 333,338 **** --- 333,339 ---- Int2 pg_version_minor; char ms_jet; char unicode; + char report_wide_types; char result_uncommitted; char schema_support; char *client_encoding; Index: pgtypes.c =================================================================== RCS file: /usr/local/cvsroot/psqlodbc/psqlodbc/pgtypes.c,v retrieving revision 1.70 diff -c -r1.70 pgtypes.c *** pgtypes.c 3 Aug 2005 08:09:33 -0000 1.70 --- pgtypes.c 31 Aug 2005 11:28:15 -0000 *************** *** 250,268 **** case PG_TYPE_BPCHAR: if (col >= 0 && getCharColumnSize(stmt, type, col, UNKNOWNS_AS_MAX) > ci->drivers.max_varchar_size) ! return conn->unicode ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR; ! return conn->unicode ? SQL_WCHAR : SQL_CHAR; case PG_TYPE_VARCHAR: if (col >= 0 && getCharColumnSize(stmt, type, col, UNKNOWNS_AS_MAX) > ci->drivers.max_varchar_size) ! return conn->unicode ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR; ! return conn->unicode ? SQL_WVARCHAR : SQL_VARCHAR; case PG_TYPE_TEXT: return ci->drivers.text_as_longvarchar ? ! (conn->unicode ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR) : ! (conn->unicode ? SQL_WVARCHAR : SQL_VARCHAR); case PG_TYPE_BYTEA: if (ci->bytea_as_longvarbinary) --- 250,268 ---- case PG_TYPE_BPCHAR: if (col >= 0 && getCharColumnSize(stmt, type, col, UNKNOWNS_AS_MAX) > ci->drivers.max_varchar_size) ! return (conn->unicode && conn->report_wide_types) ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR; ! return (conn->unicode && conn->report_wide_types) ? SQL_WCHAR : SQL_CHAR; case PG_TYPE_VARCHAR: if (col >= 0 && getCharColumnSize(stmt, type, col, UNKNOWNS_AS_MAX) > ci->drivers.max_varchar_size) ! return (conn->unicode && conn->report_wide_types) ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR; ! return (conn->unicode && conn->report_wide_types) ? SQL_WVARCHAR : SQL_VARCHAR; case PG_TYPE_TEXT: return ci->drivers.text_as_longvarchar ? ! ((conn->unicode && conn->report_wide_types) ? SQL_WLONGVARCHAR : SQL_LONGVARCHAR) : ! ((conn->unicode && conn->report_wide_types) ? SQL_WVARCHAR : SQL_VARCHAR); case PG_TYPE_BYTEA: if (ci->bytea_as_longvarbinary) *************** *** 416,422 **** case PG_TYPE_BPCHAR: case PG_TYPE_VARCHAR: case PG_TYPE_TEXT: ! if (conn->unicode && ! conn->ms_jet && ! stmt->manual_result) return SQL_C_WCHAR; return SQL_C_CHAR; --- 416,422 ---- case PG_TYPE_BPCHAR: case PG_TYPE_VARCHAR: case PG_TYPE_TEXT: ! if (conn->unicode && conn->report_wide_types && ! conn->ms_jet && ! stmt->manual_result) return SQL_C_WCHAR; return SQL_C_CHAR; *************** *** 977,984 **** { int coef = 1; Int4 prec = pgtype_column_size(stmt, type, col, handle_unknown_size_as), maxvarc; ! if (conn->unicode) ! return prec * 2; /* after 7.2 */ if (PG_VERSION_GE(conn, 7.2)) coef = 3; --- 977,984 ---- { int coef = 1; Int4 prec = pgtype_column_size(stmt, type, col, handle_unknown_size_as), maxvarc; ! if (conn->unicode && conn->report_wide_types) ! return prec * WCLEN; /* after 7.2 */ if (PG_VERSION_GE(conn, 7.2)) coef = 3; *************** *** 1054,1061 **** { case PG_TYPE_VARCHAR: case PG_TYPE_BPCHAR: ! if (conn->unicode) ! return prec * 2; /* after 7.2 */ if (PG_VERSION_GE(conn, 7.2)) coef = 3; --- 1054,1061 ---- { case PG_TYPE_VARCHAR: case PG_TYPE_BPCHAR: ! if (conn->unicode && conn->report_wide_types) ! return prec * WCLEN; /* after 7.2 */ if (PG_VERSION_GE(conn, 7.2)) coef = 3; *************** *** 1406,1412 **** case SQL_WCHAR: case SQL_WVARCHAR: case SQL_WLONGVARCHAR: ! if (conn->ms_jet || ! conn->unicode) return SQL_C_CHAR; return SQL_C_WCHAR; --- 1406,1412 ---- case SQL_WCHAR: case SQL_WVARCHAR: case SQL_WLONGVARCHAR: ! if (conn->ms_jet || ! conn->unicode || ! conn->report_wide_types) return SQL_C_CHAR; return SQL_C_WCHAR;
^ permalink raw reply [nested|flat] 32+ messages in thread

* Re: Unicode support
@ 2005-08-31 15:11  Marko Ristola <marko.ristola@kolumbus.fi>
  parent: Dave Page <dpage@vale-housing.co.uk>
  2 siblings, 0 replies; 32+ messages in thread

From: Marko Ristola @ 2005-08-31 15:11 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; +Cc: Anoop Kumar <anoopk@pervasive-postgres.com>; pgsql-odbc


LATIN1 and UCS have one common point by design:
0x00 - 0xFF are equal numbers, so the SQL_ASCII
ignorance means, that LATIN1 characters won't get changed!

So, this means, that:
0xE4 in ISO-8859-1 is the same as
0x00E4 in UCS-2. Just the number of needed bytes change.

Reference: "man 7 unicode"

Marko Ristola

Dave Page wrote:

>Hi Anoop and anyone else who might be interested,
>
>I've been thinking about how the Unicode support might be improved to
>allow the old 07.xx non-unicode style behaviour to work for those that
>need it. At them moment, when we connect using on of the wide connect
>functions, the CC->unicode flag is set to true. This only affects a few
>options, such as pgtype_to_concise_type()'s mapping of PG types to SQL
>types.
>
>It seems to me that perhaps we should set CC->unicode = 1, only upon
>connection to a Unicode database. Anything else, we leave it set to 0 so
>that it always maps varchars etc to ANSI types, and handles other
>encodings in single byte or non-unicode multibyte mode (which worked
>fine in 07.xx where those encodings where appropriate, such as SJIS in
>Japan). This should also help BDE based apps, which further research has
>shown me are broken with Unicode columns in SQL Server and Oracle as
>well as PostgreSQL (search unicode + BDE on Google Groups for more).
>
>Am I seeing a possible improvement where in fact there isn't one, or
>missing some obvious downside?
>
>Regards, Dave.
>
>---------------------------(end of broadcast)---------------------------
>TIP 2: Don't 'kill -9' the postmaster
>  
>




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

* Re: Unicode support
@ 2005-08-31 17:52  Hiroshi Saito <saito@inetrt.skcapi.co.jp>
  parent: Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 1 reply; 32+ messages in thread

From: Hiroshi Saito @ 2005-08-31 17:52 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; Anoop Kumar <anoopk@pervasive-postgres.com>; +Cc: pgsql-odbc

From: "Dave Page" 

Thanks.!!

> Please look at this carefully - as most of you know, MB/Unicode issues
> aren't exactly my strong point!

Ok, I am going to try the specification in multibyte. :-)

>
> I'll forward test DLLs to volunteer victims privately.

Regards,
Hiroshi Saito




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

* Re: Unicode support
@ 2005-08-31 20:00  Hiroshi Saito <saito@inetrt.skcapi.co.jp>
  parent: Hiroshi Saito <saito@inetrt.skcapi.co.jp>
  0 siblings, 1 reply; 32+ messages in thread

From: Hiroshi Saito @ 2005-08-31 20:00 UTC (permalink / raw)
  To: Hiroshi Saito <saito@inetrt.skcapi.co.jp>; Dave Page <dpage@vale-housing.co.uk>; Anoop Kumar <anoopk@pervasive-postgres.com>; +Cc: pgsql-odbc

Hi Dave.

I tried your patch by SJIS of Japan. It seems that it needs some additional 
correction. Moreover, it is necessary to make the driver different from 
UNICODE (WideCharacter). It seems that I have to catch up further. 

BTW, I remembered the discussion original by pgAdminIII. I said that I 
should support MullutiByte then. However, How is it now? It is very wonderful.
I feel that that there are many choices of a character code complicates a problem 
more. but, it is although external environment is different. 

Regards,
Hiroshi Saito

Attachments:

CONVERT_PATCH.txt (text/plain, 3.7K) download --- convert.c.orig Thu Aug 4 21:26:57 2005 +++ convert.c Thu Sep 1 04:38:45 2005 @@ -762,7 +762,7 @@ { BOOL lf_conv = conn->connInfo.lf_conversion; - if (fCType == SQL_C_WCHAR) + if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_WCHAR)) { len = utf8_to_ucs2_lf(neut_str, -1, lf_conv, NULL, 0); len *= WCLEN; @@ -778,7 +778,7 @@ } else #ifdef WIN32 - if (fCType == SQL_C_CHAR) + if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_CHAR)) { wstrlen = utf8_to_ucs2_lf(neut_str, -1, lf_conv, NULL, 0); allocbuf = (SQLWCHAR *) malloc(WCLEN * (wstrlen + 1)); @@ -810,7 +810,7 @@ pgdc->ttlbuflen = len + 1; } - if (fCType == SQL_C_WCHAR) + if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_WCHAR)) { utf8_to_ucs2_lf(neut_str, -1, lf_conv, (SQLWCHAR *) pgdc->ttlbuf, len / WCLEN); } @@ -824,7 +824,7 @@ } else #ifdef WIN32 - if (fCType == SQL_C_CHAR) + if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_CHAR)) { len = WideCharToMultiByte(CP_ACP, 0, allocbuf, wstrlen, pgdc->ttlbuf, pgdc->ttlbuflen, NULL, NULL); free(allocbuf); @@ -871,7 +871,7 @@ copy_len = (len >= cbValueMax) ? cbValueMax - 1 : len; - if (fCType == SQL_C_WCHAR) + if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_WCHAR)) { copy_len /= WCLEN; copy_len *= WCLEN; @@ -911,7 +911,7 @@ memcpy(rgbValueBindRow, ptr, copy_len); /* Add null terminator */ - if (fCType == SQL_C_WCHAR) + if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_WCHAR)) memset(rgbValueBindRow + copy_len, 0, WCLEN); else @@ -942,7 +942,7 @@ break; } - if (SQL_C_WCHAR == fCType && ! wchanged) + if ((conn->unicode && conn->report_wide_types) && (SQL_C_WCHAR == fCType && ! wchanged)) { if (cbValueMax > (SDWORD) (WCLEN * (len + 1))) { @@ -2629,6 +2629,8 @@ case SQL_WCHAR: case SQL_WVARCHAR: case SQL_WLONGVARCHAR: + if (conn->unicode && conn->report_wide_types) + { if (SQL_NTS == used) used = strlen(buffer); allocbuf = malloc(WCLEN * (used + 1)); @@ -2637,6 +2639,11 @@ buf = ucs2_to_utf8((SQLWCHAR *) allocbuf, used, (UInt4 *) &used, FALSE); free(allocbuf); allocbuf = buf; + { + else + { + buf = buffer; + } break; default: buf = buffer; @@ -2647,10 +2654,17 @@ break; case SQL_C_WCHAR: + if (conn->unicode && conn->report_wide_types) + { if (SQL_NTS == used) used = WCLEN * wcslen((SQLWCHAR *) buffer); buf = allocbuf = ucs2_to_utf8((SQLWCHAR *) buffer, used / WCLEN, (UInt4 *) &used, FALSE); used *= WCLEN; + } + else + { + buf = buffer; + } break; case SQL_C_DOUBLE: --- psqlodbc_win32.def.orig Thu Sep 1 04:41:37 2005 +++ psqlodbc_win32.def Thu Sep 1 04:42:08 2005 @@ -78,31 +78,3 @@ DllMain @201 ConfigDSN @202 -SQLColAttributeW @101 -SQLColumnPrivilegesW @102 -SQLColumnsW @103 -SQLConnectW @104 -SQLDescribeColW @106 -SQLExecDirectW @107 -SQLForeignKeysW @108 -SQLGetConnectAttrW @109 -SQLGetCursorNameW @110 -SQLGetInfoW @111 -SQLNativeSqlW @112 -SQLPrepareW @113 -SQLPrimaryKeysW @114 -SQLProcedureColumnsW @115 -SQLProceduresW @116 -SQLSetConnectAttrW @117 -SQLSetCursorNameW @118 -SQLSpecialColumnsW @119 -SQLStatisticsW @120 -SQLTablesW @121 -SQLTablePrivilegesW @122 -SQLDriverConnectW @123 -SQLGetDiagRecW @124 -SQLGetStmtAttrW @125 -SQLSetStmtAttrW @126 -SQLSetDescFieldW @127 -SQLGetTypeInfoW @128 -SQLGetDiagFieldW @129 =
^ permalink raw reply [nested|flat] 32+ messages in thread

* Re: Unicode support
@ 2005-09-01 08:24  Miguel Juan <mjuan@cibal.es>
  parent: Dave Page <dpage@vale-housing.co.uk>
  2 siblings, 0 replies; 32+ messages in thread

From: Miguel Juan @ 2005-09-01 08:24 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; +Cc: pgsql-odbc

hello,

I will try it with BDE environment if you want.

Regards,

Miguel Juan


----- Original Message ----- 
From: "Dave Page" <dpage@vale-housing.co.uk>
To: "Anoop Kumar" <anoopk@pervasive-postgres.com>
Cc: <pgsql-odbc@postgresql.org>
Sent: Tuesday, August 30, 2005 11:36 PM
Subject: [ODBC] Unicode support


Hi Anoop and anyone else who might be interested,

I've been thinking about how the Unicode support might be improved to
allow the old 07.xx non-unicode style behaviour to work for those that
need it. At them moment, when we connect using on of the wide connect
functions, the CC->unicode flag is set to true. This only affects a few
options, such as pgtype_to_concise_type()'s mapping of PG types to SQL
types.

It seems to me that perhaps we should set CC->unicode = 1, only upon
connection to a Unicode database. Anything else, we leave it set to 0 so
that it always maps varchars etc to ANSI types, and handles other
encodings in single byte or non-unicode multibyte mode (which worked
fine in 07.xx where those encodings where appropriate, such as SJIS in
Japan). This should also help BDE based apps, which further research has
shown me are broken with Unicode columns in SQL Server and Oracle as
well as PostgreSQL (search unicode + BDE on Google Groups for more).

Am I seeing a possible improvement where in fact there isn't one, or
missing some obvious downside?

Regards, Dave.

---------------------------(end of broadcast)---------------------------
TIP 2: Don't 'kill -9' the postmaster





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

* Re: Unicode support
@ 2005-09-01 09:05  Miguel Juan <mjuan@cibal.es>
  1 sibling, 0 replies; 32+ messages in thread

From: Miguel Juan @ 2005-09-01 09:05 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; +Cc: pgsql-odbc


----- Original Message ----- 
From: "Dave Page" <dpage@vale-housing.co.uk>
To: "Miguel Juan" <mjuan@cibal.es>
Cc: <pgsql-odbc@postgresql.org>
Sent: Thursday, September 01, 2005 10:32 AM
Subject: RE: [ODBC] Unicode support


Yes please - attached. 

> -----Original Message-----
> From: Miguel Juan [mailto:mjuan@cibal.es] 
> Sent: 01 September 2005 09:25
> To: Dave Page
> Cc: pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Unicode support
> 
> hello,
> 
> I will try it with BDE environment if you want.
> 
> Regards,
> 
> Miguel Juan
> 
> 
> ----- Original Message ----- 
> From: "Dave Page" <dpage@vale-housing.co.uk>
> To: "Anoop Kumar" <anoopk@pervasive-postgres.com>
> Cc: <pgsql-odbc@postgresql.org>
> Sent: Tuesday, August 30, 2005 11:36 PM
> Subject: [ODBC] Unicode support
> 
> 
> Hi Anoop and anyone else who might be interested,
> 
> I've been thinking about how the Unicode support might be improved to
> allow the old 07.xx non-unicode style behaviour to work for those that
> need it. At them moment, when we connect using on of the wide connect
> functions, the CC->unicode flag is set to true. This only 
> affects a few
> options, such as pgtype_to_concise_type()'s mapping of PG types to SQL
> types.
> 
> It seems to me that perhaps we should set CC->unicode = 1, only upon
> connection to a Unicode database. Anything else, we leave it 
> set to 0 so
> that it always maps varchars etc to ANSI types, and handles other
> encodings in single byte or non-unicode multibyte mode (which worked
> fine in 07.xx where those encodings where appropriate, such as SJIS in
> Japan). This should also help BDE based apps, which further 
> research has
> shown me are broken with Unicode columns in SQL Server and Oracle as
> well as PostgreSQL (search unicode + BDE on Google Groups for more).
> 
> Am I seeing a possible improvement where in fact there isn't one, or
> missing some obvious downside?
> 
> Regards, Dave.
> 
> ---------------------------(end of 
> broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
> 
> 
> 





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

* Re: Unicode support
@ 2005-09-01 09:11  Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 0 replies; 32+ messages in thread

From: Dave Page @ 2005-09-01 09:11 UTC (permalink / raw)
  To: Miguel Juan <mjuan@cibal.es>; +Cc: pgsql-odbc

Did this miss something?

:-)

/D 

> -----Original Message-----
> From: Miguel Juan [mailto:mjuan@cibal.es] 
> Sent: 01 September 2005 10:06
> To: Dave Page
> Cc: pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Unicode support
> 
> 
> ----- Original Message ----- 
> From: "Dave Page" <dpage@vale-housing.co.uk>
> To: "Miguel Juan" <mjuan@cibal.es>
> Cc: <pgsql-odbc@postgresql.org>
> Sent: Thursday, September 01, 2005 10:32 AM
> Subject: RE: [ODBC] Unicode support
> 
> 
> Yes please - attached. 
> 
> > -----Original Message-----
> > From: Miguel Juan [mailto:mjuan@cibal.es] 
> > Sent: 01 September 2005 09:25
> > To: Dave Page
> > Cc: pgsql-odbc@postgresql.org
> > Subject: Re: [ODBC] Unicode support
> > 
> > hello,
> > 
> > I will try it with BDE environment if you want.
> > 
> > Regards,
> > 
> > Miguel Juan
> > 
> > 
> > ----- Original Message ----- 
> > From: "Dave Page" <dpage@vale-housing.co.uk>
> > To: "Anoop Kumar" <anoopk@pervasive-postgres.com>
> > Cc: <pgsql-odbc@postgresql.org>
> > Sent: Tuesday, August 30, 2005 11:36 PM
> > Subject: [ODBC] Unicode support
> > 
> > 
> > Hi Anoop and anyone else who might be interested,
> > 
> > I've been thinking about how the Unicode support might be 
> improved to
> > allow the old 07.xx non-unicode style behaviour to work for 
> those that
> > need it. At them moment, when we connect using on of the 
> wide connect
> > functions, the CC->unicode flag is set to true. This only 
> > affects a few
> > options, such as pgtype_to_concise_type()'s mapping of PG 
> types to SQL
> > types.
> > 
> > It seems to me that perhaps we should set CC->unicode = 1, only upon
> > connection to a Unicode database. Anything else, we leave it 
> > set to 0 so
> > that it always maps varchars etc to ANSI types, and handles other
> > encodings in single byte or non-unicode multibyte mode (which worked
> > fine in 07.xx where those encodings where appropriate, such 
> as SJIS in
> > Japan). This should also help BDE based apps, which further 
> > research has
> > shown me are broken with Unicode columns in SQL Server and Oracle as
> > well as PostgreSQL (search unicode + BDE on Google Groups for more).
> > 
> > Am I seeing a possible improvement where in fact there isn't one, or
> > missing some obvious downside?
> > 
> > Regards, Dave.
> > 
> > ---------------------------(end of 
> > broadcast)---------------------------
> > TIP 2: Don't 'kill -9' the postmaster
> > 
> > 
> > 
> 
> 
> 



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

* Re: Unicode support
@ 2005-09-01 09:15  Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 1 reply; 32+ messages in thread

From: Dave Page @ 2005-09-01 09:15 UTC (permalink / raw)
  To: Hiroshi Saito <saito@inetrt.skcapi.co.jp>; Anoop Kumar <anoopk@pervasive-postgres.com>; +Cc: pgsql-odbc

 

> -----Original Message-----
> From: Hiroshi Saito [mailto:saito@inetrt.skcapi.co.jp] 
> Sent: 31 August 2005 21:00
> To: Hiroshi Saito; Dave Page; Anoop Kumar
> Cc: pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Unicode support
> 
> Hi Dave.
> 
> I tried your patch by SJIS of Japan. It seems that it needs 
> some additional 
> correction. Moreover, it is necessary to make the driver 
> different from 
> UNICODE (WideCharacter). It seems that I have to catch up further. 

Hmmm, well I can't remove the Unicode functions. Do your apps request
SQL_C_WCHAR etc even if the driver doesn't offer it?

> BTW, I remembered the discussion original by pgAdminIII. I 
> said that I 
> should support MullutiByte then. However, How is it now? It 
> is very wonderful.
> I feel that that there are many choices of a character code 
> complicates a problem 
> more. but, it is although external environment is different. 

Hmm, I hate multibyte :-(!!

Regards, Dave



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

* Re: Unicode support
@ 2005-09-01 10:05  Miguel Juan <mjuan@cibal.es>
  1 sibling, 0 replies; 32+ messages in thread

From: Miguel Juan @ 2005-09-01 10:05 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; +Cc: pgsql-odbc

Hello Dave,

I'm just trying the last fix (for BDE) and I can see some odd behavior.

- It shows the TEXT fields as MEMO. But you can see the data if you make a 
double click on it. It looks like it doesn't use the "text as LongVarchar" 
option (this works in version 7.x).

- After a "SELECT * FROM table" The Borland SQL Explorer shows an error 
('Invalid Blob Handle') for empty TEXT fields (NULL) when you try to view 
them. This works fine for table view.

- After an error inserting a row ('not null' constraint) it closes the 
connection (dead connection error)


Regards,

Miguel Juan




----- Original Message ----- 
From: "Dave Page" <dpage@vale-housing.co.uk>
To: "Miguel Juan" <mjuan@cibal.es>
Cc: <pgsql-odbc@postgresql.org>
Sent: Thursday, September 01, 2005 10:32 AM
Subject: RE: [ODBC] Unicode support


Yes please - attached.

> -----Original Message-----
> From: Miguel Juan [mailto:mjuan@cibal.es]
> Sent: 01 September 2005 09:25
> To: Dave Page
> Cc: pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Unicode support
>
> hello,
>
> I will try it with BDE environment if you want.
>
> Regards,
>
> Miguel Juan
>
>
> ----- Original Message ----- 
> From: "Dave Page" <dpage@vale-housing.co.uk>
> To: "Anoop Kumar" <anoopk@pervasive-postgres.com>
> Cc: <pgsql-odbc@postgresql.org>
> Sent: Tuesday, August 30, 2005 11:36 PM
> Subject: [ODBC] Unicode support
>
>
> Hi Anoop and anyone else who might be interested,
>
> I've been thinking about how the Unicode support might be improved to
> allow the old 07.xx non-unicode style behaviour to work for those that
> need it. At them moment, when we connect using on of the wide connect
> functions, the CC->unicode flag is set to true. This only
> affects a few
> options, such as pgtype_to_concise_type()'s mapping of PG types to SQL
> types.
>
> It seems to me that perhaps we should set CC->unicode = 1, only upon
> connection to a Unicode database. Anything else, we leave it
> set to 0 so
> that it always maps varchars etc to ANSI types, and handles other
> encodings in single byte or non-unicode multibyte mode (which worked
> fine in 07.xx where those encodings where appropriate, such as SJIS in
> Japan). This should also help BDE based apps, which further
> research has
> shown me are broken with Unicode columns in SQL Server and Oracle as
> well as PostgreSQL (search unicode + BDE on Google Groups for more).
>
> Am I seeing a possible improvement where in fact there isn't one, or
> missing some obvious downside?
>
> Regards, Dave.
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 2: Don't 'kill -9' the postmaster
>
>
>





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

* Re: Unicode support
@ 2005-09-01 11:17  Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 0 replies; 32+ messages in thread

From: Dave Page @ 2005-09-01 11:17 UTC (permalink / raw)
  To: Miguel Juan <mjuan@cibal.es>; +Cc: pgsql-odbc

 

> -----Original Message-----
> From: Miguel Juan [mailto:mjuan@cibal.es] 
> Sent: 01 September 2005 11:06
> To: Dave Page
> Cc: pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Unicode support
> 
> Hello Dave,
> 
> I'm just trying the last fix (for BDE) and I can see some odd 
> behavior.
> 
> - It shows the TEXT fields as MEMO. But you can see the data 
> if you make a 
> double click on it. It looks like it doesn't use the "text as 
> LongVarchar" 
> option (this works in version 7.x).

Right, I'll look at that.

> - After a "SELECT * FROM table" The Borland SQL Explorer 
> shows an error 
> ('Invalid Blob Handle') for empty TEXT fields (NULL) when you 
> try to view 
> them. This works fine for table view.

Strange.

> - After an error inserting a row ('not null' constraint) it 
> closes the 
> connection (dead connection error)

I'll test that as well.

To be honest though, I've been researching BDE on Google Groups and
there are lots of people reporting similar problems with SQL Server and
Oracle - apparently BDE fails to work properly with any Unicode data.
I'm happy to spend a little time trying to work around that, but I can't
spend masses of time on it.

Regards, Dave.



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

* Re: Unicode support
@ 2005-09-01 17:20  Marko Ristola <Marko.Ristola@kolumbus.fi>
  parent: Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 0 replies; 32+ messages in thread

From: Marko Ristola @ 2005-09-01 17:20 UTC (permalink / raw)
  To: ; +Cc: Hiroshi Saito <saito@inetrt.skcapi.co.jp>; Anoop Kumar <anoopk@pervasive-postgres.com>; pgsql-odbc


Hi all.

How about creating a charset conversion interface
and taking UTF-8 as an internal format for ODBC?:

At least the following functions might be needed:

Internal2WChar()
WChar2Internal()

Internal2Char()
Char2Internal()

Backend would talk only UTF-8.

Here is a minimum set of interface
(Object oriented design term) functions:

cvt_FromUTF8()
cvt_ToUTF8()
cvt_Free()

Interface implementation:

struct CvtInterface {
  char (*cvt_FromUTF8)(void *internalData, char *source, size_t bytes);
  char (*cvt_ToUTF8)(void *internalData, char *source, size_t bytes);
  void (*cvt_Free)(void *internalData);

  void *internalData;
}
Object creation:

struct Env {
    struct CvtInterface char_cvt; // C program char conversions
    struct CvtInterface wchar_cvt; // C program wchar_t conversions
};

struct CvtInterface utf8_to_utf8_New();
env->char_cvt = utf8_to_utf8_New();

These are some interface implementation functions:
(I don't know, how many are needed, but at least
supporting of char, wchar and multibyte is needed).

sjis_new()
sjis_FromUTF8()
sjis_ToUTF8()
sjis_Free()

wchar_FromUTF8()
wchar_ToUTF8()
wchar_Free()

char_FromUTF8()
char_ToUTF8()
char_Free()

utf8_FromUTF8()
utf8_ToUTF8()
utf8_Free()

ascii8_FromUTF8()
ascii8_ToUTF8()
ascii8_Free()

So, there would be a single internal UTF-8 format inside PsqlODBC.
The backend could always deliver UTF-8, so the need for internal
format <-> backend format layer is not needed.

This implementation would be easy to implement.

Examples:

A C program calls SQLExecuteW.
AllocEnv has found out, that the wchar format is UCS-2.
So it has created an object:
env->char_cvt = cvt_ucs2_UTF8_New();

The PGAPI function needs to convert from WCHAR into internal format:
sqlquery = (*env->char_cvt->cvt_ToUTF8)(wcharquery);
Then the sqlquery is in UTF8, and the query is in
an easilly manageable format!

A C program uses SQLGetDataW to get a string.
So when the data will be converted in convert.c, psqlodbc calls:
result = (*env->char_cvt->cvt_FromUTF8)(internalformat);

I don't know, wether ENV handle is the best place to put the converter
objects.

I like about this implementation:
- Simplifies support for clients using different charsets.
- Simplifies psqodbc internally, because of internal UTF8 assumption.
- Easy to implement and to test.
- Easy to add more converters, when the initial implementation works.
- Enables usage of advanced lexers and parsers when needed to improve
performance.
- PSQLODBC will support well all UTF-8 supported charsets.
 
I have not suggested this before, because of the following reasons:
- psqlodbc charset conversion implementation seems to work most times.
- Avoiding unnecessary charset conversions is good for performance.
- It takes time to implement and test this.
- Unnecessary malloc + free is bad for performance.

What do you think about this?
Would this solve the problems?
Is this implementable?
Would the performance be good enough?
Would this simplify things (that's the Goal)?

Regards,
Marko Ristola


Dave Page wrote:

> 
>
>  
>
>>-----Original Message-----
>>From: Hiroshi Saito [mailto:saito@inetrt.skcapi.co.jp] 
>>Sent: 31 August 2005 21:00
>>To: Hiroshi Saito; Dave Page; Anoop Kumar
>>Cc: pgsql-odbc@postgresql.org
>>Subject: Re: [ODBC] Unicode support
>>
>>Hi Dave.
>>
>>I tried your patch by SJIS of Japan. It seems that it needs 
>>some additional 
>>correction. Moreover, it is necessary to make the driver 
>>different from 
>>UNICODE (WideCharacter). It seems that I have to catch up further. 
>>    
>>
>
>Hmmm, well I can't remove the Unicode functions. Do your apps request
>SQL_C_WCHAR etc even if the driver doesn't offer it?
>
>  
>



>>BTW, I remembered the discussion original by pgAdminIII. I 
>>said that I 
>>should support MullutiByte then. However, How is it now? It 
>>is very wonderful.
>>I feel that that there are many choices of a character code 
>>complicates a problem 
>>more. but, it is although external environment is different. 
>>    
>>
>
>Hmm, I hate multibyte :-(!!
>
>Regards, Dave
>
>---------------------------(end of broadcast)---------------------------
>TIP 1: if posting/reading through Usenet, please send an appropriate
>       subscribe-nomail command to majordomo@postgresql.org so that your
>       message can get through to the mailing list cleanly
>  
>




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

* Re: Unicode support
@ 2005-09-02 07:50  Dave Page <dpage@vale-housing.co.uk>
  0 siblings, 0 replies; 32+ messages in thread

From: Dave Page @ 2005-09-02 07:50 UTC (permalink / raw)
  To: Marko Ristola <Marko.Ristola@kolumbus.fi>; +Cc: Hiroshi Saito <saito@inetrt.skcapi.co.jp>; Anoop Kumar <anoopk@pervasive-postgres.com>; pgsql-odbc

 

> -----Original Message-----
> From: pgsql-odbc-owner@postgresql.org 
> [mailto:pgsql-odbc-owner@postgresql.org] On Behalf Of Marko Ristola
> Sent: 01 September 2005 18:21
> Cc: Hiroshi Saito; Anoop Kumar; pgsql-odbc@postgresql.org
> Subject: Re: [ODBC] Unicode support
> 
> 
> Hi all.

Hi Marko,

> How about creating a charset conversion interface
> and taking UTF-8 as an internal format for ODBC?:
> 

<snip>

> 
> So, there would be a single internal UTF-8 format inside PsqlODBC.
> The backend could always deliver UTF-8, so the need for internal
> format <-> backend format layer is not needed.
> 
> This implementation would be easy to implement.

This is what already happens (if you ignore my recent experimental
patch). 

If the connection is made using one of the *W connect functions, then
the ConnectionClass->unicode flag is set to true, and SET
client_encoding = 'UTF-8' is sent to the backend. From then on, data
going out to the client is fed through utf8_to_ucs2_lf() *if * the data
type is specified as SQL_C_WCHAR, and data coming in to *W functions is
fed through ucs2_to_utf8().

Afaict, Unicode mode works exactly as it should.

If the connection is made using a non-wide function, the
ConnectionClass->unicode is not set. In this case, the client is
expected to continue using non-wide functions, and the client encoding
left at default. In this case, the driver will never report data types
as SQL_C_WCHAR.

This, is where I believe the major problem occurs - if the ODBC Driver
Manager sees that SQLConnectW (iirc) exists, it will automatically map
ANSI calls (eg. SQLConnect()) to Unicode (eg. SQLConnectW()). This then
causes the driver to report text/char columns as SQL_C_WCHAR. Less well
written apps then fall over because they aren't clever enough to request
data as SQL_C_CHAR instead of SQL_C_WCHAR.

My recent experimental patch aims to address this, by forcing the driver
to report SQL_C_CHAR instead of SQL_C_WCHAR for non-unicode databases.
This should (and seems to, with minor side effects yet to be fully
investigated) fix the BDE problem.

As for multibyte (non-unicode) data such as Hiroshi's, my understanding
is that in the presence of a Unicode driver, apps are expected to use
Unicode (and in fact, are forced to by the driver manager's mapping of
ANSI function calls to Unicode calls). 

Anoop, do you or any of your guys (or anyone else) know
unicode/multibyte/encoding well? I'm learning as I go at the moment, so
some more experienced help would be *really* appreciated.

Regards, Dave.



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

* Re: Unicode support
@ 2005-09-02 10:45  Anoop Kumar <anoopk@pervasive-postgres.com>
  0 siblings, 0 replies; 32+ messages in thread

From: Anoop Kumar @ 2005-09-02 10:45 UTC (permalink / raw)
  To: Dave Page <dpage@vale-housing.co.uk>; +Cc: pgsql-odbc

> Anoop, do you or any of your guys (or anyone else) know
> unicode/multibyte/encoding well? I'm learning as I go at the moment,
so
> some more experienced help would be *really* appreciated.

Sorry Dave, No one in my list! :-(
 
Regards

Anoop



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

* Re: Unicode support
@ 2005-09-03 07:23  Marko Ristola <Marko.Ristola@kolumbus.fi>
  parent: Hiroshi Saito <saito@inetrt.skcapi.co.jp>
  0 siblings, 2 replies; 32+ messages in thread

From: Marko Ristola @ 2005-09-03 07:23 UTC (permalink / raw)
  To: Hiroshi Saito <saito@inetrt.skcapi.co.jp>; +Cc: Dave Page <dpage@vale-housing.co.uk>; Anoop Kumar <anoopk@pervasive-postgres.com>; pgsql-odbc


So, I don't have much experience with Windows ODBC. That's true.
Is it possible to compile psqlodbc with MinGW tools for Windows?

After using Google, I found out, that GLIB libraries are able to convert
UTF-8 into multibyte under Windows. Windows should be
able to convert UTF-8 into Multibyte and vice versa with it's character
set conversion
functions.

After using Google, I found out, that Windows XP had a problem with
Korean multibyte:


  "Windows XP Device Driver Does Not Convert Multibyte Data to Korean"

 Article ID: 817522.

That was fixed in Service Pack 2.

So I ask you, how you have thought about these things:

If I have understood Windows correctly, it uses UCS-2 as it's internal
UNICODE
character set. Linux prefers into UTF-8. So, If we classify UCS-2 and
UTF-8 equal inside psqoldbc,
that makes sense. That's what has been implemented into psqlodbc already
for Windows.

Then there is the world before Unicode existed. There were DOS codepages,
character sets for groups of countries and Multibyte character sets.

JIS X 0208 is a character set (see man 7 charsets).
Shift_JIS is an encoding that can contain JIS X 0208 multibyte
characters (see man 7 charsets).

So it seems, that one working implementation can be done by using UTF-8
PostgreSQL server
and UTF-8 to multibyte conversions.

However, according to Samba team's UNICODE problem descriptions,
there are some problems: UTF-8 to EUC_JP conversion may be different
on Linux and Windows, and on different conversion library implementations.

Some multibyte character sets are contraditory with each other.

If we drop the *W() functions away, we might get a working implementation,
but we might not support the full ODBC API?

So if and only if one single conversion library does the conversions, it
works.

So if and only if the PostgreSQL backend, or only the PSQLODBC side
does the needed conversions, psqlodbc should work with multibyte
encodings, with UTF-8. If the PostgreSQL Server is in a same kind of
Windows environment than the clients, it should work
fully with UTF-8 and the multibyte character sets. This should be the
best working option.

Windows does have a working UCS-2 to multibyte conversion implementation
on the psqlodbc client (since Service Pack 2).

Unfortunately pg_dump + restore from SJIS into UTF-8 might not work,
because Linux's ICONV might not do the conversion correctly.

The conversion into UTF-8 must be done using fully working Windows
conversion functions.
So one way might be something like using such pg_dump under Windows,
that does the multibyte into UTF-8 conversion in Windows side.

How about the following implementation:
ODBC against the backend:
- Backend has multibyte characters.
- Windows uses multibyte characters.
psqlodbc has UTF-8 as it's internal formats.

=> A fully working implementation:
- Backend deliveres multibyte characters.
PSQLODBC converts them into UTF-8.
PSQLODBC deliveres multibyte characters to the client
using utf8_to_locale Windows functions, when necessary.

So the solution might be here to do all conversions on the client side!
However the reasoning for this is, that two separate conversion
libraries might
be contradictory with each other, at least with the Asian character sets.
(With MACs, UTF-8 implementation differs from the standard.)

Or then Asian users should move and use UTF-8 as their PostgreSQL
Server's backend format.
That's the other solution for the same problem. Then PostgreSQL Server
doesn't
have to do the conversion.

It does not seem possible to do all the conversion functions inside
PostgreSQL Server under Windows,
because of the xx() -> xxW() mapping inside Windows ODBC manager. We
can't control that.

What do you think about these thoughts?

Marko Ristola

Hiroshi Saito wrote:

>Hi Dave.
>
>I tried your patch by SJIS of Japan. It seems that it needs some additional 
>correction. Moreover, it is necessary to make the driver different from 
>UNICODE (WideCharacter). It seems that I have to catch up further. 
>
>BTW, I remembered the discussion original by pgAdminIII. I said that I 
>should support MullutiByte then. However, How is it now? It is very wonderful.
>I feel that that there are many choices of a character code complicates a problem 
>more. but, it is although external environment is different. 
>
>Regards,
>Hiroshi Saito
>
>------------------------------------------------------------------------
>
>--- convert.c.orig	Thu Aug  4 21:26:57 2005
>+++ convert.c	Thu Sep  1 04:38:45 2005
>@@ -762,7 +762,7 @@
> 				{
> 					BOOL lf_conv = conn->connInfo.lf_conversion;
> 
>-					if (fCType == SQL_C_WCHAR)
>+					if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_WCHAR))
> 					{
> 						len = utf8_to_ucs2_lf(neut_str, -1, lf_conv, NULL, 0);
> 						len *= WCLEN;
>@@ -778,7 +778,7 @@
> 					}
> 					else
> #ifdef	WIN32
>-					if (fCType == SQL_C_CHAR)
>+					if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_CHAR))
> 					{
> 						wstrlen = utf8_to_ucs2_lf(neut_str, -1, lf_conv, NULL, 0);
> 						allocbuf = (SQLWCHAR *) malloc(WCLEN * (wstrlen + 1));
>@@ -810,7 +810,7 @@
> 							pgdc->ttlbuflen = len + 1;
> 						}
> 
>-						if (fCType == SQL_C_WCHAR)
>+						if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_WCHAR))
> 						{
> 							utf8_to_ucs2_lf(neut_str, -1, lf_conv, (SQLWCHAR *) pgdc->ttlbuf, len / WCLEN);
> 						}
>@@ -824,7 +824,7 @@
> 						}
> 						else
> #ifdef	WIN32
>-						if (fCType == SQL_C_CHAR)
>+						if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_CHAR))
> 						{
> 							len = WideCharToMultiByte(CP_ACP, 0, allocbuf, wstrlen, pgdc->ttlbuf, pgdc->ttlbuflen, NULL, NULL);
> 							free(allocbuf);
>@@ -871,7 +871,7 @@
> 
> 					copy_len = (len >= cbValueMax) ? cbValueMax - 1 : len;
> 
>-					if (fCType == SQL_C_WCHAR)
>+					if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_WCHAR))
> 					{
> 						copy_len /= WCLEN;
> 						copy_len *= WCLEN;
>@@ -911,7 +911,7 @@
> 						memcpy(rgbValueBindRow, ptr, copy_len);
> 						/* Add null terminator */
> 
>-						if (fCType == SQL_C_WCHAR)
>+						if ((conn->unicode && conn->report_wide_types) && (fCType == SQL_C_WCHAR))
> 							memset(rgbValueBindRow + copy_len, 0, WCLEN);
> 						else
> 
>@@ -942,7 +942,7 @@
> 				break;
> 		}
> 
>-		if (SQL_C_WCHAR == fCType && ! wchanged)
>+		if ((conn->unicode && conn->report_wide_types) && (SQL_C_WCHAR == fCType && ! wchanged))
> 		{
> 			if (cbValueMax > (SDWORD) (WCLEN * (len + 1)))
> 			{
>@@ -2629,6 +2629,8 @@
> 				case SQL_WCHAR:
> 				case SQL_WVARCHAR:
> 				case SQL_WLONGVARCHAR:
>+					if (conn->unicode && conn->report_wide_types)
>+					{
> 					if (SQL_NTS == used)
> 						used = strlen(buffer);
> 					allocbuf = malloc(WCLEN * (used + 1));
>@@ -2637,6 +2639,11 @@
> 					buf = ucs2_to_utf8((SQLWCHAR *) allocbuf, used, (UInt4 *) &used, FALSE);
> 					free(allocbuf);
> 					allocbuf = buf;
>+					{
>+					else
>+					{
>+						buf = buffer;
>+					}
> 					break;
> 				default:
> 					buf = buffer;
>@@ -2647,10 +2654,17 @@
> 			break;
> 
> 		case SQL_C_WCHAR:
>+			if (conn->unicode && conn->report_wide_types)
>+			{
>             if (SQL_NTS == used)
>                 used = WCLEN * wcslen((SQLWCHAR *) buffer);
> 			buf = allocbuf = ucs2_to_utf8((SQLWCHAR *) buffer, used / WCLEN, (UInt4 *) &used, FALSE);
> 			used *= WCLEN;
>+			}
>+			else
>+			{
>+				buf = buffer;
>+			}
> 			break;
> 
> 		case SQL_C_DOUBLE:
>--- psqlodbc_win32.def.orig	Thu Sep  1 04:41:37 2005
>+++ psqlodbc_win32.def	Thu Sep  1 04:42:08 2005
>@@ -78,31 +78,3 @@
> DllMain @201
> ConfigDSN @202
> 
>-SQLColAttributeW	@101
>-SQLColumnPrivilegesW	@102
>-SQLColumnsW		@103
>-SQLConnectW		@104
>-SQLDescribeColW		@106
>-SQLExecDirectW		@107
>-SQLForeignKeysW		@108
>-SQLGetConnectAttrW	@109
>-SQLGetCursorNameW	@110
>-SQLGetInfoW		@111
>-SQLNativeSqlW		@112
>-SQLPrepareW		@113
>-SQLPrimaryKeysW		@114
>-SQLProcedureColumnsW	@115
>-SQLProceduresW		@116
>-SQLSetConnectAttrW	@117
>-SQLSetCursorNameW	@118
>-SQLSpecialColumnsW	@119
>-SQLStatisticsW		@120
>-SQLTablesW		@121
>-SQLTablePrivilegesW	@122
>-SQLDriverConnectW	@123
>-SQLGetDiagRecW		@124
>-SQLGetStmtAttrW		@125
>-SQLSetStmtAttrW		@126
>-SQLSetDescFieldW	@127
>-SQLGetTypeInfoW		@128
>-SQLGetDiagFieldW	@129
>  
>
>------------------------------------------------------------------------
>
>
>---------------------------(end of broadcast)---------------------------
>TIP 3: Have you checked our extensive FAQ?
>
>               http://www.postgresql.org/docs/faq
>  
>




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

* Re: Unicode support
@ 2005-09-03 08:00  Marko Ristola <Marko.Ristola@kolumbus.fi>
  parent: Marko Ristola <Marko.Ristola@kolumbus.fi>
  1 sibling, 0 replies; 32+ messages in thread

From: Marko Ristola @ 2005-09-03 08:00 UTC (permalink / raw)
  To: Marko Ristola <Marko.Ristola@kolumbus.fi>; +Cc: Hiroshi Saito <saito@inetrt.skcapi.co.jp>; Dave Page <dpage@vale-housing.co.uk>; Anoop Kumar <anoopk@pervasive-postgres.com>; pgsql-odbc

Marko Ristola wrote:

>However, according to Samba team's UNICODE problem descriptions,
>there are some problems: UTF-8 to EUC_JP conversion may be different
>on Linux and Windows, and on different conversion library implementations.
>
>  
>

This was the Samba reference. I recommend you to read the applicable parts.
http://www.samba.org/samba/docs/man/Samba-HOWTO-Collection/unicode.html

I hope, that the multibyte into UTF-8 and vice versa is possible.
If not, disabling UTF-8 and UCS-2 seems to be the only workable choise :(

Regards,
Marko

>Some multibyte character sets are contraditory with each other.
>
>  
>




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

* Re: Unicode support
@ 2005-09-08 17:22  Marko Ristola <Marko.Ristola@kolumbus.fi>
  parent: Marko Ristola <Marko.Ristola@kolumbus.fi>
  1 sibling, 1 reply; 32+ messages in thread

From: Marko Ristola @ 2005-09-08 17:22 UTC (permalink / raw)
  To: Marc Herbert <Marc.Herbert@emicnetworks.com>; pgsql-odbc


Marc Herbert wrote:

>Marko Ristola <Marko.Ristola@kolumbus.fi> writes:
>  
>
>>So I ask you, how you have thought about these things:
>>
>>If I have understood Windows correctly, it uses UCS-2 as it's internal
>>UNICODE
>>character set. Linux prefers into UTF-8. 
>>    
>>
>
>I am not sure what you mean by "internal UNICODE character set", but I
>understand that Linux does prefer UTF-32, NOT UTF-8 !
>
>  
>

If you want to know the details about UTF-8's encoding, the following
is a recommended reading (Linux manual page) :)

man utf-8

It gives you a good explanation of the encoding used in  UTF-8.

UTF-8 uses from one to four bytes per character.
It supports almost all character sets in the World.

Because the task is so huge, there exist variants and bugs in
the implementations. That's what I read from Samba filesystem
FAQ.

So, if you stick with Windows implementation, you don't find
any bugs, but when you move the file into another operating system,
the file might look different :(

UCS-2 is a 32-bit Unicode wchar_t type. According to
Linux manuals, wchar_t is not equal on all implementations.
According to manuals, inside binary files, it is recommended in C
to use UTF-8 strings, that are then converted at runtime into
wchar_t type. Java language is another story. There might
be same problems though. The number remains the same, but
if you try to draw the character into the window with
different implementations, you might get different drawings.


>On all platforms I had a look at, variable-length encodings are only
>for disk and network, never used in memory.
>
>Don't you agree?
>  
>
> locale
LANG=fi_FI.UTF-8@euro
LC_CTYPE="fi_FI.UTF-8@euro"
LC_NUMERIC="fi_FI.UTF-8@euro"
LC_TIME="fi_FI.UTF-8@euro"
LC_COLLATE="fi_FI.UTF-8@euro"
LC_MONETARY="fi_FI.UTF-8@euro"
LC_MESSAGES="fi_FI.UTF-8@euro"
LC_PAPER="fi_FI.UTF-8@euro"
LC_NAME="fi_FI.UTF-8@euro"
LC_ADDRESS="fi_FI.UTF-8@euro"
LC_TELEPHONE="fi_FI.UTF-8@euro"
LC_MEASUREMENT="fi_FI.UTF-8@euro"
LC_IDENTIFICATION="fi_FI.UTF-8@euro"
LC_ALL=

So, under Linux nowadays, UTF-8 is used very much.
Just as Windows recommends everybody to move into
native Windows Unicode characters (UCS-2), under Linux
it is recommended to move into UTF-8. Both are UNICODE
character encodings.  UCS-2 encoding is just simpler: just
an integer, that has a numerical value.

The reason for the popularity of UTF-8 under Linux is, that each
program needs to be adjusted very little to be able to move
from LATIN1 style encoding into UTF-8.

Happy studying about Unicode character sets :)

Regards,
Marko Ristola






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

* Re: Unicode support
@ 2005-09-09 16:40  Marko Ristola <marko.ristola@kolumbus.fi>
  parent: Marko Ristola <Marko.Ristola@kolumbus.fi>
  0 siblings, 0 replies; 32+ messages in thread

From: Marko Ristola @ 2005-09-09 16:40 UTC (permalink / raw)
  To: Marc Herbert <Marc.Herbert@emicnetworks.com>; pgsql-odbc

Marc Herbert wrote:

>On Thu, Sep 08, 2005 at 08:22:50PM +0300, Marko Ristola wrote:
>  
>
>>Marc Herbert wrote:
>>
>>    
>>
>>>Marko Ristola <Marko.Ristola@kolumbus.fi> writes:
>>> 
>>>
>>>      
>>>
>
>Actually my question was just: what do you mean by 'internal'?
>
>Usually 'internal" means 'in memory', and I really don't think there
>is any application/system using UTF-8 in memory, is there?
>
>  
>
I'm sorry.

I hope, that this time I'll answer to the right question.
Unfortunately this is also a lengthy answer.


I meant with internal unicode, the wchar_t type in Linux and Unixes.
Or the Windows internal Unicode (TCHAR).

I tried to find out more about the wchar_t(TCHAR) implementations - the
internal Unicode representations.

According to libc info pages:

Under GNU Linux, wchar_t is implemented as 32bit UCS-4 characters.
My ealier assumption, that Linux uses UCS-2, is wrong :(
My ealier assumption, that UCS-2 is 32bit, is wrong :(

Some Unix systems implement wchar_t as 16bit UCS-2 characters.
This means, that if they want to implement the full 31 bit character set 
space,
they can do so by using pairs of certain UCS-2 characters. This
is UCS-16 format (a multibyte version of UCS-2).

- If I remember correctly: Java uses 16bit Unicode, meaning, that they 
use UCS-2 or UCS-16.
- According to psqlodbc implementation, Windows uses UCS-2 as it's
internal format. This implicates also, that Windows might actually use
UCS-16 multibyte format internally, because UCS-2 is a subset of UCS-16.
Of course, Windows is capable to create it's own private standards.

PostgreSQL ODBC driver for Windows has already the UTF-8 to UCS-2
character set conversion functions.

PostgreSQL ODBC driver for Linux still misses UTF-8 to UCS-4 character
set conversion functions.


PostgreSQL Server deliveres the query results as UTF-8 for Windows ODBC
driver. ODBC driver then converts the UTF-8 data into UCS-2. So psqlodbc 
driver
uses internally UTF-8 under Windows.

UTF-8 use cases under Linux:

- Openoffice files are stored as UTF-8.
- Emacs and many other editors store files as UTF-8.
- LATIN1 or another non-Unicode characters still work, but are less used.
- Some programs still don't work with UTF-8.

The names of the files and their data are stored nowadays as UTF-8.
Many programs use UTF-8 internally, not wchar_t format UCS-4.

There might be some new programs and editors (Gnome, Kde ??) that are 
written from
scratch, and might use wchar_t internally (UCS-4). Java programs use 
always UCS-2 (or UCS-16)
as their internal format. So it isn't wchar_t Unicode. Java way is 
standardized.

Terminals use nowadays UTF-8. With network, UTF-8 works (ideal. 
Reality??) from Windows
to Linux, and from Mac to Linux. So a common format is good.

So, under Linux every program may choose:
- to store file names as UTF-8 or as LATIN1. This is actually a bad 
thing. The
behaviour depends on which character set you have selected before 
logging in.
- to store files as UTF-8 or as LATIN1. This is again based on the 
console logging option.
- to do any character conversions they like, with libiconv library.


>
> 
>  
>
>>>locale
>>>      
>>>
>>The reason for the popularity of UTF-8 under Linux is, that each
>>program needs to be adjusted very little to be able to move
>>from LATIN1 style encoding into UTF-8.
>>    
>>
>
>Again, are you talking about memory, disk/network?
>
>This is definitely not the same thing IMHO.
>
>  
>
So when you ask about memory and disk: the answer is that each 
application chooses
it's character set formats. Usually the environment variables affect the 
selections.

So when you ask about the network character set: Network interaction is 
standardized.
Many Unixes,Linux and Windows try to conform to these network standards.

Regards, Marko Ristola




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


end of thread, other threads:[~2005-09-09 16:40 UTC | newest]

Thread overview: 32+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2002-02-03 20:26 Unicode support Nhan Ngo Dinh <nngodinh@tiscali.it>
2002-02-11 17:22 ` Jean-Michel POURE <jm.poure@freesurf.fr>
2002-02-12 00:45   ` Hiroshi Inoue <Inoue@tpf.co.jp>
2002-02-12 09:02     ` Jean-Michel POURE <jm.poure@freesurf.fr>
2002-02-18 11:14 ` Jean-Michel POURE <jm.poure@freesurf.fr>
2002-02-19 07:28 ` Jean-Michel POURE <jm.poure@freesurf.fr>
2002-02-21 22:34   ` Jean-Michel POURE <jm.poure@freesurf.fr>
2002-02-19 07:34 ` Jean-Michel POURE <jm.poure@freesurf.fr>
2002-02-19 09:10   ` Hiroshi Inoue <Inoue@tpf.co.jp>
2002-02-19 08:27 ` Jean-Michel POURE <jm.poure@freesurf.fr>
2005-08-30 21:36 Unicode support Dave Page <dpage@vale-housing.co.uk>
2005-08-31 01:55 ` Hiroshi Saito <saito@inetrt.skcapi.co.jp>
2005-08-31 15:11 ` Marko Ristola <marko.ristola@kolumbus.fi>
2005-09-01 08:24 ` Miguel Juan <mjuan@cibal.es>
2005-08-31 05:08 Re: Unicode support Anoop Kumar <anoopk@pervasive-postgres.com>
2005-08-31 07:19 Re: Unicode support Dave Page <dpage@vale-housing.co.uk>
2005-08-31 08:00 ` Johann Zuschlag <zuschlag2@online.de>
2005-08-31 11:31 Re: Unicode support Dave Page <dpage@vale-housing.co.uk>
2005-08-31 17:52 ` Hiroshi Saito <saito@inetrt.skcapi.co.jp>
2005-08-31 20:00   ` Hiroshi Saito <saito@inetrt.skcapi.co.jp>
2005-09-03 07:23     ` Marko Ristola <Marko.Ristola@kolumbus.fi>
2005-09-03 08:00       ` Marko Ristola <Marko.Ristola@kolumbus.fi>
2005-09-08 17:22       ` Marko Ristola <Marko.Ristola@kolumbus.fi>
2005-09-09 16:40         ` Marko Ristola <marko.ristola@kolumbus.fi>
2005-09-01 09:05 ` Miguel Juan <mjuan@cibal.es>
2005-09-01 10:05 ` Miguel Juan <mjuan@cibal.es>
2005-09-01 09:11 Re: Unicode support Dave Page <dpage@vale-housing.co.uk>
2005-09-01 09:15 Re: Unicode support Dave Page <dpage@vale-housing.co.uk>
2005-09-01 17:20 ` Marko Ristola <Marko.Ristola@kolumbus.fi>
2005-09-01 11:17 Re: Unicode support Dave Page <dpage@vale-housing.co.uk>
2005-09-02 07:50 Re: Unicode support Dave Page <dpage@vale-housing.co.uk>
2005-09-02 10:45 Re: Unicode support Anoop Kumar <anoopk@pervasive-postgres.com>

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