firebird
firebird copied to clipboard
FOR EXECUTE STATEMENT cursors are unstable
We have announced 'cursor stability' for most types of queries in v3, but this improvement does not affect FOR EXECUTE STATEMENT cursors. Consider the following example:
create table t (id int, val int);
insert into t values (1, 1);
insert into t values (2, 2);
insert into t values (3, 3);
commit;
set term ^;
execute block returns (val int)
as begin
for
select val from t into :val
do begin
delete from t where id = 3;
end
suspend;
end^
execute block returns (val int)
as begin
for
execute statement 'select val from t' into :val
do begin
delete from t where id = 3;
end
suspend;
end^
set term ;^
rollback;
Here we have two kinds of loop iterating through all records in table T and returning the value of the last record. Inside the loop there's a DELETE statement that affects the record set. Case with a native FOR loop returns 3 but case with FOR EXECUTE STATEMENT loop returns 2, i.e. its cursor does not return the deleted record. This behaviour is contradictory to what is expected from a stable cursor.