FEAT: Adding commit and rollback in cursor#179
Merged
jahnvi480 merged 3 commits intojahnvi/cursor_fetchvalfrom Aug 27, 2025
Merged
FEAT: Adding commit and rollback in cursor#179jahnvi480 merged 3 commits intojahnvi/cursor_fetchvalfrom
jahnvi480 merged 3 commits intojahnvi/cursor_fetchvalfrom
Conversation
gargsaumya
approved these changes
Aug 20, 2025
sumitmsft
approved these changes
Aug 24, 2025
Contributor
sumitmsft
left a comment
There was a problem hiding this comment.
This is quite straight forward implementation of commit and rollback.
sumitmsft
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#34892](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34892) ------------------------------------------------------------------- ### Summary This pull request introduces support for emulated scrolling (relative and absolute) in the `Cursor` class for forward-only result sets, including a new `scroll()` method and comprehensive tests for scroll behavior. It also refines row position tracking, improves error handling, and updates some test assertions for clarity. The most important changes are grouped below. ### Cursor Scrolling Feature * Added a new `scroll()` method to the `Cursor` class, allowing movement to a specific row position in the result set using relative or absolute modes. This is implemented by consuming rows for forward-only cursors, with robust error handling for unsupported operations and invalid parameters. * Implemented helper methods `_scroll_relative`, `_scroll_absolute`, and `_consume_rows_for_scroll` to handle the logic for moving the cursor position and updating internal counters. ### Row Position Tracking Improvements * Refined row position tracking by introducing `_next_row_index` and updating how `rownumber` is managed after fetch and scroll operations, ensuring consistency with DB-API semantics. ### Error Handling and Validation * Improved error handling in cursor methods by providing more descriptive error messages and raising appropriate exceptions for invalid scroll operations or parameters. * Updated import statements to include new exception types used for scroll validation. ### Test Coverage for Scrolling * Added a suite of new tests to verify scroll behavior, including relative and absolute scrolling, backward scroll rejection, empty result set handling, mixed fetch/scroll operations, and edge case validation. ### Minor Test Assertion Updates * Updated test assertions and comments in transaction-related tests for clarity and to better reflect the intended behavior. --------- 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 two convenience methods to the
Cursorclass inmssql_python/cursor.py, making it easier to manage transactions directly from the cursor object without needing to access the underlying connection. This improves usability for developers working with the cursor API.Transaction management enhancements:
commitmethod to theCursorclass, allowing users to commit transactions directly from the cursor. This delegates to the underlying connection'scommitmethod and provides error handling if the cursor is closed.rollbackmethod to theCursorclass, allowing users to roll back transactions directly from the cursor. This delegates to the underlying connection'srollbackmethod and provides error handling if the cursor is closed.