Skip to content

Conversation

@bewithgaurav
Copy link
Collaborator

Work Item / Issue Reference

AB#<WORK_ITEM_ID>

GitHub Issue: #318


Summary

This pull request introduces improvements to the handling of string encoding in the getinfo method for SQL Server connections, adds support for profiling builds in the Windows build script, and enhances test coverage for string decoding. The most important changes are grouped below:

String Decoding Improvements

  • The getinfo method in connection.py now attempts to decode string results from SQL Server using multiple encodings in order: UTF-16LE (Windows default), UTF-8, and Latin-1. This improves robustness when handling driver responses and avoids silent data corruption by returning None if all decoding attempts fail.

Test Coverage

  • Added a new test test_getinfo_string_encoding_utf16 in test_003_connection.py to verify that string values returned by getinfo are properly decoded from UTF-16, contain no null bytes, and are non-empty, helping catch encoding mismatches early.

Build Script Cleanup

  • Removed redundant logic from build.bat related to copying the msvcp140.dll redistributable, simplifying the post-build process.

@github-actions github-actions bot added the pr-size: medium Moderate update size label Nov 21, 2025
@github-actions
Copy link

github-actions bot commented Nov 21, 2025

📊 Code Coverage Report

🔥 Diff Coverage

40%


🎯 Overall Coverage

77%


📈 Total Lines Covered: 5063 out of 6536
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

  • mssql_python/connection.py (40.0%): Missing lines 1206-1207,1215

Summary

  • Total: 5 lines
  • Missing: 3 lines
  • Coverage: 40%

mssql_python/connection.py

Lines 1202-1211

  1202                     # Try encodings in order: UTF-16LE (Windows), UTF-8, Latin-1
  1203                     for encoding in ("utf-16-le", "utf-8", "latin1"):
  1204                         try:
  1205                             return actual_data.decode(encoding).rstrip("\0")
! 1206                         except UnicodeDecodeError:
! 1207                             continue
  1208                     
  1209                     # All decodings failed
  1210                     logger.debug(
  1211                         "error",

Lines 1211-1219

  1211                         "error",
  1212                         "Failed to decode string in getinfo with any supported encoding. "
  1213                         "Returning None to avoid silent corruption.",
  1214                     )
! 1215                     return None
  1216                 else:
  1217                     # If it's not bytes, return as is
  1218                     return data
  1219             elif is_yn_type:


📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.helpers.py: 66.6%
mssql_python.row.py: 67.4%
mssql_python.pybind.ddbc_bindings.cpp: 70.4%
mssql_python.pybind.connection.connection.cpp: 76.3%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.pybind.ddbc_bindings.h: 79.7%
mssql_python.connection.py: 82.2%
mssql_python.cursor.py: 83.6%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

@github-actions github-actions bot added pr-size: small Minimal code update and removed pr-size: medium Moderate update size labels Nov 21, 2025
except UnicodeDecodeError:
# SQLGetInfoW returns UTF-16LE encoded strings
# Try encodings in order: UTF-16LE (Windows), UTF-8, Latin-1
for encoding in ("utf-16-le", "utf-8", "latin1"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why latin1 ? :) Asking out of curiosity. IIUC, utf-16-le and utf-8 might be sufficient. If you have other reasons to add latin1, it would be good to know

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-size: small Minimal code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants