Repository navigation
Fix calculation of number of affected rows. - #30
Conversation
| if modifiedCount != 0 { | ||
| return modifiedCount | ||
| } | ||
| return sd.StatementInfo.Counts.SelectCount |
There was a problem hiding this comment.
There remains the case where there are zero changes within the EXECUTE BLOCK.
The table pr30_live_counts(id integer primary key, val integer) contains a single row: (1, 10). Let's execute the block:
execute block as
declare v integer;
begin
select id
from pr30_live_counts
where id = 1
into :v;
update pr30_live_counts
set val = val + 1
where id = -1;
endThe block read one row, but the UPDATE did not change anything. The server returns:
StatementType = 8(isc_info_sql_stmt_exec_procedure);SelectCount = 1;InsertCount = UpdateCount = DeleteCount = 0.
The data in the table remains unchanged. However, RowsAffected() returns 1 instead of the expected 0. This is reproducible via fbconn and database/sql.
The reason is that when modifiedCount == 0, the system switches to SelectCount, even though an anonymous block with zero changes was executed.
| func (sd *StatementDescription) GetAffectedCount() int64 { | ||
| return sd.StatementInfo.Counts.SelectCount + sd.StatementInfo.Counts.InsertCount + sd.StatementInfo.Counts.UpdateCount + sd.StatementInfo.Counts.DeleteCount | ||
| modifiedCount := sd.StatementInfo.Counts.InsertCount + sd.StatementInfo.Counts.UpdateCount + sd.StatementInfo.Counts.DeleteCount | ||
| if modifiedCount != 0 { |
There was a problem hiding this comment.
The modifiedCount != 0 check is redundant; we can return modifiedCount directly, since a zero sum already produces the same result.
No description provided.