Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull Request Overview
This pull request adds configurable text encoding support to the Connection class in the mssql_python package, allowing users to specify how text data is encoded when communicating with the database.
- Introduces
setencoding()andgetencoding()methods for configuring and retrieving text encoding settings - Provides automatic ctype detection based on encoding type with override capability
- Includes comprehensive validation, error handling, and extensive test coverage
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| mssql_python/connection.py | Adds setencoding/getencoding methods with validation and default UTF-16LE encoding |
| tests/test_003_connection.py | Comprehensive test suite covering encoding functionality, edge cases, and error conditions |
| mssql_python/type.py | Minor documentation update removing pyodbc compatibility reference |
… jahnvi/conn_setencoding
sumitmsft
reviewed
Aug 22, 2025
sumitmsft
reviewed
Aug 22, 2025
sumitmsft
reviewed
Aug 22, 2025
sumitmsft
requested changes
Aug 22, 2025
Contributor
sumitmsft
left a comment
There was a problem hiding this comment.
Left a few comments...
sumitmsft
previously approved these changes
Aug 26, 2025
gargsaumya
previously approved these changes
Aug 27, 2025
### Work Item / Issue Reference <!-- IMPORTANT: Please follow the PR template guidelines below. For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452) For external contributors: Insert Github Issue number below (e.g. #149) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- mssql-python maintainers: ADO Work Item --> > [AB#34918](https://sqlclientdrivers.visualstudio.com/c6d89619-62de-46a0-8b46-70b92a84d85e/_workitems/edit/34918) ------------------------------------------------------------------- ### Summary This pull request introduces new functionality for configuring and retrieving text decoding settings in the `Connection` class of the `mssql_python` package. 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 (`setdecoding` and `getdecoding`) for managing decoding configuration per SQL type. **Enhancements to decoding configuration:** * Added a new constant, `SQL_WMETADATA`, in both `mssql_python/__init__.py` and `mssql_python/connection.py`, to allow explicit configuration of column name decoding. * Initialized a `_decoding_settings` dictionary in the `Connection` class to store decoding settings for `SQL_CHAR`, `SQL_WCHAR`, and `SQL_WMETADATA`, with sensible Python 3 defaults. * Introduced the `setdecoding` method to the `Connection` class, allowing users to configure the decoding (encoding and ctype) for each SQL type, including validation and error handling. * Added the `getdecoding` method to the `Connection` class, enabling retrieval of the current decoding settings for a specific SQL type, with validation and error handling. **Testing configuration:** * Updated the `conn_str` fixture in `tests/conftest.py` to use a hardcoded connection string, likely for local testing purposes. --------- Co-authored-by: Jahnvi Thakkar <jathakkar@microsoft.com>
… jahnvi/conn_setencoding
gargsaumya
approved these changes
Aug 28, 2025
sumitmsft
approved these changes
Aug 28, 2025
bewithgaurav
approved these changes
Aug 28, 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 adds support for configurable text encoding in the
Connectionclass of themssql_pythonpackage, allowing users to specify how text is encoded when interacting with the database. It introduces new methods for setting and retrieving encoding settings, provides robust validation and error handling, and includes comprehensive tests to ensure correct behavior across a wide range of scenarios.Encoding support and configuration:
setencodingandgetencodingmethods to theConnectionclass, allowing users to configure and retrieve text encoding and C type for SQL statements and parameters. The default encoding is set to'utf-16le'withSQL_WCHAR, and robust validation is performed for both encoding and ctype values.setencoding, raisingProgrammingErrorfor invalid encodings or ctypes, andInterfaceErrorif the connection is closed.Testing and validation:
Documentation and compatibility:
These changes make it easier and safer for users to control how text data is encoded and sent to the database, with clear error reporting and extensive test coverage to ensure reliability.