FEAT: Adding Columns API in cursor #199
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work Item / Issue Reference
Summary
This pull request adds support for retrieving column metadata from SQL Server using the ODBC
SQLColumnsAPI, and exposes this functionality to Python through thecolumns()method on thecursorclass. The implementation includes both backend C++ bindings and a high-level Python interface, as well as careful handling of cursor state and result set mapping.The most important changes are:
Python interface:
Added a new
columns()method to thecursorclass inmssql_python/cursor.pyto retrieve detailed column metadata for tables using the ODBCSQLColumnsfunction. This method includes extensive documentation, result mapping, and warnings about potentially expensive queries. It also wraps and overrides the fetch methods to provide specialized column mappings for the result set.Updated the
execute()method incursor.pyto restore the original fetch methods if they were previously overridden, ensuring correct behavior after usingcolumns().C++ bindings and backend:
Added the
SQLColumnsFunctypedef, function pointer, and symbol loading for theSQLColumnsWODBC API inddbc_bindings.handddbc_bindings.cpp. This ensures the backend can call the ODBC function for column metadata.Implemented the
SQLColumns_wrapC++ function inddbc_bindings.cppto call the ODBCSQLColumnsAPI, handling both Windows and Unix platforms, and converting Python objects to wide strings as needed.Exposed a new
DDBCSQLColumnsmethod in the Python extension module, allowing Python code to call the new backend functionality.