Skip to content

Commit 2543217

Browse files
committed
Fix #44 - Invalid affected_row count on multiple statements
1 parent 60bca03 commit 2543217

File tree

5 files changed

+36
-2
lines changed

5 files changed

+36
-2
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [1.10.9] - 2025-01-03
8+
9+
### Fixed
10+
11+
- Fix #44 - Invalid affected_row count on multiple statements
12+
713
## [1.10.8] - 2024-12-23
814

915
### Fixed

docs/changelog.txt

+5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@
22
Changelog
33
#########
44

5+
Version 1.10.9
6+
==============
7+
8+
- Fix #44 - Invalid affected_row count on multiple statements
9+
510
Version 1.10.8
611
==============
712

src/firebird/driver/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -61,4 +61,4 @@
6161
Server, Statement)
6262

6363
#: Current driver version, SEMVER string.
64-
__VERSION__ = '1.10.8'
64+
__VERSION__ = '1.10.9'

src/firebird/driver/core.py

+13-1
Original file line numberDiff line numberDiff line change
@@ -4134,7 +4134,19 @@ def affected_rows(self) -> int:
41344134
"""
41354135
if self._stmt is None:
41364136
return -1
4137-
return sum(self._stmt.info.get_info(StmtInfoCode.RECORDS).values())
4137+
rows: Dict[ReqInfoCode, int] = self._stmt.info.get_info(StmtInfoCode.RECORDS)
4138+
code: ReqInfoCode = None
4139+
if self._stmt.type in (StatementType.SELECT, StatementType.SELECT_FOR_UPD):
4140+
code = ReqInfoCode.SELECT_COUNT
4141+
elif self._stmt.type == StatementType.UPDATE:
4142+
code = ReqInfoCode.UPDATE_COUNT
4143+
elif self._stmt.type == StatementType.INSERT:
4144+
code = ReqInfoCode.INSERT_COUNT
4145+
elif self._stmt.type == StatementType.DELETE:
4146+
code = ReqInfoCode.DELETE_COUNT
4147+
else:
4148+
return -1
4149+
return rows[code]
41384150
rowcount = affected_rows
41394151
@property
41404152
def transaction(self) -> TransactionManager:

tests/test_driver.py

+11
Original file line numberDiff line numberDiff line change
@@ -1043,6 +1043,17 @@ def test_affected_rows(self):
10431043
rcount = 1
10441044
self.assertEqual(cur.affected_rows, rcount)
10451045
self.assertEqual(cur.rowcount, rcount)
1046+
def test_affected_rows_with_multiple_execute_statements_and_different_command(self):
1047+
with self.con.cursor() as cur:
1048+
cur.execute("insert into project (proj_id, proj_name) values ('FOO', 'BAR')")
1049+
cur.execute("update project set proj_name = 'RAB' where proj_id = 'FOO'")
1050+
cur.fetchone()
1051+
if sys.platform == 'win32':
1052+
rcount = 6
1053+
else:
1054+
rcount = 1
1055+
self.assertEqual(cur.affected_rows, rcount)
1056+
self.assertEqual(cur.rowcount, rcount)
10461057
def test_name(self):
10471058
def assign_name():
10481059
cur.set_cursor_name('testx')

0 commit comments

Comments
 (0)