-
Notifications
You must be signed in to change notification settings - Fork 31
FEAT: Adding rowID and rowvVer functions #197
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
sumitmsft
requested changes
Sep 11, 2025
Contributor
sumitmsft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few comments
sumitmsft
approved these changes
Sep 12, 2025
bewithgaurav
approved these changes
Sep 15, 2025
### Work Item / Issue Reference <!-- IMPORTANT: Please follow the PR template guidelines below. For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452) For external contributors: Insert Github Issue number below (e.g. #149) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- mssql-python maintainers: ADO Work Item --> > [AB#34928](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34928) ------------------------------------------------------------------- ### Summary This pull request adds support for retrieving table and index statistics via the ODBC `SQLStatistics` API in the `mssql_python` package. The main changes include implementing the `statistics` method on the Python cursor, exposing the required C++ bindings, defining new constants, and introducing comprehensive tests to ensure the new functionality works as expected. **New statistics feature:** * Added the `statistics` method to the `Cursor` class in `mssql_python/cursor.py`, allowing users to retrieve index and table statistics for a given table, with options to filter by uniqueness, catalog, schema, and quickness of statistics retrieval. * Defined new constants (`SQL_INDEX_UNIQUE`, `SQL_INDEX_ALL`, `SQL_QUICK`, `SQL_ENSURE`) in `mssql_python/constants.py` to support the statistics method options. **C++ binding and integration:** * Added the `SQLStatisticsFunc` type and related function pointer to `mssql_python/pybind/ddbc_bindings.h` and initialized it in `mssql_python/pybind/ddbc_bindings.cpp`. * Implemented the `SQLStatistics_wrap` function and exposed it to Python via the `DDBCSQLStatistics` binding in the pybind module. **Testing:** * Added a comprehensive suite of tests in `tests/test_004_cursor.py` for the new `statistics` method, including tests for setup, basic functionality, unique index filtering, empty tables, non-existent tables, result structure, catalog filtering, the `quick` parameter, and cleanup. --------- Co-authored-by: Jahnvi Thakkar <[email protected]>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 special columns from a database table using the ODBC
SQLSpecialColumnsfunction. The main changes include new methods in the Python cursor for accessing row identifier and version columns, as well as the necessary C++ and Python bindings to expose this ODBC functionality. Additionally, relevant constants have been added to support these features.New Python cursor methods:
rowIdColumnsandrowVerColumnsmethods to theCursorclass inmssql_python/cursor.py, allowing users to retrieve columns that uniquely identify a row (SQL_BEST_ROWID) and columns that are automatically updated when any value in the row is updated (SQL_ROWVER). These methods handle ODBC parameter preparation, call the new binding, and return results as row objects.ODBC and pybind11 binding support:
SQLSpecialColumnsFuncfunction pointer type and added the corresponding global pointer inmssql_python/pybind/ddbc_bindings.handmssql_python/pybind/ddbc_bindings.cpp.SQLSpecialColumnsWsymbol from the ODBC driver in the driver loader, and included it in the function pointer validation check.SQLSpecialColumns_wrapfunction to call the ODBC API, handling both Unix and Windows string conversions, and exposed it to Python asDDBCSQLSpecialColumnsin the module definition.Constants:
SQL_SCOPE_CURROW,SQL_BEST_ROWID,SQL_ROWVER,SQL_NO_NULLS, andSQL_NULLABLE_UNKNOWNto theConstantsDDBCenum inmssql_python/constants.pyto support the new functionality.