We are having problems retrieving diagnostic information from a DB2
database (server is 7.1.x, client is 8.1). The SQLGetDiagRec()
function, when called on a valid DB2 statement handle, always returns
SQL_SUCCESS_WIT H_INFO instead of SQL_SUCCESS, as the documentation
says it should. SQL_SUCCESS_WIT H_INFO, according to the documentation
excerpt from "The ODBC Programmer's Reference" posted below, means
that the text buffer for retrieving the error message passed to the
function was too small. The docs are quite clear about this. However,
this is never the case, as the buffer is large enough.
Here is the excerpt from the MSDN documentation mentioned above:
<quote>
SQLRETURN SQLGetDiagRec(
SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLCHAR * Sqlstate,
SQLINTEGER * NativeErrorPtr,
SQLCHAR * MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT * TextLengthPtr);
[...]
Returns:
SQL_SUCCESS, SQL_SUCCESS_WIT H_INFO, SQL_ERROR, or SQL_INVALID_HAN DLE.
Diagnostics:
SQLGetDiagRec does not post diagnostic records for itself. It uses the
following return values to report the outcome of its own execution:
- SQL_SUCCESS: The function successfully returned diagnostic
information.
- SQL_SUCCESS_WIT H_INFO: The *MessageText buffer was too small
to hold the requested diagnostic message. No diagnostic
records were generated. To determine that a truncation
occurred, the application must compare BufferLength to
the actual number of bytes available, which is
written to *StringLengthPt r.
- SQL_INVALID_HAN DLE: The handle indicated by HandleType and
Handle was not a valid handle.
- SQL_ERROR: One of the following occurred:
- RecNumber was negative or 0.
- BufferLength was less than zero.
- SQL_NO_DATA: RecNumber was greater than the number of
diagnostic records that existed for the handle specified
in Handle. The function also returns SQL_NO_DATA for any
positive RecNumber if there are no diagnostic records
for Handle.
</quote>
For those who have ever done ODBC programming with DB2 databases, it
should be obvious that this is NOT how DB2 acts when diagnosing
errors. I consider this to be a bug.
If it's not a bug, can anyone tell me how this is properly done?
Thanks.
Bob
database (server is 7.1.x, client is 8.1). The SQLGetDiagRec()
function, when called on a valid DB2 statement handle, always returns
SQL_SUCCESS_WIT H_INFO instead of SQL_SUCCESS, as the documentation
says it should. SQL_SUCCESS_WIT H_INFO, according to the documentation
excerpt from "The ODBC Programmer's Reference" posted below, means
that the text buffer for retrieving the error message passed to the
function was too small. The docs are quite clear about this. However,
this is never the case, as the buffer is large enough.
Here is the excerpt from the MSDN documentation mentioned above:
<quote>
SQLRETURN SQLGetDiagRec(
SQLSMALLINT HandleType,
SQLHANDLE Handle,
SQLSMALLINT RecNumber,
SQLCHAR * Sqlstate,
SQLINTEGER * NativeErrorPtr,
SQLCHAR * MessageText,
SQLSMALLINT BufferLength,
SQLSMALLINT * TextLengthPtr);
[...]
Returns:
SQL_SUCCESS, SQL_SUCCESS_WIT H_INFO, SQL_ERROR, or SQL_INVALID_HAN DLE.
Diagnostics:
SQLGetDiagRec does not post diagnostic records for itself. It uses the
following return values to report the outcome of its own execution:
- SQL_SUCCESS: The function successfully returned diagnostic
information.
- SQL_SUCCESS_WIT H_INFO: The *MessageText buffer was too small
to hold the requested diagnostic message. No diagnostic
records were generated. To determine that a truncation
occurred, the application must compare BufferLength to
the actual number of bytes available, which is
written to *StringLengthPt r.
- SQL_INVALID_HAN DLE: The handle indicated by HandleType and
Handle was not a valid handle.
- SQL_ERROR: One of the following occurred:
- RecNumber was negative or 0.
- BufferLength was less than zero.
- SQL_NO_DATA: RecNumber was greater than the number of
diagnostic records that existed for the handle specified
in Handle. The function also returns SQL_NO_DATA for any
positive RecNumber if there are no diagnostic records
for Handle.
</quote>
For those who have ever done ODBC programming with DB2 databases, it
should be obvious that this is NOT how DB2 acts when diagnosing
errors. I consider this to be a bug.
If it's not a bug, can anyone tell me how this is properly done?
Thanks.
Bob
Comment