Skip to content

Commit 1372ef2

Browse files
committed
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).
1 parent d71ccae commit 1372ef2

File tree

1 file changed

+187
-0
lines changed

1 file changed

+187
-0
lines changed

tests/bugs/gh_7713_test.py

Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
#coding:utf-8
2+
3+
"""
4+
ID: issue-7713
5+
ISSUE: https://github.com/FirebirdSQL/firebird/issues/7713
6+
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.
7+
DESCRIPTION:
8+
NOTES:
9+
[25.08.2023] pzotov
10+
Confirmed problem on 5.0.0.1169
11+
Checked on 5.0.0.1170, 4.0.4.2979 (intermediate snapshots).
12+
"""
13+
14+
import pytest
15+
from firebird.qa import *
16+
17+
db = db_factory()
18+
19+
test_script = """
20+
set list on;
21+
create table test_1 (
22+
id int generated by default as identity constraint test_1_pk primary key,
23+
name varchar(20)
24+
);
25+
26+
create table test_2 (
27+
id int generated by default as identity constraint test_2_pk primary key,
28+
t1_id int not null,
29+
x int
30+
);
31+
32+
alter table test_2 add constraint test_2_fk foreign key (t1_id) references test_1(id) on delete cascade on update cascade;
33+
34+
create or alter view v_test_1(
35+
id,
36+
x)
37+
as
38+
select
39+
a.id,
40+
case
41+
when a.id > 2 then (select sum(b.x) from test_2 b where b.t1_id < a.id)
42+
else a.id * 10
43+
end x
44+
from test_1 a
45+
order by a.id
46+
;
47+
48+
set term ^;
49+
50+
create procedure table_aaa_proc
51+
returns (
52+
id int,
53+
x int)
54+
as
55+
begin
56+
for
57+
select
58+
a.id,
59+
case
60+
when a.id > 2 then (select sum(b.x) from test_2 b where b.t1_id < a.id)
61+
else a.id * 10
62+
end x
63+
from
64+
test_1 a
65+
into
66+
:id, :x
67+
do
68+
begin
69+
suspend;
70+
end
71+
end
72+
^
73+
set term ;^
74+
75+
commit;
76+
77+
insert into test_1 (id, name) values ( 1, '1');
78+
insert into test_1 (id, name) values ( 2, '2');
79+
insert into test_1 (id, name) values ( 3, '3');
80+
commit;
81+
82+
--##################################################################
83+
84+
-- All following checks must output <NULL> for 'X' column if T1_ID =3:
85+
86+
set term ^;
87+
execute block as
88+
declare variable t1_id int;
89+
declare variable x int;
90+
begin
91+
delete from test_2 b where 0 = 0;
92+
for
93+
select
94+
a.id, a.x
95+
from
96+
v_test_1 a
97+
order by
98+
a.id
99+
into
100+
:t1_id, :x
101+
do
102+
begin
103+
insert into test_2 (t1_id, x) values (:t1_id, :x);
104+
end
105+
106+
end
107+
^
108+
select 'chk-1' as msg, b.t1_id, b.x from test_2 b order by b.t1_id
109+
^
110+
rollback
111+
^
112+
--##################################################################
113+
114+
delete from test_2
115+
^
116+
insert into test_2 (t1_id, x)
117+
select a.id, a.x
118+
from v_test_1 a
119+
order by a.id
120+
^
121+
select 'chk-2' as msg, b.t1_id, b.x from test_2 b order by b.t1_id
122+
^
123+
rollback
124+
^
125+
--##################################################################
126+
127+
alter table test_1
128+
add dbl_expr computed by (
129+
case
130+
when test_1.id > 2 then (select sum(b.x) from test_2 b where b.t1_id < test_1.id)
131+
else test_1.id * 10
132+
end )
133+
^
134+
commit
135+
^
136+
delete from test_2
137+
^
138+
insert into test_2 (t1_id, x)
139+
select a.id, a.dbl_expr
140+
from test_1 a
141+
order by a.id
142+
^
143+
select 'chk-3' as msg, b.t1_id, b.x from test_2 b order by b.t1_id
144+
^
145+
rollback
146+
^
147+
"""
148+
149+
act = isql_act('db', test_script)
150+
151+
expected_stdout = """
152+
MSG chk-1
153+
T1_ID 1
154+
X 10
155+
MSG chk-1
156+
T1_ID 2
157+
X 20
158+
MSG chk-1
159+
T1_ID 3
160+
X <null>
161+
162+
MSG chk-2
163+
T1_ID 1
164+
X 10
165+
MSG chk-2
166+
T1_ID 2
167+
X 20
168+
MSG chk-2
169+
T1_ID 3
170+
X <null>
171+
172+
MSG chk-3
173+
T1_ID 1
174+
X 10
175+
MSG chk-3
176+
T1_ID 2
177+
X 20
178+
MSG chk-3
179+
T1_ID 3
180+
X <null>
181+
"""
182+
183+
@pytest.mark.version('>=3.0.12')
184+
def test_1(act: Action):
185+
act.expected_stdout = expected_stdout
186+
act.execute(combine_output = True)
187+
assert act.clean_stdout == act.clean_expected_stdout

0 commit comments

Comments
 (0)