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

[14 Jul 9:30] fz 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 12:50] Miguel Solorzano
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 14:47] fz 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.