Firebird 2.1 UTF8 trouble?

Discussion of open issues, suggestions and bugs regarding UniDAC (Universal Data Access Components) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
acastiello
Posts: 7
Joined: Tue 01 Feb 2011 16:21

Firebird 2.1 UTF8 trouble?

Post by acastiello » Tue 01 Feb 2011 16:59

Hi out there,

I´m an old IB/FB wolf but a newie to UniDAC and UTF8. I created (FB 2.1) a database and table like this:

create database 'database.fdb' user 'SYSDBA' password 'masterkey'
page_size 16384
default character set UTF8;

create table USUARIOS (
USUARIO_ID
varchar(20) not null
constraint USUARIOS_PK primary key,
USUARIO_NOMBRE
varchar(80) not null
constraint USUARIO_NOMBRE_BLANCO check (USUARIO_NOMBRE '')
collate UTF8 .........

My connection has the specific options:
InterBase.Charset=UTF-8 (not the Unicode one since I´m using D2007 and don´t want to use WideStrings)

and so, I expect every string read to be converted to AnsiString and every written be converted to UTF8 but that is not working. I´m making wrong assumptions here? If I enter a string like "capitán" in the application I get a malformed string exception, and if I populate the table with an external tool, the string is shown with gibberish (but correct UTF8 encoded) characters

Regards,
Alvaro Castiello

AndreyZ

Post by AndreyZ » Wed 02 Feb 2011 12:02

Hello,

To work with unicode data you should enable unicode support in the following way:

Code: Select all

UniConnection.SpecificOptions.Values['UseUnicode'] := 'True';

acastiello
Posts: 7
Joined: Tue 01 Feb 2011 16:21

Post by acastiello » Wed 02 Feb 2011 17:26

AndreyZ wrote:Hello,

To work with unicode data you should enable unicode support in the following way:

Code: Select all

UniConnection.SpecificOptions.Values['UseUnicode'] := 'True';
Hi Andrey,

When I do that I get a field mistmach exception "actual string expecting widestring". My fields are not TStrngField but a descendant class. Also, does the solution you state implies that database columns should also be wide ones? I´m a little confused here

Note: If I encode/decode the fields by "hand" with AnsiToUTF8 and UTF8ToAnsi in get/set text events everything runs fine but certainly I don´t want to go to set such events to every TmgStringField, and for certain ones I certainly can´t since they have their own context specific get/set

AndreyZ

Post by AndreyZ » Thu 03 Feb 2011 13:12

When the UseUnicode option is set to True, UniDAC creates TWideStingField instead of TStringField. That is why after setting UseUnicode to True, you should remove persistent fields from your datasets and add them again.
Also please look at this topic: http://www.devart.com/forums/viewtopic. ... c&start=15
There you can find more information about unicode usage.

acastiello
Posts: 7
Joined: Tue 01 Feb 2011 16:21

Post by acastiello » Fri 04 Feb 2011 01:54

AndreyZ wrote:When the UseUnicode option is set to True, UniDAC creates TWideStingField instead of TStringField. That is why after setting UseUnicode to True, you should remove persistent fields from your datasets and add them again.
Also please look at this topic: http://www.devart.com/forums/viewtopic. ... c&start=15
There you can find more information about unicode usage.
That´s very bad news since I use a TStringField descendant :( and can not switch to TWideString as such. I suggest in the Santa Box :D to have UTF8 functionallity without the use of wide strings. It could be implemented at the TUniConnection, TUNiTable or TUniQuery level. It can be done as you implied by using get/set text events and UTF8 Delphi support

Regards,
Alvaro

AndreyZ

Post by AndreyZ » Fri 04 Feb 2011 14:31

You are right. If you cannot use TWideStringField (UseUnicode = True), the only solution is to work with the OnGetText and OnSetText event handlers. You can implement this functionality on the persistent fields level and on the TCustomUniDataSet (TUniTable and TUniQuery) level.

Post Reply