-
Notifications
You must be signed in to change notification settings - Fork 28
pooling support #61
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
pooling support #61
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 PR introduces connection pooling support and refactors the Python Connection/Cursor classes to delegate to the new C++ binding ConnectionHandle, while removing redundant handle-allocation code.
- Adds a global
enable_poolingAPI and C++ConnectionPool/ConnectionPoolManager - Refactors
Connection/Cursorto useddbc_bindings.ConnectionHandleand simplifies transaction/handle logic - Removes legacy allocation wrappers and disables outdated connection tests
Reviewed Changes
Copilot reviewed 16 out of 16 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/test_005_exceptions.py | Disabled legacy connection error test (commented out) |
| tests/test_003_connection.py | Disabled invalid-connection and close tests (commented out) |
| mssql_python/pybind/ddbc_bindings.h | Updated pybind11 includes & added default constructor for SqlHandle |
| mssql_python/pybind/ddbc_bindings.cpp | Streamlined SqlHandle destructor, removed redundant wrapper fns & exposed ConnectionHandle |
| mssql_python/pybind/connection/connection_pool.h | Added ConnectionPool and ConnectionPoolManager interfaces |
| mssql_python/pybind/connection/connection_pool.cpp | Implemented pool acquire/release logic with commented debug blocks |
| mssql_python/pybind/connection/connection.h | Refactored C++ Connection/ConnectionHandle interfaces for pooling |
| mssql_python/pybind/CMakeLists.txt | Included connection_pool.cpp in the ddbc_bindings build |
| mssql_python/mssql_python.pyi | Added stub for enable_pooling |
| mssql_python/db_connection.py | Introduced module‐level _pooling_enabled and passed use_pool flag |
| mssql_python/cursor.py | Updated _allocate_statement_handle and _reset_cursor to use new API |
| mssql_python/connection.py | Delegated Python Connection to C++ binding and added use_pool |
| mssql_python/init.py | Exported enable_pooling at package level |
| main.py | Added example usage of pooling and demonstration script |
Comments suppressed due to low confidence (3)
tests/test_005_exceptions.py:127
- A critical error handling test was commented out, reducing coverage for connection errors; consider re-enabling or replacing it with a pooling-aware test.
# def test_connection_error(db_connection):
tests/test_003_connection.py:171
- Key connection validation tests were commented out, lowering test coverage; consider restoring tests or adding new cases for pooled connections.
# def test_invalid_connection_string():
mssql_python/pybind/connection/connection_pool.cpp:7
- [nitpick] There are extensive commented-out debug blocks throughout this file; consider removing dead code to improve readability and maintainability.
// std::wcout << L"[POOL] Created new pool. ConnStr: " << _conn_str
| # pooling.py | ||
| _pooling_enabled = False | ||
|
|
||
| def enable_pooling(): |
Copilot
AI
May 29, 2025
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.
The enable_pooling function signature doesn't accept max_size or idle_timeout parameters as advertised in the docs and pyi, leading to an API mismatch.
| """ | ||
| ... | ||
|
|
||
| def enable_pooling(max_size: int, idle_timeout: int) -> None: |
Copilot
AI
May 29, 2025
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.
The stub signature for enable_pooling expects two parameters, but the implementation takes none; sync the pyi with the actual function signature or update the implementation.
| rows = cursor1.fetchone() | ||
| print (rows) | ||
|
|
||
| print(conn1._conn) |
Copilot
AI
May 29, 2025
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.
[nitpick] The sample script accesses a private attribute _conn; consider exposing a public API or removing debug prints to avoid relying on internal implementation details.
| print(conn1._conn) | |
| print(conn1.get_connection()) |
This pull request introduces significant changes to the
mssql_pythonlibrary, including the addition of connection pooling functionality, refactoring of the connection and cursor handling, and simplifications to the codebase. The most important changes are grouped into themes below.Connection Pooling:
enable_poolingfunction and modifying theConnectionclass to accept ause_poolparameter. Pooling configuration is managed globally and integrated into the connection initialization process. (main.py[1]mssql_python/__init__.py[2]mssql_python/db_connection.py[3] [4]mssql_python/mssql_python.pyi[5]Refactoring Connection Class:
Connectionclass to replace manual resource allocation and attribute handling with direct calls toddbc_bindings.Connection. Removed redundant methods such as_initializer,_allocate_environment_handle,_allocate_connection_handle, and_connect_to_db. (mssql_python/connection.py[1] [2] [3]commitandrollbackoperations directly to theddbc_bindings.Connectionobject. (mssql_python/connection.py[1] [2]autocommitproperty andsetautocommitmethod to use theddbc_bindings.ConnectionAPI for managing autocommit mode. (mssql_python/connection.py[1] [2]Refactoring Cursor Class:
Cursorclass to allocate statement handles directly via theddbc_bindings.Connectionobject, removing dependency on thehdbchandle from theConnectionclass. (mssql_python/cursor.py[1] [2]mssql_python/cursor.pymssql_python/cursor.pyL560-R553)Codebase Simplification:
_is_closed,_apply_attrs_before, and_set_connection_attributes. (mssql_python/connection.pymssql_python/connection.pyL104-R113)CMakeLists.txtfile to include the newconnection_pool.cppfile for connection pooling implementation in theddbc_bindingsmodule. (mssql_python/pybind/CMakeLists.txtmssql_python/pybind/CMakeLists.txtL93-R93)Checklist
Testing Performed
<mention Python version><mention OS>Additional Notes