FIX: Correcting getinfo API by jahnvi480 · Pull Request #249 · microsoft/mssql-python

Work Item / Issue Reference

AB#34911


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++ getInfo method in connection.cpp now 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 getinfo method in connection.py has 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

  • GetInfoConstants is now imported and its members (such as SQL_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 available GetInfoConstants as a dictionary, simplifying programmatic access.
  • Added missing constant SQL_PROCEDURE_TERM to the GetInfoConstants enum.

Testing Improvements

  • Added debug print statements in test_getinfo_standard_types to help diagnose info type values during test runs.

These changes collectively improve the reliability, usability, and maintainability of metadata access in the driver.