Bug #31965 SQLDescribeCol returns a data type of 12 (SQL_VARCHAR) for a VARBINARY column
Submitted: 30 Oct 2007 17:47 Modified: 13 Nov 2007 12:00
Reporter: John Water Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:3.51.20 OS:Microsoft Windows
Assigned to: Jim Winstead CPU Architecture:Any
Tags: ODBC driver, SQLDescribeCol

[30 Oct 2007 17:47] John Water
Description:
It seems there is a bug in SQLDescribeCol in the MySQL ODBC driver 03.51.20 with the MySQL Server 5.1.22. The driver would return a datatype of 12 (SQL_VARCHAR) for a VARBINARY column.

How to repeat:
here is my repro: 

void ShowBug( p_odbc_conn conn ) 
/******************************/ 
{ 
SQLHSTMT stmt; 
RETCODE ret; 
char * drop = "drop table test"; 
char * create = "create table test( pk int primary key, c1 varchar(128), c2 varbinary(128) )"; 
char * insert = "insert into test values( 1,'junk', 0x31323334 )"; 
char * select = "select pk, c1, c2 from test"; 
SQLCHAR name[128]; 
SQLSMALLINT nameLength; 
SQLSMALLINT type; 
SQLUINTEGER size; 
SQLSMALLINT digits; 
SQLSMALLINT nullable; 
SQLSMALLINT ncols = 0; 

ret = SQLAllocHandle( SQL_HANDLE_STMT, conn->dbc, &stmt ); 
_c( conn->info->env, conn->dbc, stmt ); 
ret = SQLExecDirect( stmt, (SQLCHAR *)drop, SQL_NTS ); 
ret = SQLExecDirect( stmt, (SQLCHAR *)create, SQL_NTS ); 
_c( conn->info->env, conn->dbc, stmt ); 
ret = SQLExecDirect( stmt, (SQLCHAR *)insert, SQL_NTS ); 
_c( conn->info->env, conn->dbc, stmt ); 
ret = SQLEndTran( SQL_HANDLE_DBC, conn->dbc, SQL_COMMIT ); 
_c( conn->info->env, conn->dbc, stmt ); 
ret = SQLFreeHandle( SQL_HANDLE_STMT, stmt ); 
ret = SQLAllocHandle( SQL_HANDLE_STMT, conn->dbc, &stmt ); 
_c( conn->info->env, conn->dbc, stmt ); 
ret = SQLPrepare( stmt, (SQLCHAR *)select, SQL_NTS ); 
_c( conn->info->env, conn->dbc, stmt ); 
ret = SQLNumResultCols( stmt, &ncols ); 
_c( conn->info->env, conn->dbc, stmt ); 
printf( "number of result cols = %d\n", ncols ); 
ret = SQLDescribeCol( stmt, 1, name, sizeof( name ), 
&nameLength, &type, &size, &digits, &nullable ); 
printf( "col: name, type, size, digits, null = %s %ld %ld %ld %ld\n", 
name, type, size, digits, nullable ); 
ret = SQLDescribeCol( stmt, 2, name, sizeof( name ), 
&nameLength, &type, &size, &digits, &nullable ); 
printf( "col: name, type, size, digits, null = %s %ld %ld %ld %ld\n", 
name, type, size, digits, nullable ); 
ret = SQLDescribeCol( stmt, 3, name, sizeof( name ), 
&nameLength, &type, &size, &digits, &nullable ); 
printf( "col: name, type, size, digits, null = %s %ld %ld %ld %ld\n", 
name, type, size, digits, nullable ); 
ret = SQLExecute( stmt ); 
_c( conn->info->env, conn->dbc, stmt ); 
ret = SQLEndTran( SQL_HANDLE_DBC, conn->dbc, SQL_COMMIT ); 
_c( conn->info->env, conn->dbc, stmt ); 
ret = SQLFreeHandle( SQL_HANDLE_STMT, stmt ); 
done: 
return; 
} 

It should return -3 (SQL_VARBINARY). Is it possible to fix this bug in the next release?
[30 Oct 2007 18:41] Susanne Ebrecht
Hello John,

thank you for reporting a bug.

This could be a duplicate of bug #28820.
We will check this.

Many thanks for trusting MySQL.
Please try also our new version MyODBC v5.1.

Kind Regards,

Susanne
[5 Nov 2007 19:53] Jim Winstead
This is due to the workaround in place for Bug #10491. This server bug is now fixed, so we can remove the workaround.
[5 Nov 2007 20:00] Jim Winstead
Remove workaround for Bug #10491

Attachment: bug31965.patch (text/plain), 1.86 KiB.

[8 Nov 2007 18:50] Jim Winstead
The workaround for bug #10491 has been removed, and this will be fixed in the next 3.51 release (3.51.22).
[13 Nov 2007 12:00] MC Brown
This has already been documented as part of the changelog entry for 10491.