Page 1 of 1

Unidac Special Characters

Posted: Sat 16 Feb 2013 18:33
by softwestteam
Hi,
I have a problem with TUniSQL component.
I want to insert a string that is encrypted... in a MySQL table but the string is changed.

Text that I want to insert
—•yu¯ÐßÊE<[©su¦¯˜¶•h¡†¥™²­˜¢¶¨zv\¶xi¨ž–ª©h~J—”ž˜—§–hb3{b@o›ÏØÈ›×©ÒÌà˜uk

Text in MySQL DB
—•yuŻĐßĘE<[©su¦Ż˜¶•hˇ†Ą™˛­˜˘¶¨zv\¶xi¨ž–Ş©h~J—”žť˜—§–hb3{b@o›ĎŘțשŇĚŕ˜uk

Some characters are changed ....yu¯ to yuŻ
If I write this string in DB manualy it works ...

I try also with Parameters but is the same result. I changed the connection to UniCode,I try with charset UTF8 but I didn't find a solution.
What I did wrong?

Unidac version is 4.1.3
Delphi 2006

Thanks !

Re: Unidac Special Characters

Posted: Mon 18 Feb 2013 07:20
by CristianP
Hi,

in MySQL I prefer to use BLOB type for raw strings.
And I prefer to use these functions (maybe is not the best way but it works):

Code: Select all

procedure WriteAnsiStringToBlob(AField: TField; s: AnsiString);
var
  strm: TStream;
begin
  strm := AField.DataSet.CreateBlobStream(AField, bmWrite);
  try
    if Length(s) > 0 then
      strm.Write(s[1], Length(s)) else
      strm.Size := 0;
  finally
    strm.Free;
  end;
end;

function ReadAnsiStringFromBlob(AField: TField): AnsiString;
var
  strm: TStream;
begin
  strm := AField.DataSet.CreateBlobStream(AField, bmRead);
  try
    SetLength(Result, TBlobField(AField).BlobSize);
    if TBlobField(AField).BlobSize > 0 then
      strm.Read(Result[1], TBlobField(AField).BlobSize);
  finally
    strm.Free;
  end;
end;
You can use TBytes and read with .AsByte. This is pretty similar with AnsiString I used.
If you use WideString you need to modify the functions accordingly.
If you need more help, please specify your MySQL field type and how do you read and write values.

Best Regards,
Cristian Peţa

Re: Unidac Special Characters

Posted: Tue 19 Feb 2013 13:31
by DemetrionQ
Hello.

The matter is that different applications can work with the DB in different encodings, therefore the same data is displayed in different ways. Please check that the data is really different and this is not the problem with data displaying, for example, by opening the table using the TMyQuery and TMyTable components.

In addition, please specify what do you use to view the table and what do you mean by "write this string in DB manualy".