Skip to content

Commit b47655b

Browse files
committed
working
1 parent ffd36d4 commit b47655b

File tree

1 file changed

+1
-53
lines changed

1 file changed

+1
-53
lines changed

mssql_python/cursor.py

Lines changed: 1 addition & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -619,51 +619,11 @@ def execute(
619619

620620
# Initialize description after execution
621621
self._initialize_description()
622-
623-
624-
# def executemany(self, operation: str, seq_of_parameters: list) -> None:
625-
# self._check_closed()
626-
# self._reset_cursor()
627-
628-
# if not seq_of_parameters:
629-
# return
630-
631-
# # Transpose to column-major format
632-
# columns = list(zip(*seq_of_parameters)) # Each column: tuple of values
633-
# sample_params = seq_of_parameters[0]
634-
# param_info = ddbc_bindings.ParamInfo
635-
636-
# parameters_type = []
637-
# for i, sample_val in enumerate(sample_params):
638-
# paraminfo = self._create_parameter_types_list(sample_val, param_info, sample_params, i)
639-
640-
# # Fix: Adjust string column sizes based on actual max length across all rows
641-
# if isinstance(sample_val, str):
642-
# max_len = max(
643-
# (len(v) for v in columns[i] if isinstance(v, str)),
644-
# default=1 # fallback if all values are None
645-
# )
646-
# paraminfo.columnSize = max_len
647-
648-
# parameters_type.append(paraminfo)
649-
650-
# # Now execute with adjusted parameter types
651-
# ret = ddbc_bindings.SQLExecuteMany(
652-
# self.hstmt, operation, columns, parameters_type, len(seq_of_parameters)
653-
# )
654-
# check_error(ddbc_sql_const.SQL_HANDLE_STMT.value, self.hstmt, ret)
655-
656-
# self.rowcount = ddbc_bindings.DDBCSQLRowCount(self.hstmt)
657-
# self._initialize_description()
658622

659623
def _transpose_rowwise_to_columnwise(self, seq_of_parameters: list) -> list:
660624
"""
661625
Convert list of rows (row-wise) into list of columns (column-wise),
662626
for array binding via ODBC.
663-
664-
Example:
665-
Input: [(1, "a"), (2, "b")]
666-
Output: [[1, 2], ["a", "b"]]
667627
"""
668628
if not seq_of_parameters:
669629
return []
@@ -689,36 +649,24 @@ def executemany(self, operation: str, seq_of_parameters: list) -> None:
689649
self.rowcount = 0
690650
return
691651

692-
# # Infer types from the first row
693-
# first_row = list(seq_of_parameters[0])
694-
# param_info = ddbc_bindings.ParamInfo
695-
# parameters_type = [
696-
# self._create_parameter_types_list(param, param_info, first_row, i)
697-
# for i, param in enumerate(first_row)
698-
# ]
699652
param_info = ddbc_bindings.ParamInfo
700653
param_count = len(seq_of_parameters[0])
701654
parameters_type = []
702655

703656
for col_index in range(param_count):
704-
# Use the longest string (or most precise value) in that column for inference
705657
column = [row[col_index] for row in seq_of_parameters]
706658
sample_value = column[0]
707659

708-
# For strings, pick the value with max len
709660
if isinstance(sample_value, str):
710661
sample_value = max(column, key=lambda s: len(str(s)) if s is not None else 0)
711662

712-
# For decimals, use the one with highest precision
713663
elif isinstance(sample_value, decimal.Decimal):
714664
sample_value = max(column, key=lambda d: len(d.as_tuple().digits) if d is not None else 0)
715665

716666
param = sample_value
717-
dummy_row = list(seq_of_parameters[0]) # to pass for `_get_numeric_data()` mutation
667+
dummy_row = list(seq_of_parameters[0])
718668
parameters_type.append(self._create_parameter_types_list(param, param_info, dummy_row, col_index))
719669

720-
721-
# Transpose to column-wise format for array binding
722670
columnwise_params = self._transpose_rowwise_to_columnwise(seq_of_parameters)
723671

724672
# Execute batched statement

0 commit comments

Comments
 (0)