Page 1 of 1
TMemoField and UNICODE
Posted: Mon 26 Jan 2009 18:42
by flashDEVART
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
Posted: Tue 27 Jan 2009 09:52
by Dimon
Please, try to download the latest MyDAC build (5.70.0.44 ) and check if this problem still exists.
Posted: Tue 27 Jan 2009 18:00
by flashDEVART
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?
Posted: Wed 28 Jan 2009 15:10
by Dimon
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
Posted: Wed 28 Jan 2009 17:38
by flashDEVART
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.
Posted: Fri 30 Jan 2009 11:26
by Dimon
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;
Posted: Fri 30 Jan 2009 15:18
by flashDEVART
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?
Posted: Mon 02 Feb 2009 12:07
by Dimon
flashDEVART wrote:PS: Additional 0-byte at work through Streams - this is bug?
Please specify what 0-byte do you mean?
Posted: Mon 02 Feb 2009 17:37
by flashDEVART
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
Posted: Tue 03 Feb 2009 07:38
by Dimon
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.
Posted: Thu 05 Feb 2009 10:55
by flashDEVART
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);
Posted: Fri 06 Feb 2009 08:49
by Dimon
These converts are executed when writing data in internal data structure of TBlob.
Posted: Fri 06 Feb 2009 09:45
by flashDEVART
Dimon wrote:These converts are executed when writing data in internal data structure of TBlob.
Not clearly, but can be....
The problem solved.