UTF8 encoding error

Discussion of open issues, suggestions and bugs regarding usage of dbExpress drivers for PostgreSQL in Delphi and C++Builder
Post Reply
fvwendt
Posts: 2
Joined: Mon 27 Jul 2009 19:42

UTF8 encoding error

Post by fvwendt » Mon 27 Jul 2009 20:29

Hi,

I've installed dbxpgsql100.exe, version 1.0.0.4, to be used with BDS 2006.
But I'm having problems when I try to execute a SELECT statement using accentuated parameters, as in the example below:
SQLQuery.SQL.Text := 'SELECT cod_bairro FROM bairro WHERE descricao = ' + QuotedStr('Universitário');
SQLQuery.Open;


When this TSQLQuery component try to open a dataset, an exception is raised:
Database Server Error: invalid byte sequence for encoding "UTF8": 0xe17269

But if I execute the following statement:
SQLQuery.SQL.Text := 'SELECT cod_bairro FROM bairro WHERE descricao = ' + QuotedStr('Universitario');
SQLQuery.Open;


No problem happens. As you can see, I've just replaced the parameter value "Universitário" to "Universitario".

My database was created using UTF8 encoding.
How can I solve this problem?

Fabrício

fvwendt
Posts: 2
Joined: Mon 27 Jul 2009 19:42

Post by fvwendt » Mon 03 Aug 2009 17:02

The following code solves this problem:

const
coUseUnicode = TSQLConnectionOption(209); // boolean
...
SQLConnection1.Connected := True;
SQLConnection1.SQLConnection.SetOption(coUseUnicode, Integer(True));
...

It only works calling SQLConnection1.SQLConnection.SetOption method after connecting to database.

Fabrício

Post Reply