-
Notifications
You must be signed in to change notification settings - Fork 31
FEAT: Adding cursor.scoll function #180
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
+1,509
−52
Conversation
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
gargsaumya
reviewed
Aug 22, 2025
sumitmsft
requested changes
Aug 24, 2025
Contributor
sumitmsft
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just have the apprehension around scrolling many rows forward may result in high memory usage due to row by row operation. Let's make the correction and do the above mentioned fix.
### 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#34924](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34924) ------------------------------------------------------------------- ### Summary This pull request introduces a new convenience method, `skip`, to the `Cursor` class in `mssql_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** * Added `skip(count: int)` method to the `Cursor` class, 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** * Added `test_cursor_skip_basic_functionality` to verify that `skip` advances the cursor as expected and integrates correctly with `fetchone`. * Added tests for edge cases: skipping zero rows (`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`). * Added integration tests to ensure `skip` works correctly with `fetchone`, `fetchmany`, and `fetchall` methods (`test_cursor_skip_integration_with_fetch_methods`). --------- Co-authored-by: Jahnvi Thakkar <[email protected]>
sumitmsft
approved these changes
Aug 27, 2025
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 support for emulated scrolling (relative and absolute) in the
Cursorclass for forward-only result sets, including a newscroll()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
scroll()method to theCursorclass, 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._scroll_relative,_scroll_absolute, and_consume_rows_for_scrollto handle the logic for moving the cursor position and updating internal counters.Row Position Tracking Improvements
_next_row_indexand updating howrownumberis managed after fetch and scroll operations, ensuring consistency with DB-API semantics.Error Handling and Validation
Test Coverage for Scrolling
Minor Test Assertion Updates