Bug #36373 Incorrect BLOB field mapping in ADO
Submitted: 28 Apr 2008 12:00 Modified: 28 Apr 2008 13:26
Reporter: einars matjusenoks Email Updates:
Status: Unsupported Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:3.51.25 OS:Windows (XP SP2)
Assigned to: CPU Architecture:Any
Tags: ADO, BLOB

[28 Apr 2008 12:00] einars matjusenoks
Description:
Using MySQL server 4.0.21 and Visual Basic 6 I can't bind MEDIUMBLOB field (where I store picture) to picture box control. I get message 'Unable to bind to field or DataMember:'FieldName''. If I look at field properties in DataEnvironment, I see that there are data type adLongVarChar.
With MyODBC driver version 3.51.06 binding are correct - DataEnvironment shows field data type adLongVarBinary.

How to repeat:
Create table:
CREATE TABLE `images` (
  `RecID` varchar(10) NOT NULL default '',
  `Image` mediumblob NOT NULL,
  `User` varchar(16) NOT NULL default '',
  `Laiks` timestamp(14) NOT NULL,
  PRIMARY KEY  (`RecID`)
) TYPE=MyISAM; 

Create new data project in VB6.
In DataEnvironment's Connection1 add connection string: 
'Driver={mySQL ODBC 3.51 driver};Server=SERVER_IP;Port=3306;Option=1 + 2 + 32 + 16384;Stmt=;Database=DBNAME;Uid=;Data Provider=MSDASQL.1'
Add command to Connection1:
'select * from images'

Look at field 'Image' properties.

Suggested fix:
BLOB fields should be mapped as adLongVarBinary.
[28 Apr 2008 13:26] Tonci Grgin
Hi Einars and thanks for your report.

You are right, I got -1 (SQL_LONGVARCHAR) instead of -4 (SQL_LONGVARBINARY) using your sample table. But, quoting the manual, 4.0 is not supported any more:
MySQL Connector/ODBC 3.51.25, a new version of the ODBC driver for the MySQL database management system, has been released. This release is the latest release of the 3.51 series and is suitable for use with any MySQL version including MySQL 4.1, 5.0, or 5.1.

mysql> CREATE TABLE `images` (
    ->   `RecID` varchar(10) NOT NULL default '',
    ->   `Image` mediumblob NOT NULL,
    ->   `User` varchar(16) NOT NULL default '',
    ->   `Laiks` timestamp(14) NOT NULL,
    ->   PRIMARY KEY  (`RecID`)
    -> ) TYPE=MyISAM;
Query OK, 0 rows affected (0.08 sec)

Server version: 4.0.30-nt-max-log
SQLColumns(test, test, images, NULL) produces:
Get Data All:
"TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE"
"test", <Null>, "images", "RecID", 12, "varchar", 10, 10, <Null>, <Null>, 0, "", <Null>, 12, <Null>, 10, 1, "NO"
"test", <Null>, "images", "Image", -1, "text", 16777215, 16777215, <Null>, <Null>, 0, "", <Null>, -1, <Null>, 16777215, 2, "NO"  <<<<<<<
"test", <Null>, "images", "User", 12, "varchar", 16, 16, <Null>, <Null>, 0, "", <Null>, 12, <Null>, 16, 3, "NO"
"test", <Null>, "images", "Laiks", 93, "timestamp", 19, 16, 0, 10, 1, "", <Null>, 9, 93, <Null>, 4, "YES"
4 rows fetched from 18 columns.

MySQL server 4.1.22:
Get Data All:
"TABLE_CAT", "TABLE_SCHEM", "TABLE_NAME", "COLUMN_NAME", "DATA_TYPE", "TYPE_NAME", "COLUMN_SIZE", "BUFFER_LENGTH", "DECIMAL_DIGITS", "NUM_PREC_RADIX", "NULLABLE", "REMARKS", "COLUMN_DEF", "SQL_DATA_TYPE", "SQL_DATETIME_SUB", "CHAR_OCTET_LENGTH", "ORDINAL_POSITION", "IS_NULLABLE"
"test", <Null>, "images", "RecID", 12, "varchar", 10, 10, <Null>, <Null>, 0, "", <Null>, 12, <Null>, 10, 1, "NO"
"test", <Null>, "images", "Image", -4, "blob", 16777215, 16777215, <Null>, <Null>, 0, "", <Null>, -4, <Null>, 16777215, 2, "NO"
"test", <Null>, "images", "User", 12, "varchar", 16, 16, <Null>, <Null>, 0, "", <Null>, 12, <Null>, 16, 3, "NO"
"test", <Null>, "images", "Laiks", 93, "timestamp", 19, 16, 0, 10, 1, "", <Null>, 9, 93, <Null>, 4, "YES"
4 rows fetched from 18 columns.

Please upgrade your MySQL server.
[2 Jun 2008 8:12] Tonci Grgin
Bug#37127 was marked as duplicate of this report.