PRB: *StringLengthPtr Returns Incorrect Value When SQLGETInfo Called with Insufficient Buffer Size (294189)



The information in this article applies to:

  • Microsoft Data Access Components 2.1
  • Microsoft Data Access Components 2.5
  • Microsoft Data Access Components 2.6

This article was previously published under Q294189

SYMPTOMS

When you call SQLGetInfo with a buffer size that is smaller than required, the string data is right-truncated as expected. According to the ODBC specification, in this situation, *StringLengthPtr should return the length of the requested information in bytes. The string passed back to the client is a regular char string (in other words, not Unicode), but when the string truncation occurs, the Driver Manager may return the length of the string in its Unicode form.

Here is an excerpt from the ODBC specification from Microsoft Developer Network (MSDN):

"The buffer *InfoValuePtr was not large enough to return all of the requested information, so the information was truncated. The length of the requested information in its untruncated form is returned in *StringLengthPtr. (Function returns SQL_SUCCESS_WITH_INFO.)"

CAUSE

The driver's SQLGetInfo function is always Unicode-based. The problem occurs in the Driver Manager. When the truncation occurs, the Driver Manager converts the Unicode string it receives from the driver to ANSI. However, it does not adjust the string length value accordingly, because it is allowing for a scenario where the data is entirely composed of double-byte character set (DBCS) data.

STATUS

This behavior is by design.

MORE INFORMATION

Steps to Reproduce Behavior

The following steps reproduce the problem using the Microsoft ODBC Driver for Jet as an example:
  1. Within ODBC Test, select Full Connect and connect to either a SQL Server or Microsoft Access database.
  2. On the Conn menu, click SQLGetInfo. For Info Type, enter SQL_DRIVER_NAME, and for Buffer Length, enter 12.

    The driver name is returned and *StringLengthPtr shows a size of 12.
  3. Repeat step 2 but for Buffer Length, enter a buffer size of less than 12. You receive the following information:
    MessageText = "[Microsoft][ODBC Microsoft Access Driver]String data, right truncated " *StringLengthPtr = 24

Modification Type:MajorLast Reviewed:11/17/2003
Keywords:kbprb KB294189