2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-22 21:59:15 +01:00
|
|
|
"""
|
|
|
|
ID: issue-4298
|
|
|
|
ISSUE: 4298
|
|
|
|
TITLE: Creating a procedure containing "case when" expression leads to a server crash
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-3965
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_3965
|
2022-01-22 21:59:15 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-22 21:59:15 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-22 21:59:15 +01:00
|
|
|
db = db_factory(from_backup='employee-ods12.fbk')
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-22 21:59:15 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
-- Table 'sales' for this SP is taken from standard samples database 'employee.fdb' which comes with every FB build.
|
|
|
|
set term ^;
|
|
|
|
create or alter procedure p_beteiligung_order (
|
|
|
|
gid char(36) character set iso8859_1 collate iso8859_1,
|
|
|
|
ordernr integer,
|
|
|
|
dir smallint,
|
|
|
|
mit_fuehrender char(1) character set iso8859_1 collate iso8859_1)
|
|
|
|
as
|
|
|
|
declare variable cur_ordernr integer;
|
|
|
|
declare variable max_ordernr integer;
|
|
|
|
declare variable fk_ref char(36);
|
|
|
|
begin
|
2022-01-22 21:59:15 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
if (mit_fuehrender is null) then
|
|
|
|
mit_fuehrender = 'F';
|
2022-01-22 21:59:15 +01:00
|
|
|
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select r.qty_ordered, r.item_type
|
|
|
|
from sales r
|
|
|
|
where r.po_number = :gid
|
|
|
|
into :cur_ordernr, :fk_ref;
|
2022-01-22 21:59:15 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
if (ordernr is null) then
|
|
|
|
ordernr = cur_ordernr + coalesce(dir, 0);
|
2022-01-22 21:59:15 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
if (ordernr <= case mit_fuehrender
|
|
|
|
when 'T' then 1
|
|
|
|
else 2
|
|
|
|
end) then
|
|
|
|
ordernr = case mit_fuehrender
|
|
|
|
when 'T' then 1
|
|
|
|
else 2
|
|
|
|
end;
|
|
|
|
else
|
|
|
|
begin
|
|
|
|
select max(r.qty_ordered)
|
|
|
|
from sales r
|
|
|
|
where r.item_type = :fk_ref
|
|
|
|
into :max_ordernr;
|
|
|
|
if (ordernr > max_ordernr) then
|
|
|
|
ordernr = max_ordernr;
|
|
|
|
end
|
2022-01-22 21:59:15 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
if (ordernr = cur_ordernr) then
|
|
|
|
exit;
|
|
|
|
else
|
|
|
|
if (ordernr < cur_ordernr) then
|
|
|
|
update sales r
|
|
|
|
set r.qty_ordered = r.qty_ordered + 1
|
|
|
|
where r.item_type = :fk_ref and
|
|
|
|
r.qty_ordered between :ordernr and :cur_ordernr;
|
|
|
|
else
|
|
|
|
update sales r
|
|
|
|
-- ::: NB ::: in the ticket it was: "set r.qty_ordered = r.ordernr - 1" - but there is NO such field in the table SALES!
|
2022-01-22 21:59:15 +01:00
|
|
|
set r.qty_ordered = :ordernr - 1
|
2021-04-26 20:07:00 +02:00
|
|
|
where r.qty_ordered = :fk_ref and
|
|
|
|
r.qty_ordered between :cur_ordernr and :ordernr;
|
2022-01-22 21:59:15 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
update sales r
|
|
|
|
set r.qty_ordered = :ordernr
|
|
|
|
where r.po_number = :gid;
|
2022-01-22 21:59:15 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
end^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
|
|
|
|
|
|
|
drop procedure p_beteiligung_order;
|
|
|
|
commit;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-22 21:59:15 +01:00
|
|
|
act = isql_act('db', test_script)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2022-01-22 21:59:15 +01:00
|
|
|
def test_1(act: Action):
|
2022-01-25 22:55:48 +01:00
|
|
|
act.execute()
|