UTF8 encoding error

UTF8 encoding error

Postby 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

Postby 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
fvwendt
 
Posts: 2
Joined: Mon 27 Jul 2009 19:42


Return to dbExpress driver for PostgreSQL