Skip to content

Connection.getinfo(SQL_DATABASE_NAME) returns string with embedded NUL characters #762

Description

@jonahmdot

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.

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage neededFor new issues, not triaged yet.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions