Delphi 2005 and Firebird 2.5 utf8 - malformed string

In this forum we will discuss things relating the ZEOSLib 6.6.x stable versions

Moderators: gto, EgonHugeist

Post Reply
RomanV
Fresh Boarder
Fresh Boarder
Posts: 1
Joined: 28.05.2011, 17:39

Delphi 2005 and Firebird 2.5 utf8 - malformed string

Post by RomanV »

Hello,

I have application written in Delphi 2005 (I cannot upgrade into new version right now).

The program works fine with MS Access databases via ADO.
The program is used in several countries.

Now I am porting it into Zeos + Firebird 2.5.

BTW I know that Zeos DBO work with Firebird 2.1. But managed it in this way:
1. I created database file with Firebird 2.1
2. I am using fbclient from Firebird 2.1.
3. But the real DB server is Firebird 2.5.
It works fine.
I am using Firebird 2.5 and not 2.1 because I need some features from v2.5.

But the problem is the different.
For example in old application: Delphi 2005 + ADO + Access
it works fine. For example, in Russia, I can write Russian text from my application and record it into database. The collation works fine.
For example, I may have a table:
COMPANY
companyid: integer
name: varchar(50)

so when I insert two records into it
Test company 1
test company 2

and after the query:
select * from company where name like '%te%'
it returns two records.
note: the text Test company is written in Russian.

But when I use Delphi 2005 + Zeos 6.6+ Firebird 2.5 + database UTF8
after posting the Russian text I get "malformed string" error
because it does not know how to convert Russian text (non unicode) into UTF8.

if i create database with Charset NONE then I can post Russian text into database.
But the example above does not work: it returns only one record.
because in this case.
Firebird's Lower and Upper functions do not work when Charset is NONE for Russian text.

The question is how to achieve the behavior of Delphi 2005 + ADO + Access
so collation works fine and I can insert Russian or any other language text into it.

Now I use ZConnection without any parameters.
I tried different options like

character_set_client=utf8
character_set_connection=utf8
character_set_database=utf8
character_set_results=utf8
character_set_server=utf8
character_set_system=utf8
collation_connection=utf8_general_ci
collation_database=utf8_general_ci
collation_server=utf8_general_ci

Codepage=utf8

Charset=UTF8

But it does not work.

The good article about it is here:
http://www.destructor.de/firebird/charsets.htm
Ideally I need database in utf8 but application should be non-Unicode (written in D2005).

Any feedback would be really appreciated.
trupka
Expert Boarder
Expert Boarder
Posts: 140
Joined: 26.08.2007, 22:10

Post by trupka »

Zconnection codepage param is client codepage so you will need something like:
ZConnection.Params.Add('codepage=win1252')
or, more generic:

Code: Select all

var 
  CPCode: cardinal
  sCP: string;
begin
  cpcode := GetACP();
  case cpcode of
    1250,1251,1252,1256,1258: sCP := 'WIN' +  IntToStr(CPCode);
    some_other ACP:  sCP := 'something'
  else // unsupported encoding
  end;
ZConnection.Properties.Add('codepage=' + sCP);
end
Database is in UTF8.

Try it, works for me.. :-)
btw, Win7 have nasty bug - in some installations you need to adjust regional settings twice and reboot or you end up with wrong CPCode.
Post Reply