-
Notifications
You must be signed in to change notification settings - Fork 21
FEAT: Adding conn.setencoding() API #172
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 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
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...
### 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
Work Item / Issue Reference
Summary
This pull request adds support for configurable text encoding in the
Connection
class of themssql_python
package, 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:
setencoding
andgetencoding
methods to theConnection
class, 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
, raisingProgrammingError
for invalid encodings or ctypes, andInterfaceError
if 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.