Bug #91904 SQLBindCol, binding SQL_BIT column to SQL_C_CHAR doesn't work properly
Submitted: 6 Aug 2018 3:47 Modified: 16 Jan 2020 23:36
Reporter: Zhang Garriot Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:8.0.12 OS:Any
Assigned to: CPU Architecture:Any
Tags: driver, ODBC

[6 Aug 2018 3:47] Zhang Garriot
Description:
When binding a SQL_BIT type column to SQL_C_CHAR type, SQLFetchScroll doesn't return data properly. 

Pseudo code: 
... 
SQLCHAR buffer[5][2] = { 0 }; 
SQLBindCol(HSTMT, 1, SQL_C_CHAR, buffer, 2, NULL); 
sqlReturn = SQLFetchScroll(HSTMT, SQL_FETCH_NEXT, 0); 
... 

After SQLFetchScroll, the buffer is filled by integer value 1,0 but not chars value "1", "0".

This code works properly with ODBC driver of other databases, like PostgreSQL and SQL Server.

How to repeat:
MySQL Server: 
MySQL 8.0.12 on Windows. 
MySQL ODBC Driver 8.0 64bit. 

My Table definition: 
CREATE TABLE `bit_test` ( 
`pk` int(10) unsigned NOT NULL AUTO_INCREMENT, 
`col_bit` bit(1) NOT NULL, 
PRIMARY KEY (`pk`), 
UNIQUE KEY `pk_UNIQUE` (`pk`) 
) ENGINE=InnoDB AUTO_INCREMENT=6 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci; 

Data: 
# pk, col_bit 
1, 1 
2, 0 
3, 1 
4, 0 
5, 1 

Pseudo code: 
... 
SQLCHAR buffer[5][1] = { 0 }; 
SQLBindCol(HSTMT, 1, SQL_C_CHAR, buffer, 1, NULL); 
SQLFetchScroll(HSTMT, SQL_FETCH_NEXT, 0); 
... 

When SQLFetchScroll is executed, check the values in the buffer. The buffer is filled with short number 1 and 0. 
It's expected that the buffer should be filled with chars "1" and "0".

Suggested fix:
When binding a SQL_BIT column to SQL_C_CHAR, 1 and 0 should be converted to "1" and "0".
[9 Aug 2018 8:01] Bogdan Degtyariov
Hi Zhang,

Thank you for reporting a problem in ODBC Driver.
The issue is verified and confirmed.
[16 Jan 2020 23:36] Philip Olson
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/ODBC 8.0.20 release, and here's the proposed changelog entry by the documentation team:

When binding an SQL_BIT type column to the SQL_C_CHAR type, SQLFetchScroll
would return the values as an integer instead of a char.

Thank you for the bug report.