Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 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
39 changes: 18 additions & 21 deletions mssql_python/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -379,27 +379,24 @@ def _map_sql_type(self, param, parameters_list, i):
False,
)

if isinstance(param, bytes):
# Use VARBINARY for Python bytes/bytearray since they are variable-length by nature.
# This avoids storage waste from BINARY's zero-padding and matches Python's semantics.
return (
ddbc_sql_const.SQL_VARBINARY.value,
ddbc_sql_const.SQL_C_BINARY.value,
len(param),
0,
False,
)

if isinstance(param, bytearray):
# Use VARBINARY for Python bytes/bytearray since they are variable-length by nature.
# This avoids storage waste from BINARY's zero-padding and matches Python's semantics.
return (
ddbc_sql_const.SQL_VARBINARY.value,
ddbc_sql_const.SQL_C_BINARY.value,
len(param),
0,
False,
)
if isinstance(param, (bytes, bytearray)):
length = len(param)
if length > 8000: # Use VARBINARY(MAX) for large blobs
return (
ddbc_sql_const.SQL_VARBINARY.value,
ddbc_sql_const.SQL_C_BINARY.value,
0,
0,
True
)
else: # Small blobs → direct binding
return (
ddbc_sql_const.SQL_VARBINARY.value,
ddbc_sql_const.SQL_C_BINARY.value,
max(length, 1),
0,
False
)

if isinstance(param, datetime.datetime):
return (
Expand Down
Loading