FIX: cursor.rowcount by jahnvi480 · Pull Request #263 · microsoft/mssql-python
Work Item / Issue Reference
GitHub Issue: #258
Summary
This pull request improves the accuracy and consistency of the rowcount attribute in the mssql_python cursor implementation, ensuring it reflects the correct number of rows affected or fetched after various operations. It also introduces comprehensive tests to verify rowcount behavior for different fetch methods and scenarios, including edge cases and specific data types.
Enhancements to rowcount logic:
- Updated
fetchone,fetchmany, andfetchallmethods inmssql_python/cursor.pyto setrowcountcorrectly after each fetch operation, including for empty result sets. This ensuresrowcountis 0 for empty results, and matches the total number of rows fetched for non-empty results.
Expanded test coverage for rowcount:
- Added new tests in
tests/test_004_cursor.pyto verifyrowcountupdates afterfetchone,fetchmany, andfetchall, and to check behavior for inserts, selects, and edge cases such as empty result sets and tables with GUID columns. These tests cover typical usage patterns as well as specific scenarios reported in GitHub issues.