You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### 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#34912](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34912)
-------------------------------------------------------------------
### Summary
This pull request introduces a new convenience method, `execute`, to the
`Connection` class in `mssql_python/connection.py`, allowing users to
execute SQL statements directly on the connection without manually
creating a cursor. Comprehensive tests have been added to ensure the
correctness, error handling, and versatility of this new method,
covering a wide range of scenarios including parameter passing,
transaction management, and comparison with traditional cursor usage.
**New feature: Connection-level SQL execution**
- Added a new `execute` method to the `Connection` class, which creates
a new cursor, executes the provided SQL statement (with optional
parameters), and returns the cursor. This simplifies executing single
SQL statements without explicitly managing cursors.
**Testing and validation for the new method**
- Introduced multiple test cases in `tests/test_003_connection.py` to
verify the behavior of the new `execute` method, including:
- Basic execution and parameterized queries
- Proper cursor tracking and resource management
- Error handling for invalid SQL statements
- Handling of empty result sets
- Support for various parameter data types (integer, float, string,
binary, boolean, NULL)
- Transactional behavior, including commit and rollback scenarios
- Comparison between `connection.execute` and `cursor.execute` usage
patterns
- Execution with a large number of parameters
---------
Co-authored-by: Jahnvi Thakkar <[email protected]>
0 commit comments