Skip to content

Commit 4ea32c7

Browse files
committed
cleanup
1 parent 1daa474 commit 4ea32c7

File tree

2 files changed

+4
-62
lines changed

2 files changed

+4
-62
lines changed

mssql_python/cursor.py

Lines changed: 3 additions & 61 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),
662-
for array binding via ODBC.
663-
664-
Example:
665-
Input: [(1, "a"), (2, "b")]
666-
Output: [[1, 2], ["a", "b"]]
626+
for array binding.
667627
"""
668628
if not seq_of_parameters:
669629
return []
@@ -688,39 +648,23 @@ def executemany(self, operation: str, seq_of_parameters: list) -> None:
688648
if not seq_of_parameters:
689649
self.rowcount = 0
690650
return
691-
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-
# ]
699651
param_info = ddbc_bindings.ParamInfo
700652
param_count = len(seq_of_parameters[0])
701653
parameters_type = []
702654

703655
for col_index in range(param_count):
704-
# Use the longest string (or most precise value) in that column for inference
705656
column = [row[col_index] for row in seq_of_parameters]
706657
sample_value = column[0]
707-
708-
# For strings, pick the value with max len
709658
if isinstance(sample_value, str):
710659
sample_value = max(column, key=lambda s: len(str(s)) if s is not None else 0)
711-
712-
# For decimals, use the one with highest precision
713660
elif isinstance(sample_value, decimal.Decimal):
714661
sample_value = max(column, key=lambda d: len(d.as_tuple().digits) if d is not None else 0)
715662

716663
param = sample_value
717-
dummy_row = list(seq_of_parameters[0]) # to pass for `_get_numeric_data()` mutation
664+
dummy_row = list(seq_of_parameters[0])
718665
parameters_type.append(self._create_parameter_types_list(param, param_info, dummy_row, col_index))
719666

720-
721-
# Transpose to column-wise format for array binding
722667
columnwise_params = self._transpose_rowwise_to_columnwise(seq_of_parameters)
723-
724668
# Execute batched statement
725669
ret = ddbc_bindings.SQLExecuteMany(
726670
self.hstmt,
@@ -729,9 +673,7 @@ def executemany(self, operation: str, seq_of_parameters: list) -> None:
729673
parameters_type,
730674
len(seq_of_parameters)
731675
)
732-
check_error(ddbc_sql_const.SQL_HANDLE_STMT.value, self.hstmt, ret)
733-
734-
self.rowcount = len(seq_of_parameters)
676+
self.rowcount = ddbc_bindings.DDBCSQLRowCount(self.hstmt)
735677
self.last_executed_stmt = operation
736678
self._initialize_description()
737679

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ SQLRETURN BindParameterArray(SQLHANDLE hStmt,
10121012
", len: " + std::to_string(wstr.length()) +
10131013
" > columnSize: " + std::to_string(info.columnSize));
10141014
}
1015-
std::memcpy(wcharArray + i * (info.columnSize + 1), wstr.c_str(), (wstr.length() + 1) * sizeof(SQLWCHAR));
1015+
std::wcsncpy(wcharArray + i * (info.columnSize + 1), wstr.c_str(), info.columnSize + 1);
10161016
strLenOrIndArray[i] = SQL_NTS;
10171017
}
10181018
dataPtr = wcharArray;

0 commit comments

Comments
 (0)