Hi to you all.
I'm writing an application with a firebird 2.1 database with utf8 char set.
I use Delphi 2009 and I'm getting strange characters in my fields when I use Zeos TRUNK REV803.
I created my database with UTF8 code page and one table that have a varchar field and I can insert data in it using SQL Manager Lite from EMS using arabic characters.
I made a little application and I put codepage=UTF8 in the properties field of mu connection and, after I connect to that database, if I try to insert data with my application using Zeos connection I get a lot of '?' in my field.
When I display the record inserted manually with sql manager I see strange characters in that field.
I added to my form a label and trigged the TDBedit OnChange event and I set the caption of the label to the contete of the field using
Label1.Caption := UTF8ToWideString((sender as TDBEdit).text);
I get the label displaying the right characters.
What I'm doing wrong?
Thanks
Any idea?
Delphi 2009 With firebird 2.1 and UTF8
Moderators: gto, EgonHugeist, olehs
I'm making some debug and I tried to use a TZQuery component to insert some data directly addig arabic string in it and IT WORKS!!!
I use the ExecSQL procedure to execute
INSERT INTO LANGUAGES VALUES (-1,'انجليزي')
and the record was inserted in the database without any problem.
I hope this may help.
Thanks
I use the ExecSQL procedure to execute
INSERT INTO LANGUAGES VALUES (-1,'انجليزي')
and the record was inserted in the database without any problem.
I hope this may help.
Thanks
You do too much, what you do wrong is that tdbedit.text already is unicodestring (UTF16, like widestring). The utf8 conversion is not necessary.
The codepage=utf8 cshould already let Zeos do this translation (utf8 on the "wire" to utf16 in dbedit.text).
The only thing to check is that all your memo fields are tdbwidememo, not tdbmemo, see the last post in http://zeos.firmos.at/viewtopic.php?t=2580
p.s. I set client_encoding:=utf8 too. I don't know which one of these two (codepage, client_encoding) does what exactly, but it works fine.
The codepage=utf8 cshould already let Zeos do this translation (utf8 on the "wire" to utf16 in dbedit.text).
The only thing to check is that all your memo fields are tdbwidememo, not tdbmemo, see the last post in http://zeos.firmos.at/viewtopic.php?t=2580
p.s. I set client_encoding:=utf8 too. I don't know which one of these two (codepage, client_encoding) does what exactly, but it works fine.
I made some debug and I found that if I replace line 1357 of the file
that looks like this
WStrCopy(Buffer, PWideChar(RowAccessor.GetUnicodeString(ColumnIndex, Result)));
by this one
WStrCopy(Buffer, PWideChar(UTF8Decode(PAnsiChar(Utf8ToAnsiEx(RowAccessor.GetUnicodeString(ColumnIndex, Result),1252)))));
I get the fields displayed well.
I will try to make other experiments hoping this may help.
that looks like this
WStrCopy(Buffer, PWideChar(RowAccessor.GetUnicodeString(ColumnIndex, Result)));
by this one
WStrCopy(Buffer, PWideChar(UTF8Decode(PAnsiChar(Utf8ToAnsiEx(RowAccessor.GetUnicodeString(ColumnIndex, Result),1252)))));
I get the fields displayed well.
I will try to make other experiments hoping this may help.
Hi to all,
Since I noticed a similar question about UTF8 and My sql
(look here http://zeos.firmos.at/viewtopic.php?t=2652)
I made some debug for both databases (MySql and Firebird) and I
found some solutions for it with delphi 2009.
There is a common part in the above post that works also for Interbase/firebird.
Here below what code I modified to be able to write to database UTF8 strings.
1- In the ZDbcInterbase6Utils within the IZParamsSQLDA class definition (line 131) unit I changed the following line
To
The same thing shall be done in the TZParamsSQLDA class definition and implementation.
2- In the TZParamsSQLDA.UpdateString implementation I changed
to
This enabled me to write and read UTF8 strings withou any problem.
Please look at the other post for the other modifications to make.
Since I noticed a similar question about UTF8 and My sql
(look here http://zeos.firmos.at/viewtopic.php?t=2652)
I made some debug for both databases (MySql and Firebird) and I
found some solutions for it with delphi 2009.
There is a common part in the above post that works also for Interbase/firebird.
Here below what code I modified to be able to write to database UTF8 strings.
1- In the ZDbcInterbase6Utils within the IZParamsSQLDA class definition (line 131) unit I changed the following line
Code: Select all
procedure UpdateString(const Index: Integer; Value: AnsiString);
To
Code: Select all
{$IFDEF DELPHI12_UP}
procedure UpdateString(const Index: Integer; Value: WideString{AnsiString});
{$ELSE}
procedure UpdateString(const Index: Integer; Value: AnsiString);
{$ENDIF}
2- In the TZParamsSQLDA.UpdateString implementation I changed
Code: Select all
SQL_TEXT : EncodeString(SQL_TEXT, Index, Value);
SQL_VARYING : EncodeString(SQL_VARYING, Index, Value);
SQL_TYPE_DATE : EncodeString(SQL_DATE, Index, Value);
Code: Select all
{$IFDEF DELPHI12_UP}
SQL_TEXT : EncodeString(SQL_TEXT, Index, PAnsiChar(UTF8String(Value)));
SQL_VARYING : EncodeString(SQL_VARYING, Index, PAnsiChar(UTF8String(Value)));
SQL_LONG: PInteger(sqldata)^ := StrToInt(Value);
{$ELSE}
SQL_TEXT : EncodeString(SQL_TEXT, Index, Value);
SQL_VARYING : EncodeString(SQL_VARYING, Index, Value);
SQL_TYPE_DATE : EncodeString(SQL_DATE, Index, Value);
{$ENDIF}
Please look at the other post for the other modifications to make.