Bug #11040 Problem with ADO and blob fields
Submitted: 2 Jun 2005 15:23 Modified: 20 Jun 2005 7:06
Reporter: Jod75 Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:3.51.11 OS:Windows (WindowsXP)
Assigned to: CPU Architecture:Any

[2 Jun 2005 15:23] Jod75
Description:
I am using Microsoft OLE DB Provider for ODBC and MyODBC v3.51.11 to read/write binary data to MySQL (v5.0.6-beta-nt) table.  When I read the size of the field using ActualSize() method, only the number of bytes until the first NULL character in the binary field is read - hence return invalid size.  The same applies for GetChunk() and AppendChunk().

Please advise

Thank you

How to repeat:
Add a binary image such as jpeg image to a longblob field.

Read a record set containing a binary image with null characters (0x0) and use the ActualSize() method on the blob field.

The return value will be the number characters before the first 0x0 character.
[2 Jun 2005 15:33] Jorge del Conde
Hi,

Can you please provide us with  a test case that reproduces this behaviour ?

Thanks
[3 Jun 2005 7:27] Jod75
As a test case you can use the source code found at http://msdn.microsoft.com/library/default.asp?url=/library/en-us/ado270/htm/mdmthappendchu....

You have to change the connection string to "dsn=MyODBCTestConnection", where MyODBCTestConnection is an ODBC data source.  Lets say that the data source connects to the test database, then in the test database create a table called pub_info as follows:

CREATE TABLE `pub_info` (
  `pub_id` char(4) NOT NULL,
  `logo` longblob,
  `pr_info` text,
  PRIMARY KEY  (`pub_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;

Add a record to the table, eg:
insert into pub_info values('1', load_file('/pics/picture1.jpg'), 'Sample image');

Remove the code:
//Delete new record because this is demonstration.
pConnection->Execute("DELETE FROM PUB_INFO WHERE pub_id = '"
                        + strPubID +"'",NULL,adCmdText);

from the above program so that the newly created record will not be deleted.  Once ready, compile and execute the program.  Observe the contents of the newly created LongBlob field and you should find that only the characters before the first occurance of a null character (0x00) are copied.  If you place a breakpoint at the line 
lngLogoSize = pRstPubInfo->Fields->Item["logo"]->ActualSize;
and check the value of lngLogoSize, it will show the incorrect blob field size.  Further analysis shows that GetChunk() has the same problem, perheps it is using the same code as ActualSize().

Regards,
jod75
[3 Jun 2005 8:18] Vasily Kishkin
Probably it's server bug. 

mysql> insert into pub_info values('1', load_file('F://1.jpg'), 'Sample image');

Query OK, 1 row affected, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+--------------------------------------------------------------
------------------+
| Level   | Code | Message
                  |
+---------+------+--------------------------------------------------------------
------------------+
| Warning | 1301 | Result of load_file() was larger than max_allowed_packet (104
8576) - truncated |
+---------+------+--------------------------------------------------------------
------------------+
1 row in set (0.00 sec)

mysql> select * from pub_info;
+--------+------+--------------+
| pub_id | logo | pr_info      |
+--------+------+--------------+
| 1      | NULL | Sample image |
+--------+------+--------------+
1 row in set (0.00 sec)

There is not data of image in .MYD file.
I attached files of table
[3 Jun 2005 8:20] Vasily Kishkin
data files of table

Attachment: pub.zip (application/x-zip-compressed, text), 713 bytes.

[7 Jun 2005 18:25] Jim Winstead
No, you have not demonstrated this is a server bug -- the warning clearly indicates that your test has tried to insert a BLOB that is larger than you have configured max_allowed_packet, but the original bug report is that partial data gets inserted through ODBC.

Please try to verify the bug as it was reported.

Thanks.
[13 Jun 2005 6:24] Vasily Kishkin
Sorry for my mistake. Ok...I could't find the test case because  probably you wrote wrong URL. Could you please correct the URL or attach this file ?
[13 Jun 2005 9:02] Jod75
I checked the URL and it is correct.  Please note that it wraps to the next line.
[20 Jun 2005 7:06] Vasily Kishkin
I was not able to reproduce the bug. The program deleted new records correctly. The size of blob was calculated right. I attached test case.
[20 Jun 2005 7:06] Vasily Kishkin
Test case

Attachment: AppendChunk.cpp (text/plain), 8.76 KiB.

[20 Jun 2005 7:07] Vasily Kishkin
Test case

Attachment: AppendChunk.h (text/plain), 570 bytes.

[20 Jun 2005 8:17] Jod75
Can you please attach the file that is saved in the original blob field?  If you remove the 'delete part' of the program, would the newly copied file be valid?  What are the values of lngLogoSize variable when reading the blob field with the file that you are attaching?  What versions are you using?

Thank you