Bug #108434 SQLGetData return wrong value when using with SQLBindParameter
Submitted: 8 Sep 2022 16:06 Modified: 19 Apr 2024 18:15
Reporter: Mingwei Liu Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / ODBC Severity:S2 (Serious)
Version:8.0.30 OS:Windows
Assigned to: CPU Architecture:Any

[8 Sep 2022 16:06] Mingwei Liu
Description:
SQLGetData return wrong value for blob columns when binding a parameter in the WHERE clause with SQLBindParameter.

How to repeat:
#1. Generate data using following code:

CREATE SCHEMA `mytestdb1`;
CREATE TABLE `mytestdb1`.`mytesttable1` (
  `myint1` INT NOT NULL,
  `mybinary1` BINARY(2) NULL,
  `myblob1` BLOB NULL,
  PRIMARY KEY (`myint1`));
INSERT INTO `mytestdb1`.`mytesttable1` (`myint1`, `mybinary1`, `myblob1`) VALUES ('1', '11', '11');
INSERT INTO `mytestdb1`.`mytesttable1` (`myint1`, `mybinary1`, `myblob1`) VALUES ('2', '', '');
INSERT INTO `mytestdb1`.`mytesttable1` (`myint1`, `mybinary1`, `myblob1`) VALUES ('3', '33', '33');
INSERT INTO `mytestdb1`.`mytesttable1` (`myint1`, `mybinary1`, `myblob1`) VALUES ('4', '', '');
INSERT INTO `mytestdb1`.`mytesttable1` (`myint1`, `mybinary1`, `myblob1`) VALUES ('5', '', '');

#2. Using query 

SELECT * FROM mytestdb1.mytesttable1 WHERE myint1 >= ?

SQLPrepare the query, then SQLBindParameter to 0.

The results of SQLGetData is 

"myint1", "mybinary1", "myblob1"
1, 0x3131, 0x3131
2, 0x0000, 0x3131
3, 0x3333, 0x3333
4, 0x0000, 0x3333
5, 0x0000, 0x3333

But I'd expect the result of "myblob1" on 2nd, 4th and 5th to be 0x.

#3. SQLGetData will return different results for "myblob1", if you change the parameter value set in SQLBindParameter in #2 to 2 or 3 or 4.
[25 Nov 2022 12:15] MySQL Verification Team
Hello Mingwei Liu,

Thank you for the bug report.
Could you please provide repeatable test case (sample project, etc. - please make it as private if you prefer) to confirm this issue at our end?

Regards,
Ashwini Patil
[28 Nov 2022 18:09] Mingwei Liu
Hi Ashwini,

I generated the table and data using code in my Step #1 in the "How to repeat" section. Then tested in Microsoft® ODBC Test application (Unicode, amd64) following my Step #2 and was able to see the problem in Step #3.

Thanks!
Mingwei
[8 Apr 2024 13:04] MySQL Verification Team
Hello Mingwei Liu,

Thank you for the details. However this is not enough to reproduce the issue.
Please upgrade to latest version and report us back if issue persist even in latest version along with test case. Thank you.

Regards,
Ashwini Patil
[19 Apr 2024 18:15] Mingwei Liu
Hi Ashwini,

I've tried using the latest generally released connector (MySQL ODBC 8.3 Unicode Driver, version 8.03.00.00) but can still see the problem.

For your convenience, I attached the log from Microsoft® ODBC Test application (Unicode, amd64) when I saw the issue:

Full Connect(Default)

	Env. Attr. SQL_ATTR_ODBC_VERSION set to SQL_OV_ODBC3

	Successfully connected to DSN 'MySQL8.3DSN'.

SQLPrepare:
				In:				StatementHandle = 0x00000000024A5430, StatementText = "SELECT * FROM mytestdb1.mytesttable1 WHERE myint1 ...", TextLength = 54
				Return:	SQL_SUCCESS=0
SQLBindParameter:
				In:				StatementHandle = 0x00000000024A5430, ParameterNumber = 1, InputOutputtype = SQL_PARAM_INPUT=1, ValueType = SQL_C_CHAR=1, 
										ParameterType = SQL_CHAR=1, ColumnSize = 0, DecimalDigits = 0, ParameterValuePtr = "", BufferLength = 0, StrLen_or_IndPtr = 0x00000000005D94D0, SQL_LEN_DATA_AT_EXEC = FALSE, 
										Buffer Size = 600
				Return:	SQL_SUCCESS=0

SQLExecute:
				In:				StatementHandle = 0x00000000024A5430
				Return:	SQL_SUCCESS=0

Get Data All:
"myint1", "mybinary1", "myblob1"
1, 0x3131, 0x3131
2, 0x0000, 0x3131
3, 0x3333, 0x3333
4, 0x0000, 0x3333
5, 0x0000, 0x3333
5 rows fetched from 3 columns.

Thanks!