Skip to content

Commit 356ed50

Browse files
FIX: FetchMany(number of rows) ignores batch size with LOB columns (#346)
### Work Item / Issue Reference <!-- IMPORTANT: Please follow the PR template guidelines below. For mssql-python maintainers: Insert your ADO Work Item ID below (e.g. AB#37452) For external contributors: Insert Github Issue number below (e.g. #149) Only one reference is required - either GitHub issue OR ADO Work Item. --> <!-- External contributors: GitHub Issue --> > GitHub Issue: #345 ------------------------------------------------------------------- ### Summary Fixes FetchMany(number of rows) ignores batch size when table contains an LOB <!-- ### PR Title Guide > For feature requests FEAT: (short-description) > For non-feature requests like test case updates, config updates , dependency updates etc CHORE: (short-description) > For Fix requests FIX: Update FetchMany to break at batch size and update unit tests > For doc update requests DOC: (short-description) > For Formatting, indentation, or styling update STYLE: (short-description) > For Refactor, without any feature changes REFACTOR: (short-description) > For release related changes, without any feature changes RELEASE: #<RELEASE_VERSION> (short-description) ### Contribution Guidelines External contributors: - Create a GitHub issue first: https://github.com/microsoft/mssql-python/issues/new - Link the GitHub issue in the "GitHub Issue" section above - Follow the PR title format and provide a meaningful summary mssql-python maintainers: - Create an ADO Work Item following internal processes - Link the ADO Work Item in the "ADO Work Item" section above - Follow the PR title format and provide a meaningful summary --> --------- Co-authored-by: gargsaumya <saumyagarg.100@gmail.com>
1 parent 1187a4a commit 356ed50

2 files changed

Lines changed: 274 additions & 13 deletions

File tree

mssql_python/pybind/ddbc_bindings.cpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4033,13 +4033,15 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
40334033
lobColumns.push_back(i + 1); // 1-based
40344034
}
40354035
}
4036-
4036+
4037+
// Initialized to 0 for LOB path counter; overwritten by ODBC in non-LOB path;
4038+
SQLULEN numRowsFetched = 0;
40374039
// If we have LOBs → fall back to row-by-row fetch + SQLGetData_wrap
40384040
if (!lobColumns.empty()) {
40394041
LOG("FetchMany_wrap: LOB columns detected (%zu columns), using per-row "
40404042
"SQLGetData path",
40414043
lobColumns.size());
4042-
while (true) {
4044+
while (numRowsFetched < (SQLULEN)fetchSize) {
40434045
ret = SQLFetch_ptr(hStmt);
40444046
if (ret == SQL_NO_DATA)
40454047
break;
@@ -4050,6 +4052,7 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
40504052
SQLGetData_wrap(StatementHandle, numCols, row, charEncoding,
40514053
wcharEncoding); // <-- streams LOBs correctly
40524054
rows.append(row);
4055+
numRowsFetched++;
40534056
}
40544057
return SQL_SUCCESS;
40554058
}
@@ -4063,8 +4066,7 @@ SQLRETURN FetchMany_wrap(SqlHandlePtr StatementHandle, py::list& rows, int fetch
40634066
LOG("FetchMany_wrap: Error when binding columns - SQLRETURN=%d", ret);
40644067
return ret;
40654068
}
4066-
4067-
SQLULEN numRowsFetched;
4069+
40684070
SQLSetStmtAttr_ptr(hStmt, SQL_ATTR_ROW_ARRAY_SIZE, (SQLPOINTER)(intptr_t)fetchSize, 0);
40694071
SQLSetStmtAttr_ptr(hStmt, SQL_ATTR_ROWS_FETCHED_PTR, &numRowsFetched, 0);
40704072

0 commit comments

Comments
 (0)