Microsoft KB Archive/136653

= PRB: SQLGetData w/ SQL_C_BINARY Causes GPF in 16-bit ODBC Test =

Article ID: 136653

Article Last Modified on 3/10/2000

-

APPLIES TO


 * Microsoft Open Database Connectivity 2.1

-



This article was previously published under Q136653



SYMPTOMS
Inside 16-bit ODBC Test, when you call SQLGetData with SQL_C_BINARY on a column holding more than 40 bytes and cbValueMax is set to be smaller than the actual size of data in the column, the following general protection fault (GPF) will be raised:

ODBCTEST caused a General Protection Fault in module ODBCTEST.EXE at 0001:BF33



WORKAROUND
There are two resolutions for this problem in 16-bit ODBC Test:  Specify cbValueMax large enough to get data back by one SQLGetData call. Replace SQL_C_BINARY with SQL_C_CHAR for fCType. The following text is an excerpt from "ODBC 2.0 Programmer's Reference Book," Appendix D. Please refer to this book for more information before you use this method:

When binary SQL data is converted to character C data, each byte (8 bits) of source data is represented as two ASCII characters. These characters are the ASCII character representation of the number in its hexadecimal form. For example, a binary 00000001 is converted to "01" and a binary 11111111 is converted to "FF".

The driver always converts individual bytes to pairs of hexadecimal digits and terminates the character string with a null byte. Because of this, if cbValueMax is even and is less than the length of the converted data, the last byte of the rgbValue buffer is not used. (The converted data requires an even number of bytes, the next-to-last byte is a null byte, and the last byte cannot be used.)



You will not have this problem with 32-bit ODBC Test.



MORE INFORMATION
Here are the steps to reproduce the error:
 * 1) "Full Connect" to an ODBC data source;
 * 2) SQLExecuteDirect:

create table test(col1 varchar(50))
 * 1) SQLExecuteDirect:

insert into test values (' ')
 * 1) SQLExecuteDirect:

select * from test
 * 1) SQLFetch;
 * 2) SQLGetData(hstmt, icol=1, fCType=SQL_C_BINARY, rgbValue, cbValueMax=10, pcbValue)

Additional query words: 2.10 odbcsdk sql6 6.00

Keywords: kbprb KB136653

-

[mailto:TECHNET@MICROSOFT.COM Send feedback to Microsoft]

© Microsoft Corporation. All rights reserved.