-
Notifications
You must be signed in to change notification settings - Fork 56
Driver Manager calls SQLGetDiagFieldW with wrong handle type for SQL_DYNAMIC_FUNCTION_CODE and SQL_DYNAMIC_FUNCTION #119
Description
Summary
When retrieving diagnostic fields such as SQL_DYNAMIC_FUNCTION_CODE or SQL_DYNAMIC_FUNCTION, the Driver Manager calls SQLGetDiagFieldW with HandleType=SQL_HANDLE_DBC (connection) even though the Handle provided is that of a statement. According to the ODBC specification, these fields are statement-level diagnostics and should only ever be requested with a statement handle.
Reference in code:
https://github.com/openlink/iODBC/blob/develop/iodbc/herr.c#L1690
Expected Behavior
When requesting the dynamic function code from a statement, the Driver Manager should call into the driver with:
HandleType = SQL_HANDLE_STMTHandle= valid statement handle
Actual Behavior
iODBC calls the driver with:
HandleType = SQL_HANDLE_DBCHandle= actually a statement handleDiagIdentifier=SQL_DYNAMIC_FUNCTION_CODEorSQL_DYNAMIC_FUNCTION
This causes drivers to fail to find the appropriate diagnostic manager, as the handle maps to a statement but the type signals it should locate a connection object.
Impact
- Drivers that rely on correct diagnostic retrieval for statement operations are broken, including proper error reporting when using iODBC.
Reproduction Steps
- Execute a statement using any ODBC driver with iODBC as the Driver Manager
- Request diagnostic field
SQL_DYNAMIC_FUNCTION_CODEorSQL_DYNAMIC_FUNCTIONviaSQLGetDiagField - Observe that the driver's implementation receives
HandleType=SQL_HANDLE_DBC, even though the handle is not a connection
ODBC Specification Reference
See ODBC documentation for SQLGetDiagField, which prescribes which handle types are allowed/valid for a given DiagIdentifier:
SQL_DYNAMIC_FUNCTION_CODE (and SQL_DYNAMIC_FUNCTION) are only valid for statement handles.
Recommendation
Please correct the iODBC Driver Manager logic to ensure that statement-specific diagnostic fields are only ever requested on statement handles using HandleType=SQL_HANDLE_STMT.