Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

PRB: Unicode Data is not Converted to ANSI with SQLBindParameter and ANSI ODBC Driver


View products that this article applies to.

This article was previously published under Q271198

↑ Back to the top


Symptoms

The ODBC Driver Manager does not convert Unicode parameter data to ANSI during a call to the ODBC API SQLBindParameter, even when the ODBC driver involved is ANSI. If the ANSI driver saves this parameter data (that is in Unicode format) into its own internal buffer and tries to use it later, the results could be unpredictable. This problem also affects the parameter length, since Unicode strings require twice the buffer space of ANSI strings.

↑ Back to the top


Resolution

The ODBC driver should wait until a SQLExecute or SQLExecDirect call is made. ODBC drivers should not store parameter data or length information during the call to SQLBindParameter.

↑ Back to the top


Status

This behavior is by design.

↑ Back to the top


More information

When a Unicode application calls SQLBindParameter in an ANSI driver, the ODBC Driver Manager does not immediately convert the Unicode parameter data to ANSI. The Driver Manager does an in-place conversion to ANSI only during the call to SQLExecute or SQLExecDirect, and then immediately converts the parameters back to Unicode. This is how the Driver Manager handles compatibility between Unicode applications and ANSI drivers.

It is risky if the ANSI driver saves this parameter data while it is still in Unicode format (before the SQLExecute or SQLExecDirect call) and then tries to use it later.

As per the ODBC specification, the ParameterValuePtr, which is one of the input parameters to the SQLBindParameter, is defined as follows:
The ParameterValuePtr argument points to a buffer that, when SQLExecute or SQLExecDirect is called, contains the actual data for the parameter.

↑ Back to the top


References

Microsoft ODBC 3.0 Programmer's Reference and SDK Guide, topic: "SQLBindParameter"; (Chapter 21)

↑ Back to the top


Keywords: KB271198, kbprb

↑ Back to the top

Article Info
Article ID : 271198
Revision : 3
Created on : 5/10/2003
Published on : 5/10/2003
Exists online : False
Views : 267