From 1372ef26ce1704e4d5ab5ef200ddd6371ab3bfed Mon Sep 17 00:00:00 2001 From: pavel-zotov Date: Fri, 25 Aug 2023 21:25:33 +0300 Subject: [PATCH] Added/Updated tests\bugs\gh_7713_test.py: Confirmed problem on 5.0.0.1169. Checked on 5.0.0.1170, 4.0.4.2979 (intermediate snapshots). --- tests/bugs/gh_7713_test.py | 187 +++++++++++++++++++++++++++++++++++++ 1 file changed, 187 insertions(+) create mode 100644 tests/bugs/gh_7713_test.py diff --git a/tests/bugs/gh_7713_test.py b/tests/bugs/gh_7713_test.py new file mode 100644 index 00000000..05ba7e4f --- /dev/null +++ b/tests/bugs/gh_7713_test.py @@ -0,0 +1,187 @@ +#coding:utf-8 + +""" +ID: issue-7713 +ISSUE: https://github.com/FirebirdSQL/firebird/issues/7713 +TITLE: Stability of implicit cursor could be broken, if cursor's select expression is based on view with sub-query in select list, or on table with sub-query in computed field. +DESCRIPTION: +NOTES: + [25.08.2023] pzotov + Confirmed problem on 5.0.0.1169 + Checked on 5.0.0.1170, 4.0.4.2979 (intermediate snapshots). +""" + +import pytest +from firebird.qa import * + +db = db_factory() + +test_script = """ + set list on; + create table test_1 ( + id int generated by default as identity constraint test_1_pk primary key, + name varchar(20) + ); + + create table test_2 ( + id int generated by default as identity constraint test_2_pk primary key, + t1_id int not null, + x int + ); + + alter table test_2 add constraint test_2_fk foreign key (t1_id) references test_1(id) on delete cascade on update cascade; + + create or alter view v_test_1( + id, + x) + as + select + a.id, + case + when a.id > 2 then (select sum(b.x) from test_2 b where b.t1_id < a.id) + else a.id * 10 + end x + from test_1 a + order by a.id + ; + + set term ^; + + create procedure table_aaa_proc + returns ( + id int, + x int) + as + begin + for + select + a.id, + case + when a.id > 2 then (select sum(b.x) from test_2 b where b.t1_id < a.id) + else a.id * 10 + end x + from + test_1 a + into + :id, :x + do + begin + suspend; + end + end + ^ + set term ;^ + + commit; + + insert into test_1 (id, name) values ( 1, '1'); + insert into test_1 (id, name) values ( 2, '2'); + insert into test_1 (id, name) values ( 3, '3'); + commit; + + --################################################################## + + -- All following checks must output for 'X' column if T1_ID =3: + + set term ^; + execute block as + declare variable t1_id int; + declare variable x int; + begin + delete from test_2 b where 0 = 0; + for + select + a.id, a.x + from + v_test_1 a + order by + a.id + into + :t1_id, :x + do + begin + insert into test_2 (t1_id, x) values (:t1_id, :x); + end + + end + ^ + select 'chk-1' as msg, b.t1_id, b.x from test_2 b order by b.t1_id + ^ + rollback + ^ + --################################################################## + + delete from test_2 + ^ + insert into test_2 (t1_id, x) + select a.id, a.x + from v_test_1 a + order by a.id + ^ + select 'chk-2' as msg, b.t1_id, b.x from test_2 b order by b.t1_id + ^ + rollback + ^ + --################################################################## + + alter table test_1 + add dbl_expr computed by ( + case + when test_1.id > 2 then (select sum(b.x) from test_2 b where b.t1_id < test_1.id) + else test_1.id * 10 + end ) + ^ + commit + ^ + delete from test_2 + ^ + insert into test_2 (t1_id, x) + select a.id, a.dbl_expr + from test_1 a + order by a.id + ^ + select 'chk-3' as msg, b.t1_id, b.x from test_2 b order by b.t1_id + ^ + rollback + ^ +""" + +act = isql_act('db', test_script) + +expected_stdout = """ + MSG chk-1 + T1_ID 1 + X 10 + MSG chk-1 + T1_ID 2 + X 20 + MSG chk-1 + T1_ID 3 + X + + MSG chk-2 + T1_ID 1 + X 10 + MSG chk-2 + T1_ID 2 + X 20 + MSG chk-2 + T1_ID 3 + X + + MSG chk-3 + T1_ID 1 + X 10 + MSG chk-3 + T1_ID 2 + X 20 + MSG chk-3 + T1_ID 3 + X +""" + +@pytest.mark.version('>=3.0.12') +def test_1(act: Action): + act.expected_stdout = expected_stdout + act.execute(combine_output = True) + assert act.clean_stdout == act.clean_expected_stdout