6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_4970_test.py

105 lines
2.9 KiB
Python

#coding:utf-8
"""
ID: issue-5261
ISSUE: 5261
TITLE: Table trigger does not see its mode: inserting or updating or deleting
DESCRIPTION:
JIRA: CORE-4970
FBTEST: bugs.core_4970
"""
import pytest
from firebird.qa import *
db = db_factory()
test_script = """
set list on;
create or alter view v_chk as select 1 id from rdb$database;
recreate sequence g;
recreate table test( id int, x int );
recreate table tlog(
id int generated by default as identity
,expected_mode_in_before_trg varchar(20)
,expected_mode_in_after_trg varchar(20)
,actual_mode_in_before_trg varchar(20)
,actual_mode_in_after_trg varchar(20)
);
commit;
create or alter view v_chk as
select * from tlog
order by id;
commit;
set term ^;
create or alter trigger test_biud for test active before insert or update or delete
as
begin
update tlog set actual_mode_in_before_trg = trim( iif(inserting,'INSERTING', iif(updating,'UPDATING', iif(deleting, 'DELETING', '??? NULL ???'))) )
where actual_mode_in_before_trg is null
rows 1;
end
^
create or alter trigger test_aiud for test active after insert or update or delete
as
begin
update tlog set actual_mode_in_after_trg = trim( iif(inserting,'INSERTING', iif(updating,'UPDATING', iif(deleting, 'DELETING', '??? NULL ???'))) )
where actual_mode_in_after_trg is null
rows 1;
end
^
set term ;^
commit;
insert into tlog(expected_mode_in_before_trg, expected_mode_in_after_trg) values ('INSERTING', 'INSERTING');
insert into test default values;
insert into tlog(expected_mode_in_before_trg, expected_mode_in_after_trg) values ('UPDATING', 'UPDATING');
update test set id = -id;
insert into tlog(expected_mode_in_before_trg, expected_mode_in_after_trg) values ('DELETING', 'DELETING');
delete from test;
select * from v_chk;
rollback;
drop table test;
drop view v_chk;
commit;
"""
act = isql_act('db', test_script)
expected_stdout = """
ID 1
EXPECTED_MODE_IN_BEFORE_TRG INSERTING
EXPECTED_MODE_IN_AFTER_TRG INSERTING
ACTUAL_MODE_IN_BEFORE_TRG INSERTING
ACTUAL_MODE_IN_AFTER_TRG INSERTING
ID 2
EXPECTED_MODE_IN_BEFORE_TRG UPDATING
EXPECTED_MODE_IN_AFTER_TRG UPDATING
ACTUAL_MODE_IN_BEFORE_TRG UPDATING
ACTUAL_MODE_IN_AFTER_TRG UPDATING
ID 3
EXPECTED_MODE_IN_BEFORE_TRG DELETING
EXPECTED_MODE_IN_AFTER_TRG DELETING
ACTUAL_MODE_IN_BEFORE_TRG DELETING
ACTUAL_MODE_IN_AFTER_TRG DELETING
"""
@pytest.mark.version('>=3.0')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout