FEAT: Adding setdecoding() API for connection#173
Merged
jahnvi480 merged 5 commits intojahnvi/conn_setencodingfrom Aug 27, 2025
Merged
FEAT: Adding setdecoding() API for connection#173jahnvi480 merged 5 commits intojahnvi/conn_setencodingfrom
jahnvi480 merged 5 commits intojahnvi/conn_setencodingfrom
Conversation
Contributor
There was a problem hiding this comment.
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
approved these changes
Aug 22, 2025
Contributor
sumitmsft
left a comment
There was a problem hiding this comment.
No major issues were found. This PR is well-implemented and safe to merge.
sumitmsft
approved these changes
Aug 26, 2025
gargsaumya
approved these changes
Aug 27, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 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.