1.00.0.3 tpgconnection and unicode database name issue

Discussion of open issues, suggestions and bugs regarding PgDAC (PostgreSQL Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

1.00.0.3 tpgconnection and unicode database name issue

Post by snorkel » Wed 07 Jan 2009 15:52

Hi,
Just a FYI if I set a tpgconnections database property to Россия
or some other unicode text it raises a exception on connect that it cannot find database '?????'

The database was created before hand with create database "Россия"

useunicode is set to true and this is the 1.00.0.3 version released on the 6th.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Thu 08 Jan 2009 09:36

Note that actual database name depends on the encoding of the connection you were using to execute CREATE DATABASE statement.
If this connection has UseUnicode = True, the database is created with UTF8 name. If UseUnicode=False, the name of the database is in the WIN1251 encoding.

There was a bug in the beta version. This version did not convert SQL text to UTF8 before execution. So maybe you need to recreate the database using new PgDAC build.

snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

Post by snorkel » Thu 08 Jan 2009 15:10

Plash wrote:Note that actual database name depends on the encoding of the connection you were using to execute CREATE DATABASE statement.
If this connection has UseUnicode = True, the database is created with UTF8 name. If UseUnicode=False, the name of the database is in the WIN1251 encoding.

There was a bug in the beta version. This version did not convert SQL text to UTF8 before execution. So maybe you need to recreate the database using new PgDAC build.
It was a brand new database created with the current version of PgDAC.
and use unicode was set to true on all tpgconnection components, including the one that created the database, I can fool around with it some more, but I think it's a bug.

snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

Post by snorkel » Thu 08 Jan 2009 16:32

For further testing I created the database with PG Admin III with encoding = UTF8. Then when I use the tpgconnection component from code at runtime it raises the same error.

//all other properties needed to connect are properly set and useunicode is true
myconnection.database:= 'Россия';
myconnection.connected:=true;
( I also tried it with the database name in a edito compoent)

First chance exception at $7D4E2366. Exception class EPgError with message 'database "??????" does not exist'. Process pg_lightning_admin.exe (2900)

This is with the build released the other day (1.00.0.3)

snorkel
Posts: 384
Joined: Tue 08 Aug 2006 15:10
Location: Milwaukee WI USA

Post by snorkel » Thu 08 Jan 2009 20:55

I have been steping throught the code and in PgClasses on line 3552 there seems to be a issue.
for one a normalizename function is being called and it's lowercasing the database name used in the connection, it should be qouted not lowercased.
PostgreSQL lower cases EVERY thing sent to the server, you don't need to lowercase anything on the client.
The next problem is username and password are being converted to AnsiString, this is bad because username and passwords can be Unicode.
Actually all the params being sent to the Fprotocol.Connect method are being forced to ansistring instead of being UTF8 encoded.

The connect function should look like this:

FProtocol.Connect(utf8encode(FServer), Port, FConnectionTimeout,
utf8endode(format('"%s"',[FDatabase]),utf8encode(FUserName), utf8encode(FPassword));

Get rid of that normalize name function, it's not needed for the connection string. PostgreSQL on the server side lowercases everything sent to it, so it's a complete waste of CPU time to lowercase anything. The way case sensitivity works on PostgreSQL is that if you want a name to have upper case chars in iti you have to qoute it with double qoutes, and having the qoutes has no effect if the name is already lowercased.

I am sorry I am being such a pain in the rear, but this really needs to just work. I might be completely wrong on this but the fact is tpgconnection does not work with upper case names or with unicode.

Plash
Devart Team
Posts: 2844
Joined: Wed 10 May 2006 07:09

Post by Plash » Fri 09 Jan 2009 12:01

Please see my reply in the following topic:
http://devart.com/forums/viewtopic.php?t=13835

Post Reply