Skip to content

Conversation

jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 13, 2025

Work Item / Issue Reference

AB#34922
AB#34923


Summary

This pull request adds two convenience methods to the Cursor class in mssql_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:

  • Added a commit method to the Cursor class, allowing users to commit transactions directly from the cursor. This delegates to the underlying connection's commit method and provides error handling if the cursor is closed.
  • Added a rollback method to the Cursor class, allowing users to roll back transactions directly from the cursor. This delegates to the underlying connection's rollback method and provides error handling if the cursor is closed.

@github-actions github-actions bot added the pr-size: large Substantial code update label Aug 13, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Aug 14, 2025
Copy link
Contributor

@sumitmsft sumitmsft left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is quite straight forward implementation of commit and rollback.

### 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>
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Aug 27, 2025
@jahnvi480 jahnvi480 merged commit 1e614a6 into jahnvi/cursor_fetchval Aug 27, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-size: large Substantial code update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants