Skip to content

Commit

Permalink
Fix #44 - Invalid affected_row count on multiple statements
Browse files Browse the repository at this point in the history
  • Loading branch information
pcisar committed Jan 3, 2025
1 parent 60bca03 commit 2543217
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [1.10.9] - 2025-01-03

### Fixed

- Fix #44 - Invalid affected_row count on multiple statements

## [1.10.8] - 2024-12-23

### Fixed
Expand Down
5 changes: 5 additions & 0 deletions docs/changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
Changelog
#########

Version 1.10.9
==============

- Fix #44 - Invalid affected_row count on multiple statements

Version 1.10.8
==============

Expand Down
2 changes: 1 addition & 1 deletion src/firebird/driver/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,4 @@
Server, Statement)

#: Current driver version, SEMVER string.
__VERSION__ = '1.10.8'
__VERSION__ = '1.10.9'
14 changes: 13 additions & 1 deletion src/firebird/driver/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -4134,7 +4134,19 @@ def affected_rows(self) -> int:
"""
if self._stmt is None:
return -1
return sum(self._stmt.info.get_info(StmtInfoCode.RECORDS).values())
rows: Dict[ReqInfoCode, int] = self._stmt.info.get_info(StmtInfoCode.RECORDS)
code: ReqInfoCode = None
if self._stmt.type in (StatementType.SELECT, StatementType.SELECT_FOR_UPD):
code = ReqInfoCode.SELECT_COUNT
elif self._stmt.type == StatementType.UPDATE:
code = ReqInfoCode.UPDATE_COUNT
elif self._stmt.type == StatementType.INSERT:
code = ReqInfoCode.INSERT_COUNT
elif self._stmt.type == StatementType.DELETE:
code = ReqInfoCode.DELETE_COUNT
else:
return -1
return rows[code]
rowcount = affected_rows
@property
def transaction(self) -> TransactionManager:
Expand Down
11 changes: 11 additions & 0 deletions tests/test_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -1043,6 +1043,17 @@ def test_affected_rows(self):
rcount = 1
self.assertEqual(cur.affected_rows, rcount)
self.assertEqual(cur.rowcount, rcount)
def test_affected_rows_with_multiple_execute_statements_and_different_command(self):
with self.con.cursor() as cur:
cur.execute("insert into project (proj_id, proj_name) values ('FOO', 'BAR')")
cur.execute("update project set proj_name = 'RAB' where proj_id = 'FOO'")
cur.fetchone()
if sys.platform == 'win32':
rcount = 6
else:
rcount = 1
self.assertEqual(cur.affected_rows, rcount)
self.assertEqual(cur.rowcount, rcount)
def test_name(self):
def assign_name():
cur.set_cursor_name('testx')
Expand Down

0 comments on commit 2543217

Please sign in to comment.