BUG: GetFieldValue Returns Empty String for SQL_LONGVARCHARLast reviewed: July 10, 1997Article ID: Q157071 |
4.20
WINDOWS NT
kbprg kbtshoot kbbuglist
The information in this article applies to:
SYMPTOMSCRecordset::GetFieldValue() incorrectly returns an empty string for SQL_LONGVARCHAR data that is 1 character long.
CAUSEGetFieldValue() allocates a buffer and then calls CRecordset::GetData() to retrieve data from the field into this buffer. For long binary and character data, the length of the data is not known in advance, so GetFieldValue() does not know what size of buffer to allocate. Therefore, for SQL_LONGVARCHAR and SQL_LONGVARBINARY data, GetFieldValue() calls GetData() with a buffer length of 1. GetData() tries to retrieve the data and will likely fail because the buffer is too small. Whether GetData() fails or not, it returns the actual length of the data in the field excluding the NULL termination byte. GetFieldValue() then calls the function CRecordset::GetLongCharDataAndCleanup() to reallocate the buffer and retrieve the rest of the data, if necessary. GetLongCharDataAndCleanup() must determine whether GetData() was able to retrieve the data by checking whether the actual data length is larger than the buffer length:
// If long data, may need to call SQLGetData again if (nLen < nActualSize && (nSQLType == SQL_LONGVARCHAR || nSQLType == SQL_LONGVARBINARY))For 1-character SQL_LONGVARCHAR data, GetData() will fail because the buffer must be large enough to hold the data plus the NULL termination byte. Then, GetData() returns an actual size of 1, which does not include the NULL byte. GetLongCharDataAndCleanup() fails to consider the space required for the NULL termination byte. If the data length is 1, then both nLen and nActualSize are 1, which means that GetLongCharDataAndCleanup() will not attempt to get the additional data.
RESOLUTIONOverride the GetLongCharDataAndCleanup() function and change the length comparison above from "<" to "<=". See the MORE INFORMATION section below about how to implement this workaround.
STATUSMicrosoft has confirmed this to be a bug in the Microsoft products listed at the beginning of this article. We are researching this bug and will post new information here in the Microsoft Knowledge Base as it becomes available.
MORE INFORMATIONThe following steps detail one method of making the needed changes to GetFieldValue():
|
Additional reference words: 4.20 vcbuglist420 kbdsd
© 1998 Microsoft Corporation. All rights reserved. Terms of Use. |