FIX: Decode Raw UTF-16 data from Conn.getinfo() by bewithgaurav · Pull Request #340 · microsoft/mssql-python

Pull request overview

This pull request fixes a UTF-16 encoding bug in the getinfo() method that was causing null bytes to appear in string values returned from SQL Server. The fix implements a proper encoding fallback mechanism (UTF-16LE → UTF-8) to handle ODBC's wide-character API responses, adds comprehensive test coverage for the encoding scenarios, and removes redundant DLL copying logic from the Windows build script.

Key Changes:

  • Replaced single UTF-8 decoding attempt with a multi-encoding fallback strategy (UTF-16LE first, then UTF-8)
  • Added four new test cases covering UTF-16 decoding success, UTF-8 fallback, encoding failure, and null byte detection
  • Removed obsolete msvcp140.dll redistribution logic from the build script

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
mssql_python/connection.py Implements UTF-16LE decoding with UTF-8 fallback in getinfo() method for proper ODBC string handling
tests/test_003_connection.py Adds comprehensive test coverage for UTF-16 encoding scenarios including primary path, fallback path, and failure cases
mssql_python/pybind/build.bat Removes redundant Visual C++ redistributable DLL copying logic

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.