2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
"""
|
|
|
|
ID: issue-5181
|
|
|
|
ISSUE: 5181
|
|
|
|
TITLE: AFTER CREATE/ALTER PACKAGE DDL triggers runs in incorrectly moment
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-4887
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_4887
|
2022-01-24 20:27:02 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
set bail on;
|
|
|
|
set list on;
|
|
|
|
create exception exc_empty_pkg 'Empty package';
|
|
|
|
create sequence g;
|
|
|
|
commit;
|
|
|
|
|
|
|
|
set term ^;
|
|
|
|
create or alter trigger t_trig_pkg_head after create package as
|
|
|
|
begin
|
|
|
|
rdb$set_context('USER_SESSION','DDL_TRIGGER_ON_PKG_HEAD_FIRING', gen_id(g,1));
|
|
|
|
if ( not exists(select * from rdb$functions where rdb$package_name = rdb$get_context('DDL_TRIGGER', 'OBJECT_NAME') ) ) then
|
|
|
|
exception exc_empty_pkg;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
create or alter trigger t_trig_pkg_body after create package body as
|
|
|
|
begin
|
|
|
|
rdb$set_context('USER_SESSION','DDL_TRIGGER_ON_PKG_BODY_FIRING', gen_id(g,1));
|
|
|
|
end
|
2022-01-24 20:27:02 +01:00
|
|
|
^
|
2021-04-26 20:07:00 +02:00
|
|
|
set term ;^
|
|
|
|
commit;
|
|
|
|
|
|
|
|
set term ^;
|
|
|
|
execute block as
|
|
|
|
begin
|
|
|
|
rdb$set_context('USER_SESSION','PACKAGE_HEADER_CREATION_START', gen_id(g,1));
|
|
|
|
end
|
|
|
|
^
|
|
|
|
create package xpk1 as
|
|
|
|
begin
|
|
|
|
function f1 returns integer;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
execute block as
|
|
|
|
begin
|
|
|
|
rdb$set_context('USER_SESSION','PACKAGE_HEADER_CREATION_FINISH', gen_id(g,1));
|
|
|
|
end
|
|
|
|
^
|
|
|
|
commit
|
|
|
|
^
|
|
|
|
|
|
|
|
execute block as
|
|
|
|
begin
|
|
|
|
rdb$set_context('USER_SESSION','PACKAGE_BODY_CREATION_START', gen_id(g,1));
|
|
|
|
end
|
|
|
|
^
|
|
|
|
create package body xpk1 as
|
|
|
|
begin
|
|
|
|
function f1 returns integer as
|
|
|
|
begin
|
|
|
|
return 12345;
|
|
|
|
end
|
|
|
|
end
|
2022-01-24 20:27:02 +01:00
|
|
|
^
|
2021-04-26 20:07:00 +02:00
|
|
|
execute block as
|
|
|
|
begin
|
|
|
|
rdb$set_context('USER_SESSION','PACKAGE_BODY_CREATION_FINISH', gen_id(g,1));
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
|
|
|
|
select event_seq, event_name
|
|
|
|
from(
|
|
|
|
select
|
|
|
|
cast( rdb$get_context('USER_SESSION','PACKAGE_HEADER_CREATION_START') as int) event_seq
|
|
|
|
,'pkg_header_start' event_name
|
|
|
|
from rdb$database
|
2022-01-24 20:27:02 +01:00
|
|
|
union all
|
2021-04-26 20:07:00 +02:00
|
|
|
select
|
|
|
|
cast( rdb$get_context('USER_SESSION','PACKAGE_HEADER_CREATION_FINISH') as int)
|
|
|
|
,'pkg_header_finish'
|
|
|
|
from rdb$database
|
2022-01-24 20:27:02 +01:00
|
|
|
union all
|
2021-04-26 20:07:00 +02:00
|
|
|
select
|
2022-01-24 20:27:02 +01:00
|
|
|
cast( rdb$get_context('USER_SESSION','PACKAGE_BODY_CREATION_START') as int)
|
2021-04-26 20:07:00 +02:00
|
|
|
,'pkg_body_start'
|
|
|
|
from rdb$database
|
2022-01-24 20:27:02 +01:00
|
|
|
union all
|
2021-04-26 20:07:00 +02:00
|
|
|
select
|
|
|
|
cast( rdb$get_context('USER_SESSION','PACKAGE_BODY_CREATION_FINISH') as int)
|
|
|
|
,'pkg_body_finish'
|
|
|
|
from rdb$database
|
2022-01-24 20:27:02 +01:00
|
|
|
union all
|
2021-04-26 20:07:00 +02:00
|
|
|
select
|
2022-01-24 20:27:02 +01:00
|
|
|
cast( rdb$get_context('USER_SESSION','DDL_TRIGGER_ON_PKG_HEAD_FIRING') as int)
|
2021-04-26 20:07:00 +02:00
|
|
|
,'trg_pkg_head_firing'
|
|
|
|
from rdb$database
|
2022-01-24 20:27:02 +01:00
|
|
|
union all
|
2021-04-26 20:07:00 +02:00
|
|
|
select
|
|
|
|
cast( rdb$get_context('USER_SESSION','DDL_TRIGGER_ON_PKG_BODY_FIRING') as int)
|
|
|
|
,'trg_pkg_body_firing'
|
|
|
|
from rdb$database
|
2022-01-24 20:27:02 +01:00
|
|
|
)
|
2021-04-26 20:07:00 +02:00
|
|
|
order by event_seq;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
act = isql_act('db', test_script)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-24 20:27:02 +01:00
|
|
|
expected_stdout = """
|
2021-04-26 20:07:00 +02:00
|
|
|
EVENT_SEQ 1
|
|
|
|
EVENT_NAME pkg_header_start
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
EVENT_SEQ 2
|
|
|
|
EVENT_NAME trg_pkg_head_firing
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
EVENT_SEQ 3
|
|
|
|
EVENT_NAME pkg_header_finish
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
EVENT_SEQ 4
|
|
|
|
EVENT_NAME pkg_body_start
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
EVENT_SEQ 5
|
|
|
|
EVENT_NAME trg_pkg_body_firing
|
2022-01-24 20:27:02 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
EVENT_SEQ 6
|
|
|
|
EVENT_NAME pkg_body_finish
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2022-01-24 20:27:02 +01:00
|
|
|
def test_1(act: Action):
|
|
|
|
act.expected_stdout = expected_stdout
|
2023-10-09 11:03:01 +02:00
|
|
|
act.execute(combine_output = True)
|
2022-01-24 20:27:02 +01:00
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|
2021-04-26 20:07:00 +02:00
|
|
|
|