-
Notifications
You must be signed in to change notification settings - Fork 27
FEAT: Adding Ouput Converter APIs #190
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
sumitmsft
left a comment
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.
Left a few comments.
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 adds a flexible output converter system to the mssql-python database connection, allowing custom Python functions to be registered for converting SQL data types when fetching results. The implementation includes comprehensive thread-safe methods for managing converters and robust integration with the row handling logic.
- Adds connection-level output converter management methods (add, get, remove, clear) with thread safety
- Updates Row class to automatically apply registered output converters during data fetching with error handling
- Includes extensive testing for converter registration, retrieval, integration, and edge cases
Reviewed Changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
| mssql_python/connection.py | Adds output converter management methods and convenience execute() method with thread-safe implementation |
| mssql_python/row.py | Updates Row class to apply output converters automatically with fallback logic and error handling |
| tests/test_003_connection.py | Adds comprehensive tests for output converter functionality including helper functions and edge cases |
| tests/test_004_cursor.py | Reorganizes test functions by moving them to different locations within the file |
| tests/test_001_globals.py | Adds duplicate test for decimal separator 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 adds a flexible output converter system to the database connection, allowing custom Python functions to be registered for converting SQL data types when fetching results. It introduces new methods for managing these converters and updates the row handling logic to apply them automatically. Comprehensive tests are added to verify correct registration, retrieval, removal, and integration of output converters, including edge cases and chaining behavior.
Core output converter system:
Connection(add_output_converter,get_output_converter,remove_output_converter,clear_output_converters) for registering and managing output converter functions for specific SQL types. These converters are called when values of the registered SQL type are read from the database. (mssql_python/connection.py)Rowclass to apply registered output converters automatically to values fetched from the database, with fallback logic for string types and robust error handling. (mssql_python/row.py)Testing and validation:
NULLvalues and using multiple converters at once. (tests/test_003_connection.py)DATETIMEOFFSETand custom string handling) to support and validate the new converter system in tests. (tests/test_003_connection.py)Test and utility enhancements:
struct,datetime,timezone, and constants) to support new test cases and converter logic. (tests/test_003_connection.py)