FEAT: Adding cursor.skip(n)#181
Merged
jahnvi480 merged 5 commits intojahnvi/cursor_scrollfrom Aug 27, 2025
Merged
Conversation
gargsaumya
approved these changes
Aug 22, 2025
Contributor
gargsaumya
left a comment
There was a problem hiding this comment.
Since skip() is just an alias for scroll(count, 'relative'), it carries the same inefficiency concerns for large skips. Approving for now.
…ssql-python into jahnvi/cursor_skip
Contributor
Author
|
@sumitmsft @gargsaumya Resolved comments in #180 Please have a look at it and let me know if there are any other changes required. |
sumitmsft
approved these changes
Aug 26, 2025
Contributor
sumitmsft
left a comment
There was a problem hiding this comment.
Straightforward implementation as it is dependent on PR#180
### 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#34893](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34893) ------------------------------------------------------------------- ### Summary This pull request adds comprehensive support for capturing and managing diagnostic messages (such as SQL Server PRINT statements and warnings) in the `mssql_python` driver's `Cursor` class, following the DBAPI specification. It introduces a new `messages` attribute 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:** * Added a `messages` attribute to the `Cursor` class to store diagnostic messages, and ensured it is cleared before each non-fetch operation (e.g., `execute`, `executemany`, `close`, `commit`, `rollback`, `scroll`, and `nextset`) to comply with DBAPI expectations. (`mssql_python/cursor.py`) * After each statement execution and fetch operation, diagnostic messages (including informational and warning messages) are collected and appended to the `messages` list, using a new C++ binding. (`mssql_python/cursor.py`, `mssql_python/pybind/ddbc_bindings.cpp`) **Native driver and binding enhancements:** * Implemented the `SQLGetAllDiagRecords` function in the C++ pybind layer to retrieve all diagnostic records from an ODBC statement handle, handling both Windows and Unix platforms, and exposed it as `DDBCSQLGetAllDiagRecords` to Python. (`mssql_python/pybind/ddbc_bindings.cpp`) **Testing and specification compliance:** * Added a comprehensive test suite to verify message capturing, clearing, preservation across fetches, handling of multiple messages, message formatting, warning capture, manual clearing, and error scenarios, ensuring compliance with DBAPI and robust behavior. (`tests/test_004_cursor.py`) **Other cursor improvements:** * Refactored the `skip` method 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. --------- 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 introduces a new convenience method,
skip, to theCursorclass inmssql_python/cursor.py, which allows users to advance the cursor position by a specified number of rows without fetching them. Comprehensive tests have been added to validate the method's behavior, including edge cases and integration with existing fetch methods.New feature: Cursor skipping
skip(count: int)method to theCursorclass, enabling users to efficiently advance the cursor by a given number of rows without returning those rows. The method checks for closed cursors, validates arguments, supports no-op for zero, and raises appropriate errors for invalid usage.Testing and validation
test_cursor_skip_basic_functionalityto verify thatskipadvances the cursor as expected and integrates correctly withfetchone.test_cursor_skip_zero_is_noop), empty result sets (test_cursor_skip_empty_result_set), skipping past the end (test_cursor_skip_past_end), invalid arguments (test_cursor_skip_invalid_arguments), and closed cursors (test_cursor_skip_closed_cursor).skipworks correctly withfetchone,fetchmany, andfetchallmethods (test_cursor_skip_integration_with_fetch_methods).