Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 21, 2025

Work Item / Issue Reference

AB#34912


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

  • Added a new execute method to the Connection class 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.
  • Added a new batch_execute method to the Connection class to efficiently execute multiple SQL statements using a single cursor, supporting parameterized queries and optional cursor reuse/auto-close.
  • Improved resource management by ensuring cursors are properly tracked and removed from the connection’s internal WeakSet when closed, both in Connection._remove_cursor and within the Cursor.close method.

Transaction Error Handling

  • Updated commit and rollback methods in the Connection class to raise an InterfaceError if called on a closed connection, improving robustness and compliance with DB API expectations.

Test Suite Updates

  • Removed the redundant test_decimal_separator and test_lowercase_attribute tests, consolidating decimal separator edge case testing and cleaning up the test suite for clarity and maintainability.
  • Added a new test for decimal separator functionality, ensuring correct behavior for default values, setting, and invalid inputs.

@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 21, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: medium Moderate update size labels Sep 15, 2025
sumitmsft
sumitmsft previously approved these changes Sep 16, 2025
@jahnvi480 jahnvi480 changed the base branch from jahnvi/global_decimalseperator to main September 18, 2025 06:43
@jahnvi480 jahnvi480 dismissed sumitmsft’s stale review September 18, 2025 06:43

The base branch was changed.

Copilot AI review requested due to automatic review settings September 18, 2025 08:01
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
Copy link
Contributor

Copilot AI left a 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.

@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
@jahnvi480 jahnvi480 merged commit aa3a705 into main Sep 18, 2025
18 checks passed
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Sep 18, 2025
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.

5 participants