Bug #96201 fetch data wrong under windows when table has longtext column
Submitted: 14 Jul 2019 9:30 Modified: 12 Dec 2019 10:19
Reporter: fnzh fnzh Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / ODBC Severity:S3 (Non-critical)
Version:8.0.16 OS:Windows
Assigned to: CPU Architecture:x86

[14 Jul 2019 9:30] fnzh fnzh
Description:
use odbc for windows connect the mysql server running in windows, fetch a int column and a longtext column, the int column bound always return zero. if the mysql server running under linux or use varchar replace the longtext column, code works normally.

How to repeat:
use odbc for windows connect the mysql server running in windows, fetch a int column and a longtext column, the int column bound always return zero. if the mysql server running under linux or use varchar replace the longtext column, code works normally.
[15 Jul 2019 12:50] MySQL Verification Team
Thank you for the bug report. Could you please provide a complete test case sql script for table and code file which hit the issue reported. Thanks.
[16 Jul 2019 14:47] fnzh fnzh
The mysql server version is 8.0.16 too. table sql:

CREATE TABLE `ut_User1_Account_PrpTab` (
  `_id` int(11) NOT NULL,
  `_key` int(11) NOT NULL,
  `PrpTab` longtext,
  UNIQUE KEY `_id_key` (`_id`,`_key`),
  KEY `_id` (`_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci

code:
int main()
{
	SQLHENV henv;
	SQLHDBC hdbc;
	HSTMT hstmt;
	SQLRETURN sqlRet = ::SQLAllocHandle(SQL_HANDLE_ENV, SQL_NULL_HANDLE, &henv);
	assert(sqlRet != SQL_ERROR);
	sqlRet = ::SQLSetEnvAttr(henv, SQL_ATTR_ODBC_VERSION, (SQLPOINTER)SQL_OV_ODBC3, 0);
	assert(sqlRet != SQL_ERROR);
	sqlRet = ::SQLAllocHandle(SQL_HANDLE_DBC, henv, &hdbc);
	assert(sqlRet != SQL_ERROR);
	char strConnectOut[1024];
	SQLSMALLINT strConnectSize;
	const char* pConnectStr = "FILEDSN=../config/filedsn/mysql_fds_test1.dsn;UID=dbuser;PWD=1234";
	sqlRet = ::SQLDriverConnect(hdbc, NULL, (SQLCHAR*)pConnectStr, (SQLSMALLINT)::strlen(pConnectStr),
		(SQLCHAR*)strConnectOut, sizeof(strConnectOut), &strConnectSize, SQL_DRIVER_NOPROMPT);
	assert(sqlRet != SQL_ERROR);
	::printf("connected\n");
	sqlRet = ::SQLAllocHandle(SQL_HANDLE_STMT, hdbc, &hstmt);
	assert(sqlRet != SQL_ERROR);
	const char* pSqlSelect = "SELECT _key, PrpTab FROM ut_User1_Account_PrpTab WHERE _id = ?;";
	sqlRet = ::SQLPrepare(hstmt, (SQLCHAR*)pSqlSelect, (int)::strlen(pSqlSelect));
	assert(sqlRet != SQL_ERROR);
	sqlRet = ::SQLFreeStmt(hstmt, SQL_RESET_PARAMS);
	assert(sqlRet != SQL_ERROR);
	int id = 10001;
	sqlRet = ::SQLBindParameter(hstmt, 1, SQL_PARAM_INPUT, SQL_C_SLONG, SQL_INTEGER, 10, 0, (SQLPOINTER)&id, 0, nullptr);
	assert(sqlRet != SQL_ERROR);
	sqlRet = ::SQLExecute(hstmt);
	assert(sqlRet != SQL_ERROR);
	sqlRet = ::SQLFreeStmt(hstmt, SQL_UNBIND);
	assert(sqlRet != SQL_ERROR);
	int key = -1;
	SQLLEN retLen1;
	sqlRet = ::SQLBindCol(hstmt, 1, SQL_C_SLONG, (SQLPOINTER)&key, sizeof(key), &retLen1);
	assert(sqlRet != SQL_ERROR);
	sqlRet = ::SQLFetch(hstmt);
	assert(sqlRet != SQL_ERROR);
	if (sqlRet != SQL_NO_DATA)
	{
		char longTextBuf[4096];
		SQLLEN retLen2;
		sqlRet = ::SQLGetData(hstmt, 2, SQL_C_CHAR, longTextBuf, sizeof(longTextBuf), &retLen2);
		::printf("key=%i, text=%s", key, longTextBuf);
	}
	char ret;
	::scanf("%c", &ret);
	return 0;
}

These code connect sqlserver, can work normally, however connect mysql server, the int column return zero always, whatever data source running in windows or linux.
[12 Dec 2019 10:19] MySQL Verification Team
Hello fz fnzh,

Thank you for the bug report.
IMHO this is duplicate of bug #97191. Please see the bug #97191.

Regards,
Ashwini Patil