Describe the bug
Connection.getinfo(SQL_DATABASE_NAME) appears to decode the value using UTF-8 instead of UTF-16LE, causing embedded NUL (\x00) characters to appear between every character in the returned database name.
To reproduce
import mssql_python
from mssql_python.constants import GetInfoConstants
conn = mssql_python.connect("<connection string>")
database = conn.getinfo(
GetInfoConstants.SQL_DATABASE_NAME.value,
)
print(database)
print(repr(database))
Expected behavior
print(repr(database)) should output the database name with no NUL characters.
Further technical details
Python version: 3.14
SQL Server version: Azure SQL MI
Operating system: Ubuntu 24.04 devcontainer on WSL
Additional context
Suspected Cause
In Connection.getinfo(), string-valued SQLGetInfo constants are decoded as UTF-16LE using the string_type_constants set.
SQL_DATABASE_NAME does not appear to be included in that set, so it falls through to the generic UTF-8 decoding path.
The set currently includes values such as:
GetInfoConstants.SQL_DATA_SOURCE_NAME.value
GetInfoConstants.SQL_DRIVER_NAME.value
GetInfoConstants.SQL_DRIVER_VER.value
GetInfoConstants.SQL_SERVER_NAME.value
GetInfoConstants.SQL_USER_NAME.value
but appears to be missing:
GetInfoConstants.SQL_DATABASE_NAME.value
Adding SQL_DATABASE_NAME to the UTF-16LE string constants should make its behavior consistent with the other string-valued SQLGetInfo fields.
Describe the bug
Connection.getinfo(SQL_DATABASE_NAME)appears to decode the value using UTF-8 instead of UTF-16LE, causing embedded NUL (\x00) characters to appear between every character in the returned database name.To reproduce
Expected behavior
print(repr(database))should output the database name with no NUL characters.Further technical details
Python version: 3.14
SQL Server version: Azure SQL MI
Operating system: Ubuntu 24.04 devcontainer on WSL
Additional context
Suspected Cause
In
Connection.getinfo(), string-valuedSQLGetInfoconstants are decoded as UTF-16LE using thestring_type_constantsset.SQL_DATABASE_NAMEdoes not appear to be included in that set, so it falls through to the generic UTF-8 decoding path.The set currently includes values such as:
but appears to be missing:
Adding
SQL_DATABASE_NAMEto the UTF-16LE string constants should make its behavior consistent with the other string-valuedSQLGetInfofields.