FEAT: Adding Cursor.messages #184
Merged
jahnvi480 merged 3 commits intojahnvi/cursor_skipfrom Aug 27, 2025
Merged
Conversation
sumitmsft
approved these changes
Aug 24, 2025
sumitmsft
approved these changes
Aug 26, 2025
gargsaumya
approved these changes
Aug 26, 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#34926](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34926) ------------------------------------------------------------------- ### Summary This pull request adds a new `tables()` method to the `Cursor` class in `mssql_python/cursor.py`, providing a way to query metadata about tables in the database, including support for filtering by name, schema, catalog, and table type. It also introduces comprehensive test coverage for this new method in `tests/test_004_cursor.py`. Additionally, the `skip()` method in the cursor is simplified by delegating to the existing `scroll()` method. **New feature: Table metadata querying** - Added a `tables()` method to the `Cursor` class, enabling users to retrieve information about tables with support for filtering by table name (including temporary tables), schema, catalog, and table type (supports both string and list input). The method returns the cursor itself for easy chaining and iteration. **Testing improvements** - Introduced a suite of tests for the new `tables()` method, covering basic usage, filtering by name, schema, and type, wildcard support, combined filters, empty results, iteration, method chaining, and existence checks. These tests ensure the method works as intended and handles edge cases. **Code simplification** - Refactored the `skip()` method in the cursor to delegate to the `scroll()` method in 'relative' mode, removing redundant validation and manual row skipping logic. --------- Co-authored-by: Jahnvi Thakkar <jathakkar@microsoft.com>
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
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 comprehensive support for capturing and managing diagnostic messages (such as SQL Server PRINT statements and warnings) in the
mssql_pythondriver'sCursorclass, following the DBAPI specification. It introduces a newmessagesattribute on the cursor, ensures messages are cleared or preserved at the correct times, and provides robust testing for these behaviors. Additionally, it implements the underlying C++ binding for retrieving all diagnostic records from the ODBC driver.Diagnostic message handling improvements:
messagesattribute to theCursorclass to store diagnostic messages, and ensured it is cleared before each non-fetch operation (e.g.,execute,executemany,close,commit,rollback,scroll, andnextset) to comply with DBAPI expectations. (mssql_python/cursor.py)messageslist, using a new C++ binding. (mssql_python/cursor.py,mssql_python/pybind/ddbc_bindings.cpp)Native driver and binding enhancements:
SQLGetAllDiagRecordsfunction in the C++ pybind layer to retrieve all diagnostic records from an ODBC statement handle, handling both Windows and Unix platforms, and exposed it asDDBCSQLGetAllDiagRecordsto Python. (mssql_python/pybind/ddbc_bindings.cpp)Testing and specification compliance:
tests/test_004_cursor.py)Other cursor improvements:
skipmethod to validate arguments more strictly, clear messages before skipping, and improve error handling and documentation. (mssql_python/cursor.py)These changes significantly improve the usability and correctness of message handling in the driver, making it easier for users to access and manage SQL Server informational and warning messages in Python applications.