Skip to content

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 7, 2025

Work Item / Issue Reference

AB#34917


Summary

This pull request adds support for configurable text encoding in the Connection class of the mssql_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:

  • Added setencoding and getencoding methods to the Connection 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' with SQL_WCHAR, and robust validation is performed for both encoding and ctype values.
  • Improved error handling in setencoding, raising ProgrammingError for invalid encodings or ctypes, and InterfaceError if the connection is closed.

Testing and validation:

  • Added a comprehensive suite of tests for the new encoding functionality, including default settings, explicit and automatic ctype detection, invalid parameter handling, persistence across cursors, thread safety, and case sensitivity. Also includes a (skipped) test for Unicode data operations.

Documentation and compatibility:

  • Updated docstrings and comments to clarify encoding behavior and DB-API 2.0 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.

@Copilot Copilot AI review requested due to automatic review settings August 7, 2025 07:10
@github-actions github-actions bot added the pr-size: medium Moderate update size label Aug 7, 2025
Copy link
Contributor

@Copilot Copilot AI left a 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() and getencoding() 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

@github-actions github-actions bot added pr-size: medium Moderate update size and removed pr-size: medium Moderate update size labels Aug 7, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: medium Moderate update size labels Aug 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr-size: large Substantial code update
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant