-
Notifications
You must be signed in to change notification settings - Fork 31
FEAT: Adding setdecoding() API for connection #173
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
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 introduces a comprehensive encoding/decoding configuration system for the Connection class, enabling users to control how text is encoded and decoded when interacting with SQL Server databases. The changes provide explicit control over text handling for SQL statements and results with Python 3 defaults and include security improvements for logging user input.
- Added
setencoding,getencoding,setdecoding, andgetdecodingmethods for comprehensive text encoding/decoding control - Introduced module-level constants (
SQL_CHAR,SQL_WCHAR,SQL_WMETADATA) and helper functions for encoding validation - Added
sanitize_user_inputhelper function to prevent log injection attacks
Reviewed Changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 10 comments.
Show a summary per file
| File | Description |
|---|---|
tests/test_003_connection.py |
Extensive test suite covering all encoding/decoding functionality with various scenarios |
tests/conftest.py |
Hardcoded connection string for improved test reliability |
mssql_python/type.py |
Minor documentation clarification removing pyodbc reference |
mssql_python/helpers.py |
Added sanitize_user_input function for secure logging |
mssql_python/connection.py |
Core implementation of encoding/decoding methods with validation and security features |
mssql_python/__init__.py |
Export of SQL constants for public API access |
…t/mssql-python into jahnvi/conn_setdecoding
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.
No major issues were found. This PR is well-implemented and safe to merge.
Work Item / Issue Reference
Summary
This pull request introduces new functionality for configuring and retrieving text decoding settings in the
Connectionclass of themssql_pythonpackage. The main changes add support for a new special SQL type flag (SQL_WMETADATA) to allow explicit control over how column metadata is decoded, and provide two new methods (setdecodingandgetdecoding) for managing decoding configuration per SQL type.Enhancements to decoding configuration:
SQL_WMETADATA, in bothmssql_python/__init__.pyandmssql_python/connection.py, to allow explicit configuration of column name decoding._decoding_settingsdictionary in theConnectionclass to store decoding settings forSQL_CHAR,SQL_WCHAR, andSQL_WMETADATA, with sensible Python 3 defaults.setdecodingmethod to theConnectionclass, allowing users to configure the decoding (encoding and ctype) for each SQL type, including validation and error handling.getdecodingmethod to theConnectionclass, enabling retrieval of the current decoding settings for a specific SQL type, with validation and error handling.Testing configuration:
conn_strfixture intests/conftest.pyto use a hardcoded connection string, likely for local testing purposes.