Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 5, 2025

Work Item / Issue Reference

AB#34891


Summary

This pull request introduces the DB-API 2.0-compliant connection attribute to the Cursor class in mssql_python, ensuring that each cursor exposes a read-only reference to its parent connection. The implementation is thoroughly tested with new and updated test cases covering polymorphic code, multi-cursor scenarios, connection lifecycle, and transaction control.

DB-API 2.0 compliance and attribute exposure

  • Added a read-only connection property to the Cursor class, exposing the connection object used to create the cursor, and updated internal usage to store the connection as a private attribute (_connection). (mssql_python/cursor.py) [1] [2]

Internal refactoring

  • Refactored internal references from self.connection to self._connection to enforce encapsulation and ensure the public attribute is read-only. (mssql_python/cursor.py)

Test coverage for the new attribute

  • Added comprehensive tests to verify the existence, correctness, and read-only nature of the cursor.connection attribute, including multi-cursor and multi-connection environments, accessibility after cursor/connection closure, and polymorphic code examples. (tests/test_004_cursor.py)

Transaction and polymorphic usage examples

  • Added tests demonstrating transaction control and polymorphic code patterns using the new cursor.connection attribute, confirming correct behavior in real-world scenarios. (tests/test_004_cursor.py)

@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 5, 2025
@jahnvi480 jahnvi480 merged commit b22a926 into jahnvi/cursor_rownumber Aug 6, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: medium Moderate update size

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants