Skip to content

Commit b227c64

Browse files
author
Theekshna Kotian
committed
Merged PR 5330: Fix fetching of var data + Error for unsupported types + fix 2 crashes
Fix fetching of var data + Error for unsupported types + fix some crashes ---- #### AI description (iteration 1) #### PR Classification Bug fix #### PR Summary This pull request addresses issues with fetching variable-length data, adds error handling for unsupported data types, and fixes several crashes. - `mssql_python/pybind/ddbc_bindings.cpp`: Improved handling of variable-length data, added detailed logging and exceptions for unsupported data types, and fixed crashes related to data fetching. - Added `HandleZeroColumnSizeAtFetch` function to manage cases where column size is zero. - Replaced `SQL_NUMERIC_SIZE` with `MAX_DIGITS_IN_NUMERIC` for better numeric data handling. - Enhanced logging for errors during data retrieval in `SQLGetData_wrap`. <!-- GitOpsUserAgent=GitOps.Apps.Server.pullrequestcopilot --> Related work items: #33925
1 parent b5a889f commit b227c64

File tree

2 files changed

+401
-225
lines changed

2 files changed

+401
-225
lines changed

mssql_python/cursor.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,6 +555,7 @@ def execute(self, operation: str, *parameters, use_prepare: bool = True, reset_c
555555
self.last_executed_stmt = operation
556556

557557
# Update rowcount after execution
558+
# TODO: rowcount return code from SQL needs to be handled
558559
self.rowcount = ddbc_bindings.DDBCSQLRowCount(self.hstmt.value)
559560

560561
# Initialize description after execution
@@ -572,7 +573,7 @@ def executemany(self, operation: str, seq_of_parameters: list) -> None:
572573
Error: If the operation fails.
573574
"""
574575
self._check_closed() # Check if the cursor is closed
575-
576+
576577
# Reset the cursor once before the loop
577578
self._reset_cursor()
578579

@@ -657,6 +658,7 @@ def fetchmany(self, size: int = None) -> List[tuple]:
657658
# Fetch the next set of rows
658659
rows = []
659660
ret = ddbc_bindings.DDBCSQLFetchMany(self.hstmt.value, rows, size)
661+
check_error(odbc_sql_const.SQL_HANDLE_STMT.value, self.hstmt.value, ret)
660662
if ret == odbc_sql_const.SQL_NO_DATA.value:
661663
return []
662664
return rows
@@ -676,6 +678,7 @@ def fetchall(self) -> List[tuple]:
676678
# Fetch all remaining rows
677679
rows = []
678680
ret = ddbc_bindings.DDBCSQLFetchAll(self.hstmt.value, rows)
681+
check_error(odbc_sql_const.SQL_HANDLE_STMT.value, self.hstmt.value, ret)
679682
if ret != odbc_sql_const.SQL_NO_DATA.value:
680683
return []
681684
return list(rows)
@@ -694,6 +697,7 @@ def nextset(self) -> Union[bool, None]:
694697

695698
# Skip to the next result set
696699
ret = ddbc_bindings.DDBCSQLMoreResults(self.hstmt.value)
700+
check_error(odbc_sql_const.SQL_HANDLE_STMT.value, self.hstmt.value, ret)
697701
if ret == odbc_sql_const.SQL_NO_DATA.value:
698702
return False
699703
return True

0 commit comments

Comments
 (0)