2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
2022-02-04 19:05:19 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
ID: gtcs.ref-integ-drop-fk-index
|
|
|
|
TITLE: Index that is used for FK should not be avail for DROP
|
|
|
|
DESCRIPTION:
|
|
|
|
Original test see in:
|
|
|
|
https://github.com/FirebirdSQL/fbtcs/blob/master/GTCS/tests/REF_INT.4.ISQL.script
|
2022-04-20 16:03:57 +02:00
|
|
|
|
2022-10-06 11:56:49 +02:00
|
|
|
This test uses pre-created script ( <QA_ROOT>/files/gtcs-ref-integ-init.sql ) which creates two
|
2022-04-20 16:03:57 +02:00
|
|
|
tables with PK/FK referencing constraint(parent = department, child = employee).
|
|
|
|
FK-constraint uses index with name = 'ref_key', and here we try to:
|
|
|
|
* DROP this index;
|
|
|
|
* insert record in the child table which has no apropriate PK in the parent table.
|
|
|
|
(see 'sql_addi' variable which stores SQL statements for that).
|
|
|
|
Both actions should fail.
|
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
FBTEST: functional.gtcs.ref_integ_drop_fk_index
|
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
import pytest
|
2022-04-20 16:03:57 +02:00
|
|
|
import os
|
2022-02-04 19:05:19 +01:00
|
|
|
from firebird.qa import *
|
|
|
|
|
|
|
|
db = db_factory()
|
|
|
|
|
|
|
|
act = python_act('db')
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-04-20 16:03:57 +02:00
|
|
|
test_expected_stdout = """
|
|
|
|
Records affected: 0
|
|
|
|
"""
|
|
|
|
|
|
|
|
test_expected_stderr = """
|
2022-02-04 19:05:19 +01:00
|
|
|
Statement failed, SQLSTATE = 27000
|
|
|
|
unsuccessful metadata update
|
|
|
|
-DROP INDEX REF_KEY failed
|
|
|
|
-action cancelled by trigger (1) to preserve data integrity
|
|
|
|
-Cannot delete index used by an Integrity Constraint
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
Statement failed, SQLSTATE = 23000
|
|
|
|
violation of FOREIGN KEY constraint "REF_KEY" on table "EMPLOYEE"
|
|
|
|
-Foreign key reference target does not exist
|
2022-04-28 19:19:35 +02:00
|
|
|
-Problematic key value is ("DEPT_NO" = -1)
|
2022-02-04 19:05:19 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
@pytest.mark.version('>=3.0')
|
|
|
|
def test_1(act: Action):
|
2022-04-20 16:03:57 +02:00
|
|
|
|
2022-04-28 19:19:35 +02:00
|
|
|
sql_init = (act.files_dir / 'gtcs-ref-integ-init.sql').read_text()
|
2022-04-20 16:03:57 +02:00
|
|
|
sql_addi = '''
|
|
|
|
drop index ref_key;
|
|
|
|
commit;
|
|
|
|
insert into employee( emp_no, last_name, dept_no) values (12, 'e12', -1); -- should FAIL
|
|
|
|
set count on;
|
|
|
|
select * from employee e where e.dept_no < 0;
|
|
|
|
'''
|
|
|
|
|
|
|
|
act.expected_stdout = test_expected_stdout
|
|
|
|
act.expected_stderr = test_expected_stderr
|
|
|
|
|
|
|
|
act.isql(switches=['-q'], input = os.linesep.join( (sql_init, sql_addi) ) )
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-04-20 16:03:57 +02:00
|
|
|
assert (act.clean_stdout == act.clean_expected_stdout and
|
|
|
|
act.clean_stderr == act.clean_expected_stderr)
|