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_6144_test.py

62 lines
1.5 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-27 20:08:36 +01:00
"""
ID: issue-6393
ISSUE: 6393
TITLE: Inconsistent behaviour of the NEW context variable in AFTER UPDATE OR DELETE triggers
DESCRIPTION:
JIRA: CORE-6144
FBTEST: bugs.core_6144
2022-01-27 20:08:36 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
test_script = """
create table test (id integer not null primary key);
commit;
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
insert into test (id) values (1);
commit;
alter table test add v integer default 1 not null;
commit;
insert into test (id) values (2);
2021-04-26 20:07:00 +02:00
commit;
2022-01-27 20:08:36 +01:00
create exception exc_not_null_in_AD_trigger 'new.v is NOT null in AD trigger ?!';
2021-04-26 20:07:00 +02:00
commit;
2022-01-27 20:08:36 +01:00
set term ^;
create or alter trigger test_null for test after update or delete as
begin
if (new.v is not null) then -- new.v should be NULL if the trigger runs after DELETE statement
2021-04-26 20:07:00 +02:00
begin
rdb$set_context('USER_SESSION', 'AD_TRIGGER_NEW_V', new.v);
exception exc_not_null_in_AD_trigger;
end
end
^
2022-01-27 20:08:36 +01:00
set term ;^
commit;
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
delete from test where id = 2; -- no errors
delete from test where id = 1; -- trigger throws exception
2021-04-26 20:07:00 +02:00
set list on;
select rdb$get_context('USER_SESSION', 'AD_TRIGGER_NEW_V') as "new_v value in AD trigger:"
from rdb$database;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
new_v value in AD trigger: <null>
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
@pytest.mark.version('>=3')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout