-
Notifications
You must be signed in to change notification settings - Fork 27
FEAT: Adding execute in connection class #189
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.
Pull Request Overview
This pull request introduces a new execute method to the Connection class for convenient SQL execution without manually creating cursors, along with comprehensive testing for this feature. The changes include extensive test coverage for both new functionality and existing features like decimal separator handling and encoding/decoding methods.
Key changes include:
- Added
Connection.execute()convenience method that creates and returns a cursor with executed SQL - Added
Connection.batch_execute()method for executing multiple SQL statements efficiently - Enhanced connection lifecycle management with proper cursor tracking and error handling for closed connections
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| mssql_python/connection.py | Implements execute() and batch_execute() methods with cursor tracking and improved error handling for closed connections |
| mssql_python/cursor.py | Adds cursor cleanup logic to remove cursor from connection tracking when closed |
| tests/test_003_connection.py | Extensive tests for new execute/batch_execute methods plus encoding/decoding functionality |
| tests/test_004_cursor.py | Tests for lowercase attribute and decimal separator functionality with database operations |
| tests/test_001_globals.py | Tests for decimal separator global functionality |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
Work Item / Issue Reference
Summary
This pull request introduces several enhancements and fixes to the connection and cursor lifecycle management in
mssql_python, adds new convenience methods for executing SQL statements, and improves error handling for transaction operations. It also updates the test suite by reorganizing and removing redundant tests.Key changes include new convenience methods for executing SQL, improved resource management for cursors, stricter error handling for transaction operations, and test suite cleanup.
Connection and Cursor Lifecycle Improvements
executemethod to theConnectionclass for convenient one-off SQL execution, which automatically manages cursor creation and cleanup. This is not part of the DB API but simplifies simple query use cases.batch_executemethod to theConnectionclass to efficiently execute multiple SQL statements using a single cursor, supporting parameterized queries and optional cursor reuse/auto-close.Connection._remove_cursorand within theCursor.closemethod.Transaction Error Handling
commitandrollbackmethods in theConnectionclass to raise anInterfaceErrorif called on a closed connection, improving robustness and compliance with DB API expectations.Test Suite Updates
test_decimal_separatorandtest_lowercase_attributetests, consolidating decimal separator edge case testing and cleaning up the test suite for clarity and maintainability.