FIX: Correcting getinfo API by jahnvi480 · Pull Request #249 · microsoft/mssql-python
Work Item / Issue Reference
Summary
This pull request refactors and improves the handling of ODBC SQLGetInfo metadata retrieval in the mssql_python driver. The main changes include a more robust and consistent method for returning info values from the C++ layer, enhanced decoding and type handling in Python, and better exposure of constants for users. These updates should make metadata access more reliable and easier to use, especially across different drivers and platforms.
ODBC Info Retrieval Refactor
- The C++
getInfomethod inconnection.cppnow always returns a dictionary containing the raw bytes, length, and info type, instead of attempting to interpret the result as a string or integer. This enables more consistent handling in Python and avoids issues with ambiguous types. - The Python
getinfomethod inconnection.pyhas been rewritten to robustly interpret the raw result dictionary, properly decode string and Y/N types, and handle various numeric formats. It includes improved error handling and logging for easier debugging.
Constants and Metadata Exposure
GetInfoConstantsis now imported and its members (such asSQL_DRIVER_NAME,SQL_SERVER_NAME, etc.) are exported at the module level in__init__.py. This makes it easier for users to reference standard info types.- A new
get_info_constants()function is provided to return all availableGetInfoConstantsas a dictionary, simplifying programmatic access. - Added missing constant
SQL_PROCEDURE_TERMto theGetInfoConstantsenum.
Testing Improvements
- Added debug print statements in
test_getinfo_standard_typesto help diagnose info type values during test runs.
These changes collectively improve the reliability, usability, and maintainability of metadata access in the driver.