Bug #19017 GetBytes Error
Submitted: 11 Apr 2006 19:35 Modified: 22 May 2006 23:22
Reporter: Charlie Mason
Status: Closed
Category:Connector/Net Severity:S2 (Serious)
Version:1.0.7 OS:Microsoft Windows (XP SP2)
Assigned to: Tonci Grgin Target Version:

[11 Apr 2006 19:35] Charlie Mason
Description:
The bug was discovered whilst reading a simple table which contains a medium blob columb.
When the GetBytes method is called it returns 0 and no data is added column the array even
though the correct file size is passed to it. 

I found a simple work around. Swap the order of the imageSzie and image columns in the
SELECT statement and the indexs on the GetUInt and GetBytes methods. This then appears to
work fine.

This behaviour was also observed using the previous version of the connector 1.0.6. I
assume it is the connector at fault although I am using MYSQL server 4.1.14.

How to repeat:
The below is some c# code which causes no data to be returned, when passed a valid buffer
and length. The tryPrepare and tryExecuteReader are methods which execute the Perpare and
ExecuteReader methods of the MySQLConnection class excepet they add some common error
handeling code.

//Create the db command
            MySqlCommand command = connection.createCommand();

            command.CommandText = "SELECT imageSize, image FROM artwork a WHERE id =
?id";

            if (!connection.tryPrepare(command))
            {
                return new byte[0];
            }

            command.Parameters.Add("?id", artworkID);

            MySqlDataReader reader;

            if (!connection.tryExecuteReader(command, out reader))
            {
                return new byte[0];
            }

            //Read the image data from the database
            if (reader.Read())
            {
                imageSize = reader.GetUInt32(0);
                returnData = new byte[imageSize];
                reader.GetBytes(1, 0, returnData, 0, (int)(imageSize)) ;
            }
            else
            {
                returnData = new byte[0];
            }

            reader.Close();
[18 Apr 2006 17:19] Tonci Grgin
Hi. Thanks for your problem report. A sql script containing data and structure would be
nice. Also some info on server like character sets used. Can you make a small sample
program demonstrating this problem using sql script which you'll provide?
In the meantime, here are some links to check:
http://bugs.mysql.com/bug.php?id=4324
http://bugs.mysql.com/bug.php?id=6323
http://bugs.mysql.com/bug.php?id=7704
http://bugs.mysql.com/bug.php?id=11115
[18 Apr 2006 18:44] Charlie Mason
A c# test case and sql script demonstrating the bug

Attachment: MYSQL Connector Bug Test Case.zip (application/x-zip-compressed, text), 99.46 KiB.

[21 Apr 2006 18:57] Charlie Mason
I have looked at the list of other bugs you supplied. It seems to be unrelated to those as
the symptoms are quite different. Its seems dependent on the oder the blob coloumn appears
in the SELECT satement. 

The test case I uploaded demonstrates both the bug and the work around. I have included
an SQL script to make it very simple to reproduce the bug.
[21 Apr 2006 21:27] Tonci Grgin
Hi. Thanks for great test case. So far I agree with you.
[21 Apr 2006 22:04] Tonci Grgin
Hi Charlie. This turned out to be not BLOB issue at all. Try "ALTER TABLE artwork CHANGE
imageSize imagesize int" (UNSIGNED, NOT NULL as you like) and all works. It seems
mediumint processing is broken. Will investigate further.
[24 Apr 2006 7:04] Tonci Grgin
Verified as described by user using test case provided on latest connector version.
[26 Apr 2006 14:39] Charlie Mason
Thanks for for looking in to the bug. It was the first time I had used the .Net
connector's GetBytes method. For a good 30 mins or so I was somewhat confused, before I
realised it must be a bug. 

I have just used the work around demonstarted in the test case, which seems to be work
fine, after more testing.
[22 May 2006 23:22] Reggie Burnett
Thank you for your bug report. This issue has been committed to our
source repository of that product and will be incorporated into the
next release.

If necessary, you can access the source repository and build the latest
available version, including the bugfix, yourself. More information 
about accessing the source trees is available at
    http://www.mysql.com/doc/en/Installing_source_tree.html

Additional info:

Fixed in 1.0.8