You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make unsupported setencoding() requests non-silent while preserving the existing UTF-16LE / SQL_C_WCHAR parameter binding.
Emit a caller-visible UserWarning for valid requests that cannot be applied, including explicit or automatic SQL_CHAR and UTF-16BE. Keep supported defaults warning-free and retain existing validation errors.
Preserve getencoding() compatibility and leave settings unchanged when warnings are treated as errors.
Align native execute() and executemany() encoding checks.
Clarify requested versus effective settings in README/docstrings and document the legacy internal C-type alias without changing its value.
Replace permissive encoding tests with strict warning and data-preservation assertions across execute, executemany, setinputsizes, and streaming.
This is a warning-based fix for ignored configuration, not an implementation of configurable narrow binding. The public wiki has not been edited and still needs corresponding clarification if this approach is adopted.
Validation
Reproduced the silent no-op on Windows x64 / Python 3.13.15 against live SQL Server LocalDB, including native binding diagnostics. New warning assertions fail on the baseline.
Rebuilt the native extension; 408 focused encoding, CP1252-boundary, and execute-parity tests passed.
Black passed for all 101 Python files.
Full non-stress suite: 5295 passed, 173 skipped, 42 deselected, 2 failures. Both failures also reproduce with the unchanged HEAD connection implementation: a logging test assumes a password exists on a passwordless LocalDB connection, and a long-path test exceeds Windows MAX_PATH.
Preserve wide-character binding while warning about ignored encoding requests. Align native encoding gates and document and test the effective contract.
Refs #825; AB#48882
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Unix / SQL Server 2022: Python 3.12.3, x86_64, SQL 16.0.4295.3; 5 paired comparisons and 1 warmup.
Unix / SQL Server 2025: Python 3.12.3, x86_64, SQL 17.0.5005.3; 5 paired comparisons and 1 warmup.
A consistent change requires more than 20% median paired movement, at least 1 ms between the median runtimes, and at least 80% of pairs exceeding the relative threshold in the same direction. A slowdown without enough pair agreement is reported as inconsistent.
The displayed change is the median of paired before-and-after ratios. It is not recalculated from the two displayed median runtimes.
Both revisions use profiling-enabled builds on the same agent and database, with alternating order and discarded warmups. Results are diagnostic and do not represent production-wheel latency.
Raw samples and logs are attached to the ADO run as profiler-* artifacts.
2136 (SQLPOINTER)SQL_CONCUR_READ_ONLY, 0);
2137 }
21382139// This codec only applies to parameters already typed as real SQL_C_CHAR (1).
! 2140// Public text parameter detection uses SQL_C_WCHAR (-8), including the
! 2141// Python layer's legacy SQL_C_CHAR alias. setencoding() does not change2142// paramCType and warns when the requested settings cannot be applied.2143 std::string charEncoding = "utf-8";
2144if (encoding_settings.contains("ctype") && encoding_settings.contains("encoding")) {
2145int ctype = encoding_settings["ctype"].cast<int>();
📋 Files Needing Attention
📉 Files with overall lowest coverage (click to expand)
Address review feedback by documenting validation errors before warnings and removing permissive ASCII DAE tests. Assert public executemany uses DDBCSQLExecute for streaming, with exact UTF-16LE data preservation and native bridge call counts.
Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
Canonicalize codec aliases before ctype validation
mssql_python/connection.py:1293
A valid alias for the supported default can still trigger this warning. For example, Python accepts UTF-16-LE, but casefold() produces utf-16-le, which is not in UTF16_ENCODINGS; the preceding auto-selection therefore chooses SQL_CHAR, and this condition reports an unsupported request even though the codec is UTF-16LE. Canonicalize Python codec aliases before ctype selection/validation and add a warning-free alias case.
The reason will be displayed to describe this comment to others. Learn more.
Copilot review overview
🔵 Needs a closer look
Native ODBC encoding behavior still requires the pending Linux and macOS CI validation.
Review effort: Balanced Findings: None
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
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
Make unsupported
setencoding()requests non-silent while preserving the existing UTF-16LE /SQL_C_WCHARparameter binding.UserWarningfor valid requests that cannot be applied, including explicit or automaticSQL_CHARand UTF-16BE. Keep supported defaults warning-free and retain existing validation errors.getencoding()compatibility and leave settings unchanged when warnings are treated as errors.execute()andexecutemany()encoding checks.This is a warning-based fix for ignored configuration, not an implementation of configurable narrow binding. The public wiki has not been edited and still needs corresponding clarification if this approach is adopted.
Validation