Skip to content

Conversation

jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 22, 2025

Work Item / Issue Reference

AB#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.

@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-size: medium Moderate update size
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant