2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
"""
|
|
|
|
ID: fkey.primary.insert-15
|
|
|
|
FBTEST: functional.fkey.primary.insert_pk_15
|
|
|
|
TITLE: Check correct work fix with foreign key
|
|
|
|
DESCRIPTION:
|
|
|
|
Check foreign key work.
|
|
|
|
Master transaction inserts record into master_table but DOES NOT commit.
|
|
|
|
Detail transaction inserts record in detail_table and tries to COMMIT.
|
|
|
|
Expected: referential integrity error.
|
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
init_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate table t_detl(id int);
|
|
|
|
commit;
|
|
|
|
recreate table t_main(
|
|
|
|
id int constraint t_main_pk primary key using index t_main_pk
|
|
|
|
);
|
|
|
|
commit;
|
|
|
|
recreate table t_detl(
|
|
|
|
id int constraint t_detl_pk primary key using index t_detl_pk,
|
|
|
|
master_pk_id int constraint fk_tdetl_tmain references t_main(id) using index fk_tdetl_tmain
|
|
|
|
);
|
|
|
|
commit;
|
|
|
|
"""
|
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
db = db_factory(init=init_script)
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
commit;
|
|
|
|
set transaction no wait;
|
|
|
|
set term ^;
|
|
|
|
execute block as
|
|
|
|
begin
|
|
|
|
insert into t_main(id) values(1);
|
|
|
|
in autonomous transaction do
|
|
|
|
insert into t_detl(id, master_pk_id) values(100, 1);
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
2021-12-22 20:25:10 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
act = isql_act('db', test_script, substitutions=[('-At block line: [\\d]+, col: [\\d]+',
|
|
|
|
'-At block line')])
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
expected_stderr = """
|
2021-04-26 20:07:00 +02:00
|
|
|
Statement failed, SQLSTATE = 23000
|
|
|
|
violation of FOREIGN KEY constraint "FK_TDETL_TMAIN" on table "T_DETL"
|
|
|
|
-Foreign key reference target does not exist
|
|
|
|
-Problematic key value is ("MASTER_PK_ID" = 1)
|
|
|
|
-At block line: 5, col: 9
|
2021-12-22 20:25:10 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2022-02-04 19:05:19 +01:00
|
|
|
def test_1(act: Action):
|
|
|
|
act.expected_stderr = expected_stderr
|
|
|
|
act.execute()
|
|
|
|
assert act.clean_stderr == act.clean_expected_stderr
|