Delphi XE and SQLite and Chinese character

The alpha/beta tester's forum for ZeosLib 7.0.x series

Report problems concerning our Delphi 2009+ version and new Zeoslib 7.0 features here.

This is a forum that will be removed once the 7.X version goes into stable!!

Moderators: gto, EgonHugeist, olehs

Locked
mmvisual
Senior Boarder
Senior Boarder
Posts: 51
Joined: 13.10.2010, 14:55

Delphi XE and SQLite and Chinese character

Post by mmvisual »

Hello,

I have load the last SVN 966 and I want use SQLite.
But the problem, the database store the chinese characters not.

I use Delphi XE, in the Label can I see a text whith chinese characters.

When I edit a table and insert a chinese text and post it, then I see the chinese text, too.

But when I close the conection and reopen the table, then I see only "???" characters.

When I use MySQL, then it works fine, but not with SQLite.

When I use this characters ążł then zeos convert it to azl.

Can you help me, please :?:
I have search in this forum, but no solution found.

PS: I use WinXP and have install a font "Arial Unicode MS" with the included characters.

Regards, Markus.
You do not have the required permissions to view the files attached to this post.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

mmvisual,

could you be so kind and post your How-It-Works-with-MySQL-way too?
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
mmvisual
Senior Boarder
Senior Boarder
Posts: 51
Joined: 13.10.2010, 14:55

Post by mmvisual »

With phpMyAdmin, create an new database with kollation "utf8_unicode_ci" and then make your tables.

In Delphi:
Use my demo, last posting, and set User, Passwort, Port=3306, Database, Host.
Set the protocol to"mysql-5".

Finish.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

Found "Bezeichnung": aha du bist ein Deutscher, grins...


mmvisual, i've check your example-project:

First:

procedure TForm1.FormCreate(Sender: TObject);
begin

ZQuery1.SQL.Text := 'PRAGMA encoding = "UTF-8";'; -> use this in your TZConnection.Poperties...
ZQuery1.ExecSQL;

Second: These paramteters you also have to set in mysql... So i wonder why it works. In your example-project the Field-assigning of your Label1.Caption is missed...

Um dir auf die Sprünge zu helfen.. (Brain.Upgrade...)

schau mal hier (look here ) http://zeos.firmos.at/viewtopic.php?t=3367
and http://zeos.firmos.at/viewtopic.php?p=13640#13640

Some of your chinese letters work and others actually not....

The workaround you need := SQL := SQL + String(Ansistring(UTF8Encode(YourParam))); or use Params :s which solve this yet..
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
mmvisual
Senior Boarder
Senior Boarder
Posts: 51
Joined: 13.10.2010, 14:55

Post by mmvisual »

Ja, ich bin ein deutscher und mein englisch ist eher denglisch.

Yes, sorry. No extra parameter for MySQL. Use a new TZConnection and set this parameters. Then a TZQuery with "SELECT * FROM <your_table>".
No extra Execute, no extra parameters and properties in TZConnection and TZQuery.

The Zeos/SQLite working only right with chinese charactes when I using Lazarus and Linux!
So, it is not a problem from SQLite, only from Zeos with Delphi.

The Zeos/SQLite/Lazarus/Windows can store the caracters ąłż, and Delphi cannot (the result is then: alz).

I think there is a problem with the convertions between PAnsiChar and PWideChar and Delphi make automaticly a conversion, at storing in the database. SQLite have all DLL routines with "Ansi" and "WideString", I think there must be used the Wide vatiant.

I have see the other (old) threads, but, there gives no "easy to use" solution.
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

mmvisual,
mein englisch ist eher denglisch.
muhaha handshake!

look at
http://zeos.firmos.at/viewtopic.php?t=2 ... c&start=45

read carefully... It exactly discribes the problem, and what has to be done. You are right in case of delphi-using. But this problem accours only since version 2009 and it seems you are using XE or am i wrong?

It's a known problem resulting of mixing 1-Byte-Chars(the dll's Zeos is using for DB-accessing) and Delphi12_up varying-chars(up to 4 Byte per Char on some special chars)

So what can you do to work with 7.0.x Alpha in a save way: use Parameter-Queries. The parameter automalicaly do that utf8-Encoding..

regards der Egon
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
mmvisual
Senior Boarder
Senior Boarder
Posts: 51
Joined: 13.10.2010, 14:55

Post by mmvisual »

No, I want not use Parameter Queries. I want use a Query with DataSource and a Grid. Then edit / write my texts into the grid and post the changes. (One code line TZQuery.Post;)

I have set the Properties "codepage=UTF8" in TZConnection and TZQuery, but it do not work, have no result.

Yes, I have DelphiXE.
Your links showing for a description for MySQL, but my problem is with SQLite.

Can you store with my EXE (Test, see top) this characters "言順要レ" into the SQLite database?
When yes, and you have make a change, can you post the new sources, please?
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

These are Parameter-Statement-Queries, so i wonder why it happens. Did somebody forgot the UTF8Encodung of the vtUnicodeString in SQLLite? so check your pn i'll help you in german.
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
User avatar
EgonHugeist
Zeos Project Manager
Zeos Project Manager
Posts: 1936
Joined: 31.03.2011, 22:38

Post by EgonHugeist »

Yesterday, me and mmvisual,

did some debugging to solve his problem. We've some findings:

function ConvertSQLiteTypeToSQLType(TypeName: string; var Precision: Integer;
var Decimals: Integer): TZSQLType;

else if TypeName = 'VARCHAR' then
Result := {$IFDEF DELPHI12_UP}stUnicodeString{$ELSE}stString{$ENDIF} was missed so

the GetUnicodeString(..): WideString function for the IZResultSet/RowAccesor was never called.

So using stString insteat of stUnicodeString means that the TRowAccessor lost the Character-informations resulting of SetString(Value: AnsiString).

So w've changed the line in ZdbcSQLLiteUtils like above. The RowAccessor and ResultSets now uses the right Setter&Getter-Functions. Now we've the next Problem: ZQuery.Insert fails. I've checked out what happens:

InternalPost:
the Metadata lost now his informations. So the GenericResolver could not assamble the right insert-query. No more fieldnames or table-name where aviable now.

Is there somebody who knows why this happens? Reverting to Result := stString; and everything is fine, but like i said by using chinese or russian letters the Character-informations where lost and each "special"-Char changes to "?";

Regards
Best regards, Michael

You want to help? http://zeoslib.sourceforge.net/viewtopic.php?f=4&t=3671
You found a (possible) bug? Use the new bugtracker dude! http://sourceforge.net/p/zeoslib/tickets/

Image
Locked