MySqlLoader and binary data

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for MySQL
Post Reply
SquishyZA
Posts: 6
Joined: Tue 30 Jun 2020 15:34

MySqlLoader and binary data

Post by SquishyZA » Tue 30 Jun 2020 15:57

I am using MySqlLoader to load a large number of rows into a table and the performance is awesome, but it does not seem to handle binary data properly.

I followed the example from the documentation.

Some pseudo code to illustrate:

Var loader = new MySqlLoader(...);
Loader.CreateColumns();
Loader.Open();
Foreach (var item in distinctItems)
{
loader.SetValue(“Size”, item.Size); // item.Size is a long
loader.SetValue(“Data”, item.Data); // item.Data is a byte[16]
loader.NextRow();
}
loader.Close();

What I observe:
1. Item.Data is truncated to 13 bytes on the first loop, most likely because it is not properly escaped. But I don’t see a way to escape it.
2. On the next loop the “Data” column is not updated so it properly inserts rows with new “Size” values but all the “Data” values matches the first row value

I tried representing item.Data as “X’[hex representation of item.Data]’” but that complained about the string being too long.

Any ideas would be appreciated.

Thank you

SquishyZA
Posts: 6
Joined: Tue 30 Jun 2020 15:34

Re: MySqlLoader and binary data

Post by SquishyZA » Wed 01 Jul 2020 16:01

More information. So it is not actually truncating the binary data. It is storing the string ‘System.byte[]’ as bytes. I assume it is just doing a item.Data.ToString() type conversion.

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: MySqlLoader and binary data

Post by Shalex » Tue 07 Jul 2020 17:34

Specify the datatype of your Data column.

If it is BINARY or VARBINARY, try using MySqlBinaryString:

Code: Select all

    loader.SetValue("Data", new MySqlBinaryString(item.Data));
Does this help?

SquishyZA
Posts: 6
Joined: Tue 30 Jun 2020 15:34

Re: MySqlLoader and binary data

Post by SquishyZA » Wed 15 Jul 2020 16:03

Thank you, it did work.

Post Reply