Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Work Item / Issue Reference
Summary
This pull request adds comprehensive support for capturing and managing diagnostic messages (such as SQL Server PRINT statements and warnings) in the
mssql_python
driver'sCursor
class, following the DBAPI specification. It introduces a newmessages
attribute on the cursor, ensures messages are cleared or preserved at the correct times, and provides robust testing for these behaviors. Additionally, it implements the underlying C++ binding for retrieving all diagnostic records from the ODBC driver.Diagnostic message handling improvements:
messages
attribute to theCursor
class to store diagnostic messages, and ensured it is cleared before each non-fetch operation (e.g.,execute
,executemany
,close
,commit
,rollback
,scroll
, andnextset
) to comply with DBAPI expectations. (mssql_python/cursor.py
)messages
list, using a new C++ binding. (mssql_python/cursor.py
,mssql_python/pybind/ddbc_bindings.cpp
)Native driver and binding enhancements:
SQLGetAllDiagRecords
function in the C++ pybind layer to retrieve all diagnostic records from an ODBC statement handle, handling both Windows and Unix platforms, and exposed it asDDBCSQLGetAllDiagRecords
to Python. (mssql_python/pybind/ddbc_bindings.cpp
)Testing and specification compliance:
tests/test_004_cursor.py
)Other cursor improvements:
skip
method to validate arguments more strictly, clear messages before skipping, and improve error handling and documentation. (mssql_python/cursor.py
)These changes significantly improve the usability and correctness of message handling in the driver, making it easier for users to access and manage SQL Server informational and warning messages in Python applications.