TMemoField and UNICODE

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
flashDEVART
Posts: 8
Joined: Sat 01 Nov 2008 15:08

TMemoField and UNICODE

Post by flashDEVART » Mon 26 Jan 2009 18:42

Hello
I have in table field with string in UCS2-format
Field type - TMemoField

How I can get a WideString from this field?


Connection Optons-UseUnicode=True
F.AsString return invalid string
GetData return data with broken first 4 chars

PS
Some like in this link
http://www.devart.com/forums/viewtopic. ... 0649#40649

Test on version 5.50

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 27 Jan 2009 09:52

Please, try to download the latest MyDAC build (5.70.0.44 ) and check if this problem still exists.

flashDEVART
Posts: 8
Joined: Sat 01 Nov 2008 15:08

Post by flashDEVART » Tue 27 Jan 2009 18:00

Hello
With last MyDAC problem still exists.

I made small test project in D7
http://rapidshare.com/files/190260925/ProjectsUCS.rar

PS: Perhaps, this field does not support work with UNICODE.

In this case questions is:
- what other type of field can be used for storage UNICODE data (in my case)?
- whether I can get access to data in this field as a raw-data?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Wed 28 Jan 2009 15:10

In order to keep Unicode data in database you should create a database with utf8 charset, like this:

Code: Select all

CREATE DATABASE test_z CHARACTER SET utf8 COLLATE utf8_general_ci

flashDEVART
Posts: 8
Joined: Sat 01 Nov 2008 15:08

Post by flashDEVART » Wed 28 Jan 2009 17:38

Dimon wrote:In order to keep Unicode data in database you should create a database with utf8 charset, like this:

Code: Select all

CREATE DATABASE test_z CHARACTER SET utf8 COLLATE utf8_general_ci
Yes, of course.

Problem - in other:
- TMemoField don't have methods for work with WideStrings direct;
- when I use method LoadFromStream, physically in data in table after each my byte inserted 0-byte.
Of course, I can use SaveToStream and receive initial data recorded by method LoadFromStream.
But if I already have table with data in UCS format, I cannot receive them correctly: methods LoadFromStream deletes each 2nd byte.

May be, this action - not from MyDAC component, may be this is MySQL server options, but I precisely don't know... :(

PS: Property UseUnicode (from MyDAC) and Transliterate do not give any effect.

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 30 Jan 2009 11:26

In order to solve this problem you should use the TBlob.AsWideString property to assign WideString to the field, like this:

Code: Select all

Blob := MyQuery1.GetBlob(F);
Blob.AsWideString := StrWString;

flashDEVART
Posts: 8
Joined: Sat 01 Nov 2008 15:08

Post by flashDEVART » Fri 30 Jan 2009 15:18

Dimon wrote:In order to solve this problem you should use the TBlob.AsWideString property to assign WideString to the field, like this:

Code: Select all

Blob := MyQuery1.GetBlob(F);
Blob.AsWideString := StrWString;
Yes, this is work as necessary in both directions !!!
Thanks

PS: Additional 0-byte at work through Streams - this is bug?

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Mon 02 Feb 2009 12:07

flashDEVART wrote:PS: Additional 0-byte at work through Streams - this is bug?
Please specify what 0-byte do you mean?

flashDEVART
Posts: 8
Joined: Sat 01 Nov 2008 15:08

Post by flashDEVART » Mon 02 Feb 2009 17:37

Dimon wrote: Please specify what 0-byte do you mean?
Example: I have WideChar value $4401

When I use TStream method:
- when I write this value to DB - in DB I see 44-00-01-00 (after each byte inserted additional byte with 0-value)
- when I use TBlob - in DB I see 44-01

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Tue 03 Feb 2009 07:38

The problem is that when you use TStream Delphi converts WideString to AnsiString and after that it converts this result again to WideString. Therefore you should use the AsWideString property.

flashDEVART
Posts: 8
Joined: Sat 01 Nov 2008 15:08

Post by flashDEVART » Thu 05 Feb 2009 10:55

Dimon wrote:The problem is that when you use TStream Delphi converts WideString to AnsiString and after that it converts this result again to WideString. Therefore you should use the AsWideString property.
IMHI, It not correct definition, because in TStream I don't work with types "string"
or "widestring"

var
strWString:WideString;
F :TMemoField;
......
MS := TMemoryStream.Create;
MS.Write(strWString[1], Length(strWString)*2); // widestring like - row-data
MS.Position :=0;
F.LoadFromStream(MS);

Dimon
Devart Team
Posts: 2910
Joined: Mon 05 Mar 2007 16:32

Post by Dimon » Fri 06 Feb 2009 08:49

These converts are executed when writing data in internal data structure of TBlob.

flashDEVART
Posts: 8
Joined: Sat 01 Nov 2008 15:08

Post by flashDEVART » Fri 06 Feb 2009 09:45

Dimon wrote:These converts are executed when writing data in internal data structure of TBlob.
Not clearly, but can be....
The problem solved.

Post Reply