TMemoField and UNICODE
-
flashDEVART
- Posts: 8
- Joined: Sat 01 Nov 2008 15:08
TMemoField and UNICODE
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
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
-
flashDEVART
- Posts: 8
- Joined: Sat 01 Nov 2008 15:08
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?
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?
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
Yes, of course.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
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.
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
Yes, this is work as necessary in both directions !!!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;
Thanks
PS: Additional 0-byte at work through Streams - this is bug?
-
flashDEVART
- Posts: 8
- Joined: Sat 01 Nov 2008 15:08
-
flashDEVART
- Posts: 8
- Joined: Sat 01 Nov 2008 15:08
IMHI, It not correct definition, because in TStream I don't work with types "string"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.
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);
-
flashDEVART
- Posts: 8
- Joined: Sat 01 Nov 2008 15:08