Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions mssql_python/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ def _map_sql_type( # pylint: disable=too-many-arguments,too-many-positional-arg
logger.debug("_map_sql_type: Mapping param index=%d, type=%s", i, type(param).__name__)
if param is None:
logger.debug("_map_sql_type: NULL parameter - index=%d", i)
# GH-610: Send SQL_UNKNOWN_TYPE to C++ where the describe-cache
# in BindParameters / BindParameterArray resolves the correct
# type via SQLDescribeParam (cached after first call).
return (
ddbc_sql_const.SQL_UNKNOWN_TYPE.value,
ddbc_sql_const.SQL_C_DEFAULT.value,
Expand Down Expand Up @@ -2335,14 +2338,10 @@ def executemany( # pylint: disable=too-many-locals,too-many-branches,too-many-s
max_val=max_val,
)

# For executemany with all-NULL columns, SQL_UNKNOWN_TYPE doesn't work
# with array binding. Fall back to SQL_VARCHAR as a safe default.
if (
sample_value is None
and paraminfo.paramSQLType == ddbc_sql_const.SQL_UNKNOWN_TYPE.value
):
paraminfo.paramSQLType = ddbc_sql_const.SQL_VARCHAR.value
paraminfo.columnSize = 1
# GH-610: all-NULL columns now pass SQL_UNKNOWN_TYPE to C++,
# where BindParameterArray resolves the correct type via the
# SQLDescribeParam cache. The previous SQL_VARCHAR hardcoded
# fallback was removed because it broke VARBINARY columns.

# Override DECIMAL/NUMERIC to use SQL_C_CHAR string binding.
# _map_sql_type may return SQL_C_NUMERIC (expecting NumericData structs)
Expand Down
Loading
Loading