Skip to content

Fix calculation of number of affected rows. - #30

Merged
P1cheneG merged 4 commits into
FirebirdSQL:mainfrom
P1cheneG:fix_affected_rows_calculating
Nov 18, 2026
Merged

P1cheneG merged 4 commits into
FirebirdSQL:mainfrom
P1cheneG:fix_affected_rows_calculating

Conversation

@P1cheneG

@P1cheneG P1cheneG commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

No description provided.

@P1cheneG
P1cheneG requested a review from MrTeeett November 9, 2026 08:09
@P1cheneG P1cheneG self-assigned this Nov 9, 2026
@P1cheneG P1cheneG added this to the v0.8.0 milestone Nov 9, 2026
Comment thread fbconn/statement.go Outdated
if modifiedCount != 0 {
return modifiedCount
}
return sd.StatementInfo.Counts.SelectCount

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;
end

The 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.

@smirnoffjr smirnoffjr added the bug label Nov 12, 2026
Comment thread fbconn/statement.go Outdated
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 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The modifiedCount != 0 check is redundant; we can return modifiedCount directly, since a zero sum already produces the same result.

@P1cheneG
P1cheneG merged commit fc57c2b into FirebirdSQL:main Nov 18, 2026
28 of 33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants