Skip to content

Conversation

@jahnvi480
Copy link
Contributor

@jahnvi480 jahnvi480 commented Aug 7, 2025

Work Item / Issue Reference

AB#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.

Copilot AI review requested due to automatic review settings August 7, 2025 10:09
@github-actions github-actions bot added pr-size: large Substantial code update labels Aug 7, 2025
@jahnvi480 jahnvi480 changed the base branch from main to jahnvi/conn_setencoding August 7, 2025 10:10
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Aug 7, 2025
Copy link
Contributor

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 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, and getdecoding methods 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_input helper 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

@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Aug 11, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Aug 11, 2025
@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Aug 13, 2025
Copy link
Contributor

@sumitmsft sumitmsft left a 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.

@github-actions github-actions bot added pr-size: large Substantial code update and removed pr-size: large Substantial code update labels Aug 27, 2025
@jahnvi480 jahnvi480 merged commit afcdbf3 into jahnvi/conn_setencoding Aug 27, 2025
3 checks passed
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.

4 participants