Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion fbconn/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ func (sd *StatementDescription) HaveSingletonResult() bool {
}

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

}

func (sd *StatementDescription) EncodeBatchRow(values [][]byte) ([]byte, error) {
Expand Down
4 changes: 1 addition & 3 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,7 @@ begin
end`, "rows_counts_test", "rows_counts_test", "rows_counts_test"))
require.NoError(t, err)

// Firebird reports counts for all operations inside the block (including internal reads),
// so the aggregated RowsAffected should reflect the sum returned by isc_info_sql_records.
require.EqualValues(t, 5, ct.RowsAffected())
require.EqualValues(t, 3, ct.RowsAffected())
})
}

Expand Down