BufferLength in character for SQLGetDiagRecW

The SQLGetDiagRecW API returns diagnostic information in the output buffer, where the BufferLength parameter is the length of buffer allocated.

The default for BufferLength is the number of bytes allocated. After setting the SQL_INFX_ATTR_LENGTHINCHARFORDIAGRECW attribute to TRUE, the BufferLength is treated as a specific number of characters. As a Widechar API, one character=sizeof(SQLWCHAR) bytes.

Set the attribute in the following ways:
  • SQLSetEnvAttr (henv, SQL_INFX_ATTR_LENGTHINCHARFORDIAGRECW, 
                   (SQLPOINTER)SQL_TRUE, SQL_IS_UINTEGER);
  • SQLSetConnectAttr (hdbc, SQL_INFX_ATTR_LENGTHINCHARFORDIAGRECW,
                  (SQLPOINTER)SQL_TRUE, SQL_IS_UINTEGER); 
  • SQLSetStmtAttr (hstmt, SQL_INFX_ATTR_LENGTHINCHARFORDIAGRECW, 
                 (SQLPOINTER)SQL_TRUE, SQL_IS_UINTEGER); 
  • Set the LENGTHINCHARFORDIAGRECW=1 in the connection string.
  • On UNIX™ systems, in odbc.ini set LENGTHINCHARFORDIAGRECW=1
The precedence of setting SQL_INFX_ATTR_LENGTHINCHARFORDIAGRECW is:
  • Setting the SQLSetEnvAttr attribute reflects to the henv, hdbc, and hstmt handles.
  • Resetting the hdbc and hstmt handles through
    • Setting SQLSetConnectAttr
    • Passing the attribute in connection string
    • Enabling the Length in Chars for SQLGetDiagRecW option in the DSN
  • If the hstmt handle is set or not set by the previously mentioned methods, setting SQLSetStmtAttr resets it.