File tree Expand file tree Collapse file tree 5 files changed +36
-2
lines changed Expand file tree Collapse file tree 5 files changed +36
-2
lines changed Original file line number Diff line number Diff line change @@ -4,6 +4,12 @@ All notable changes to this project will be documented in this file.
44The format is based on [ Keep a Changelog] ( http://keepachangelog.com/ )
55and 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
Original file line number Diff line number Diff line change 22Changelog
33#########
44
5+ Version 1.10.9
6+ ==============
7+
8+ - Fix #44 - Invalid affected_row count on multiple statements
9+
510Version 1.10.8
611==============
712
Original file line number Diff line number Diff line change 6161 Server , Statement )
6262
6363#: Current driver version, SEMVER string.
64- __VERSION__ = '1.10.8 '
64+ __VERSION__ = '1.10.9 '
Original file line number Diff line number Diff 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 :
Original file line number Diff line number Diff 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' )
You can’t perform that action at this time.
0 commit comments