-
Notifications
You must be signed in to change notification settings - Fork 20
FEAT: Adding fetchval() in cursor class #178
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
Conversation
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.
Approving the PR. The test coverage is good - we can also aim to keep the code simple, even if that means fewer lines.
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.
Only change is requested. Rest looks good to me.
@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]>
Work Item / Issue Reference
Summary
This pull request introduces a new convenience method,
fetchval
, to thecursor.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:fetchval
to theCursor
class inmssql_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
:tests/test_004_cursor.py
to validatefetchval
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.