Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
8e3a39e
FIX: Handle empty data
bewithgaurav Aug 29, 2025
08f9a4c
undo some stuff
bewithgaurav Aug 29, 2025
38381fe
0 length fix and tests
bewithgaurav Aug 29, 2025
229c957
restore condition and cleanup
bewithgaurav Aug 29, 2025
7dc1135
fixed assert
bewithgaurav Aug 29, 2025
2255e50
Merge branch 'main' into bewithgaurav/fix_blank_columns
bewithgaurav Aug 29, 2025
40a008b
Merge branch 'main' of https://github.com/microsoft/mssql-python into…
bewithgaurav Sep 1, 2025
42785d9
Merge branch 'main' into bewithgaurav/fix_blank_columns
bewithgaurav Sep 3, 2025
96e59cc
FIX: Unix handling in Executemany
bewithgaurav Sep 3, 2025
1a0275d
Merge branch 'main' of https://github.com/microsoft/mssql-python into…
bewithgaurav Sep 3, 2025
7a4ded9
Merge branch 'bewithgaurav/fix_blank_columns' of https://github.com/m…
bewithgaurav Sep 3, 2025
18c9226
tests
bewithgaurav Sep 3, 2025
28d8441
Undo binary fixes since its in another branch now
bewithgaurav Sep 3, 2025
7969a93
add edgecase test
bewithgaurav Sep 3, 2025
283a999
test cleanup
bewithgaurav Sep 3, 2025
4b708b3
test cleanup
bewithgaurav Sep 3, 2025
2ce421c
add binary fix
bewithgaurav Sep 4, 2025
85d44ac
fix
bewithgaurav Sep 4, 2025
ca3d047
comment for clarification
bewithgaurav Sep 4, 2025
e8609d4
merge conflicts
bewithgaurav Sep 8, 2025
cf51e0c
added more tests
bewithgaurav Sep 8, 2025
94237da
reversing unwanted changes
bewithgaurav Sep 8, 2025
282a52a
reversing unwanted changes
bewithgaurav Sep 8, 2025
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
26 changes: 8 additions & 18 deletions mssql_python/cursor.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,33 +380,21 @@ def _map_sql_type(self, param, parameters_list, i):
)

if isinstance(param, bytes):
if len(param) > 8000: # Assuming VARBINARY(MAX) for long byte arrays
return (
ddbc_sql_const.SQL_VARBINARY.value,
ddbc_sql_const.SQL_C_BINARY.value,
len(param),
0,
False,
)
# 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_BINARY.value,
ddbc_sql_const.SQL_VARBINARY.value,
ddbc_sql_const.SQL_C_BINARY.value,
len(param),
0,
False,
)

if isinstance(param, bytearray):
if len(param) > 8000: # Assuming VARBINARY(MAX) for long byte arrays
return (
ddbc_sql_const.SQL_VARBINARY.value,
ddbc_sql_const.SQL_C_BINARY.value,
len(param),
0,
True,
)
# 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_BINARY.value,
ddbc_sql_const.SQL_VARBINARY.value,
ddbc_sql_const.SQL_C_BINARY.value,
len(param),
0,
Expand Down Expand Up @@ -848,6 +836,8 @@ def _select_best_sample_value(column):
return max(non_nulls, key=lambda s: len(str(s)))
if all(isinstance(v, datetime.datetime) for v in non_nulls):
return datetime.datetime.now()
if all(isinstance(v, (bytes, bytearray)) for v in non_nulls):
return max(non_nulls, key=lambda b: len(b))
if all(isinstance(v, datetime.date) for v in non_nulls):
return datetime.date.today()
return non_nulls[0] # fallback
Expand Down
Loading