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, and fetchall methods in mssql_python/cursor.py to set rowcount correctly after each fetch operation, including for empty result sets. This ensures rowcount is 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.py to verify rowcount updates after fetchone, fetchmany, and fetchall, 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.