Skip to content

Conversation

jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 13, 2025

Work Item / Issue Reference

AB#34921


Summary

This pull request introduces a new convenience method, fetchval, to the cursor.py module, designed to simplify retrieval of single values from SQL queries. Comprehensive tests have been added to ensure its correctness, robustness, and compatibility with various SQL scenarios and data types.

Addition of fetchval method:

  • Added fetchval to the Cursor class in mssql_python/cursor.py, allowing users to easily fetch the first column of the first row from a query result. This is especially useful for aggregate queries or scalar selects and supports method chaining.

Testing and validation of fetchval:

  • Extensive tests added in tests/test_004_cursor.py to validate fetchval for basic functionality, multiple data types, NULL values, empty results, multiple columns/rows, aggregate functions, method chaining, closed cursor behavior, rownumber tracking, error scenarios, and common performance patterns.

These changes make it easier and safer for users to retrieve single values from queries, improving developer experience and reliability.

@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 13, 2025
Copy link
Contributor

@gargsaumya gargsaumya left a comment

Choose a reason for hiding this comment

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

Approving the PR. The test coverage is good - we can also aim to keep the code simple, even if that means fewer lines.

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.

Only change is requested. Rest looks good to me.

@github-actions github-actions bot removed the pr-size: medium Moderate update size label Aug 25, 2025
@jahnvi480 jahnvi480 requested a review from sumitmsft August 25, 2025 09:58
@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 25, 2025
@jahnvi480
Copy link
Contributor Author

@sumitmsft Comments are resolved please approve

### 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#34922](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34922)
>
[AB#34923](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/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.

---------

Co-authored-by: Jahnvi Thakkar <[email protected]>
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: medium Moderate update size labels Aug 27, 2025
@jahnvi480 jahnvi480 merged commit f78ecc0 into jahnvi/cursor_rownumber 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