Bug #59722 values is corrupted in the buffer when sqlfetch fetch more than one rows
Submitted: 25 Jan 2011 19:19 Modified: 9 Jan 2015 16:15
Reporter: JUI-PIN JAO Email Updates:
Status: Duplicate Impact on me:
None 
Category:Connector / ODBC Severity:S1 (Critical)
Version:5.01.08.00 OS:Windows
Assigned to: CPU Architecture:Any

[25 Jan 2011 19:19] JUI-PIN JAO
Description:
execute the following SQL statement:

"select id, name from testtable"

where id is a bigint and name is a varchar(20)

and call
SQLSetStmtAttr((void*)hStatement, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)dwFetchCount, 0);

with dwFetchCount equal to 2

then call

byte pbBuffer[74];
SQLBindCol((void*)hStatement, 1, SQL_C_SBIGINT, pBuffer,     8,  &pBuffer[8]);
SQLBindCol((void*)hStatement, 2, SQL_C_CHAR,   &pBuffer[12], 21, &pBuffer[33]);
SQLSetStmtAttr(hStatement, SQL_ATTR_ROW_BIND_TYPE, 37, 0);
SQLFecth(hStatement);

The value returned in the second row in the pbBuffer is wrong

		

How to repeat:
execute the following SQL statement:

"select id, name from testtable"

where id is a bigint and name is a varchar(20)

and call
SQLSetStmtAttr((void*)hStatement, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)dwFetchCount, 0);

with dwFetchCount equal to 2

then call

byte pbBuffer[74];
SQLBindCol((void*)hStatement, 1, SQL_C_SBIGINT, pBuffer,     8,  &pBuffer[8]);
SQLBindCol((void*)hStatement, 2, SQL_C_CHAR,   &pBuffer[12], 21, &pBuffer[33]);
SQLSetStmtAttr(hStatement, SQL_ATTR_ROW_BIND_TYPE, 37, 0);
SQLFecth(hStatement);

The value returned in the second row in the pbBuffer is wrong

Suggested fix:
call SQLSetStmtAttr((void*)hStatement, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)dwFetchCount, 0);

with  dwFetchCount equal to 1
[10 Feb 2011 9:18] Bogdan Degtyariov
Thank you for your bug report.

Setting the status to 'verified'.
The problem is caused by incorrect offset value that corresponds to SQL_C_SBIGINT type. For row #2 the offset is 7 bytes instead of 8.

See the complete C test case uploaded below.
[10 Feb 2011 9:20] Bogdan Degtyariov
C test case

Attachment: bug_59722.c (text/plain), 3.15 KiB.