Skip to content

FIX: FetchMany(number of rows) ignores batch size with LOB columns - #346

Merged
gargsaumya merged 8 commits into
microsoft:mainfrom
dlevy-msft-sql:Fix-fetchmany(num_rows)
Jan 7, 2026
Merged

gargsaumya merged 8 commits into
microsoft:mainfrom
dlevy-msft-sql:Fix-fetchmany(num_rows)

Conversation

@dlevy-msft-sql

@dlevy-msft-sql David Levy (dlevy-msft-sql) commented Nov 25, 2025 •

Copy link
Copy Markdown
Contributor

Work Item / Issue Reference

GitHub Issue: #345


Summary

Fixes FetchMany(number of rows) ignores batch size when table contains an LOB

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a bug where FetchMany(number of rows) ignores the batch size parameter when tables contain LOB (Large Object) columns such as NVARCHAR(MAX). The fix ensures that when LOB columns are detected, the row-by-row fetch path properly limits the number of rows fetched to the specified batch size.

Key Changes:

  • Modified the LOB fetch loop in C++ to respect the fetchSize parameter by adding a loop condition check
  • Added a new lob_wvarchar_column (NVARCHAR(MAX)) column to the test table schema to enable LOB testing
  • Created dedicated test functions to validate fetch operations (fetchone, fetchmany, fetchall) with LOB columns present

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 9 comments.

File Description
mssql_python/pybind/ddbc_bindings.cpp Fixed FetchMany_wrap to break the LOB fetch loop when numRowsFetched reaches fetchSize, preventing infinite fetching
tests/test_004_cursor.py Added lob_wvarchar_column to test table, updated test data, and added new test functions to validate fetch behavior with LOB columns

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread tests/test_004_cursor.py Outdated
Comment thread tests/test_004_cursor.py Outdated
Comment thread tests/test_004_cursor.py Outdated
Comment thread tests/test_004_cursor.py Outdated
Comment thread mssql_python/pybind/ddbc_bindings.cpp
Comment thread tests/test_004_cursor.py Outdated
Comment thread tests/test_004_cursor.py
Comment thread tests/test_004_cursor.py Outdated
Comment thread tests/test_004_cursor.py Outdated
@dlevy-msft-sql David Levy (dlevy-msft-sql) changed the title Fix for FetchMany(number of rows) ignores batch size when table conta… Fix: FetchMany(number of rows) ignores batch size when table conta… Nov 25, 2025
@dlevy-msft-sql David Levy (dlevy-msft-sql) changed the title Fix: FetchMany(number of rows) ignores batch size when table conta… FIX: FetchMany(number of rows) ignores batch size when table conta… Nov 25, 2025
@dlevy-msft-sql David Levy (dlevy-msft-sql) changed the title FIX: FetchMany(number of rows) ignores batch size when table conta… FIX: FetchMany(number of rows) ignores batch size with LOB columns Nov 25, 2025
@dlevy-msft-sql David Levy (dlevy-msft-sql) added bug Something isn't working pr-size: small Minimal code update labels Nov 25, 2025
Comment thread mssql_python/pybind/ddbc_bindings.cpp
Comment thread tests/test_004_cursor.py

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few comments to be addressed.

gargsaumya please review this PR.

@dlevy-msft-sql

Copy link
Copy Markdown
Contributor Author

Sumit Sarabhai (@sumitmsft) this one is ready for review again. The code coverage report issues seem to be breaking the workflow.

@github-actions

github-actions Bot commented Jan 5, 2026 •

Copy link
Copy Markdown

📊 Code Coverage Report

🔥 Diff Coverage

100%


🎯 Overall Coverage

76%


📈 Total Lines Covered: 5439 out of 7114
📁 Project: mssql-python


Diff Coverage

Diff: main...HEAD, staged and unstaged changes

  • mssql_python/pybind/ddbc_bindings.cpp (100%)

Summary

  • Total: 3 lines
  • Missing: 0 lines
  • Coverage: 100%

📋 Files Needing Attention

📉 Files with overall lowest coverage (click to expand)
mssql_python.pybind.logger_bridge.hpp: 58.8%
mssql_python.pybind.logger_bridge.cpp: 59.2%
mssql_python.row.py: 66.2%
mssql_python.helpers.py: 67.5%
mssql_python.pybind.ddbc_bindings.cpp: 69.4%
mssql_python.pybind.ddbc_bindings.h: 71.7%
mssql_python.pybind.connection.connection.cpp: 73.6%
mssql_python.ddbc_bindings.py: 79.6%
mssql_python.pybind.connection.connection_pool.cpp: 79.6%
mssql_python.connection.py: 83.9%

🔗 Quick Links

⚙️ Build Summary 📋 Coverage Details

View Azure DevOps Build

Browse Full Coverage Report

@gargsaumya gargsaumya left a comment •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!
This PR will also correctly resolve #390, validated this locally with VARCHAR(MAX) columns. Approving.

@gargsaumya
gargsaumya dismissed Sumit Sarabhai (sumitmsft)’s stale review January 7, 2026 08:40

Closing this review - the fix has been validated.

@gargsaumya
gargsaumya merged commit 356ed50 into microsoft:main Jan 7, 2026
26 checks passed
@dlevy-msft-sql
David Levy (dlevy-msft-sql) deleted the Fix-fetchmany(num_rows) branch January 10, 2026 21:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working pr-size: small Minimal code update

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants