2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-18 20:45:21 +01:00
|
|
|
"""
|
|
|
|
ID: issue-536
|
|
|
|
ISSUE: 536
|
|
|
|
TITLE: CHECK constraints fire twice
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-209
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_0209
|
2022-01-18 20:45:21 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-18 20:45:21 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-18 20:45:21 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-18 20:45:21 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
create domain dm_restricted_char as char(1) check (value in ('A','B','C', 'D','E'));
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate table test (
|
|
|
|
id integer,
|
|
|
|
col dm_restricted_char
|
|
|
|
);
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate view v_test as select * from test;
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set term ^;
|
|
|
|
create trigger tab_biu for test before insert or update as
|
|
|
|
begin
|
|
|
|
new.col = upper (new.col);
|
|
|
|
end^
|
|
|
|
|
|
|
|
create trigger v_test_biu for v_test before insert or update as
|
|
|
|
begin
|
|
|
|
-- ::: NB :::
|
2022-01-18 20:45:21 +01:00
|
|
|
-- Since 2.0 trigger that belongs to updatable view MUST have DML
|
2021-04-26 20:07:00 +02:00
|
|
|
-- statement that handles underlying TABLE (this was not so in 1.5).
|
|
|
|
if ( inserting ) then
|
|
|
|
insert into test values( new.id, new.col );
|
|
|
|
else
|
2022-01-18 20:45:21 +01:00
|
|
|
update test set col = new.col, id = new.id
|
2021-04-26 20:07:00 +02:00
|
|
|
where id = old.id;
|
|
|
|
end^
|
|
|
|
|
|
|
|
set term ;^
|
|
|
|
commit;
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set count on;
|
|
|
|
set list on;
|
|
|
|
SET ECHO ON;
|
|
|
|
|
|
|
|
insert into v_test values (11, 'a');
|
|
|
|
insert into v_test values (12, 'b');
|
|
|
|
insert into v_test values (13, 'c');
|
|
|
|
insert into v_test values (14, 'd');
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select * from test;
|
|
|
|
commit;
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
update v_test set col='e' where id=11;
|
|
|
|
update v_test set col='e' where id=14;
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
update test set col='z' where id=12;
|
|
|
|
update v_test set col='x' where id=13;
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select * from test;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-18 20:45:21 +01:00
|
|
|
act = isql_act('db', test_script,
|
|
|
|
substitutions=[("-At trigger 'V_TEST_BIU' line.*", "-At trigger 'V_TEST_BIU' line")])
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-18 20:45:21 +01:00
|
|
|
expected_stdout = """
|
2021-04-26 20:07:00 +02:00
|
|
|
insert into v_test values (11, 'a');
|
|
|
|
Records affected: 1
|
|
|
|
insert into v_test values (12, 'b');
|
|
|
|
Records affected: 1
|
|
|
|
insert into v_test values (13, 'c');
|
|
|
|
Records affected: 1
|
|
|
|
insert into v_test values (14, 'd');
|
|
|
|
Records affected: 1
|
|
|
|
|
|
|
|
select * from test;
|
|
|
|
ID 11
|
|
|
|
COL A
|
|
|
|
ID 12
|
|
|
|
COL B
|
|
|
|
ID 13
|
|
|
|
COL C
|
|
|
|
ID 14
|
|
|
|
COL D
|
|
|
|
Records affected: 4
|
|
|
|
commit;
|
|
|
|
|
|
|
|
update v_test set col='e' where id=11;
|
|
|
|
Records affected: 1
|
|
|
|
update v_test set col='e' where id=14;
|
|
|
|
Records affected: 1
|
|
|
|
|
|
|
|
update test set col='z' where id=12;
|
|
|
|
Records affected: 0
|
|
|
|
update v_test set col='x' where id=13;
|
|
|
|
Records affected: 0
|
|
|
|
|
|
|
|
select * from test;
|
|
|
|
|
|
|
|
ID 11
|
|
|
|
COL E
|
|
|
|
ID 12
|
|
|
|
COL B
|
|
|
|
ID 13
|
|
|
|
COL C
|
|
|
|
ID 14
|
|
|
|
COL E
|
|
|
|
Records affected: 4
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2022-01-18 20:45:21 +01:00
|
|
|
expected_stderr = """
|
2021-04-26 20:07:00 +02:00
|
|
|
Statement failed, SQLSTATE = 23000
|
|
|
|
validation error for column "TEST"."COL", value "Z"
|
|
|
|
|
|
|
|
Statement failed, SQLSTATE = 23000
|
|
|
|
validation error for column "TEST"."COL", value "X"
|
|
|
|
-At trigger 'V_TEST_BIU' line: 8, col: 5
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-18 20:45:21 +01:00
|
|
|
@pytest.mark.version('>=3')
|
|
|
|
def test_1(act: Action):
|
|
|
|
act.expected_stdout = expected_stdout
|
|
|
|
act.expected_stderr = expected_stderr
|
|
|
|
act.execute()
|
|
|
|
assert (act.clean_stderr == act.clean_expected_stderr and
|
|
|
|
act.clean_stdout == act.clean_expected_stdout)
|
2021-04-26 20:07:00 +02:00
|
|
|
|