BLOB conversion when SaveToXML

Discussion of open issues, suggestions and bugs regarding MyDAC (Data Access Components for MySQL) for Delphi, C++Builder, Lazarus (and FPC)
Post Reply
rahucha
Posts: 24
Joined: Tue 18 Nov 2014 09:52

BLOB conversion when SaveToXML

Post by rahucha » Thu 20 Nov 2014 11:46

Hi,

I have a BLOB field in my table and I'm using TMyQuery.SaveToXML. The information in my BLOB field (MyField) is for example the string "Hello" and it's stored in the XML file as:

MyField="48656C6C6F"

(It seems that it's converting it to its hex ASCII char as string)

Anyway, at a later time I export from XML to my database (using "LOAD XML LOCAL INFILE....") and I get in "MyField" BLOB the content: 48656C6C6F (instead of the original string "Hello").

Is there any special parameter to read back the expected BLOB field string?

Thanks!

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: BLOB conversion when SaveToXML

Post by ViktorV » Fri 21 Nov 2014 05:25

Thank you for the information. We will investigate the reason for such behavior.
As a workaround, you can map data with such types using 'Field Name' of the needed columns.
Example:

Code: Select all

MyQuery1.DataTypeMap.AddFieldNameRule(FieldName, ftWideString);
More details about Data Type Mapping can be found in the MyDAC documentation: http://www.devart.com/mydac/docs/data_type_mapping.htm

rahucha
Posts: 24
Joined: Tue 18 Nov 2014 09:52

Re: BLOB conversion when SaveToXML

Post by rahucha » Fri 21 Nov 2014 11:46

Hi Viktor,

Thanks for the reply. That fixes the problem in a specific BLOB field that I have (where I just contain ASCII chars)

But I still have a problem where I have another BLOB field which contains HEX data (bytes for an image). I understand that you store the BLOB field as each HEX byte converted into ASCII (two bytes).

The problem is when I restore from the XML, the BLOB is not read correctly by "LOAD XML LOCALFILE....". So, it seems that MySQL is waiting for a different format for BLOB fields?

Thanks!

rahucha
Posts: 24
Joined: Tue 18 Nov 2014 09:52

Re: BLOB conversion when SaveToXML

Post by rahucha » Fri 21 Nov 2014 20:41

Hi Viktor,

I have used a workaround and after loading the BLOB fields into the table from the XML file, I have converted your string "hex" format into binary data (using a TStream) and it worked fine.

I'm good with that :)

Thanks

ViktorV
Devart Team
Posts: 3168
Joined: Wed 30 Jul 2014 07:16

Re: BLOB conversion when SaveToXML

Post by ViktorV » Tue 30 Dec 2014 11:56

We have added the TMyDataSetOptions.SaveBlobsAsHex property. Setting it to False you will be able to save the value of the BLOB field as string. We plan to release the new version of MyDAC within 2 weeks.

Post Reply