Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
10 changes: 6 additions & 4 deletions mssql_python/pybind/ddbc_bindings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4012,13 +4012,15 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
lobColumns.push_back(i + 1); // 1-based
}
}


// Initialized to 0 for LOB path counter; overwritten by ODBC in non-LOB path;
SQLULEN numRowsFetched = 0;
// If we have LOBs → fall back to row-by-row fetch + SQLGetData_wrap
if (!lobColumns.empty()) {
LOG("FetchMany_wrap: LOB columns detected (%zu columns), using per-row "
"SQLGetData path",
lobColumns.size());
while (true) {
while (numRowsFetched < (SQLULEN)fetchSize) {
ret = SQLFetch_ptr(hStmt);
if (ret == SQL_NO_DATA)
break;
Expand All @@ -4029,6 +4031,7 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
SQLGetData_wrap(StatementHandle, numCols, row, charEncoding,
wcharEncoding); // <-- streams LOBs correctly
rows.append(row);
numRowsFetched++;
}
return SQL_SUCCESS;
}
Expand All @@ -4042,8 +4045,7 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
LOG("FetchMany_wrap: Error when binding columns - SQLRETURN=%d", ret);
return ret;
}

SQLULEN numRowsFetched;

SQLSetStmtAttr_ptr(hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)(intptr_t)fetchSize, 0);
SQLSetStmtAttr_ptr(hStmt, SQL_ATTR_ROWS_FETCHED_PTR, &numRowsFetched, 0);

Expand Down
Loading
Loading