diff --git a/tests/functional/basic/isql/test_09.py b/tests/functional/basic/isql/test_09.py new file mode 100644 index 00000000..928c3a3c --- /dev/null +++ b/tests/functional/basic/isql/test_09.py @@ -0,0 +1,98 @@ +#coding:utf-8 + +""" +ID: isql.issue-2358 +ISSUE: https://github.com/FirebirdSQL/firebird/issues/2358 +TITLE: ISQL showing inactive constraints +DESCRIPTION: +""" + +import pytest +from firebird.qa import * + +db = db_factory() + +test_script = """RECREATE TABLE test_constraints( + id integer not null constraint pk_c primary key, + unq_act_def integer constraint uk_act_def unique, + unq_act integer constraint uk_act unique enforced, + unq_inact integer constraint uk_inact unique not enforced, + nn_act_def integer constraint not_null_act_def not null, + nn_act integer constraint not_null_act not null enforced, + nn_inact integer constraint not_null_inact not null not enforced, + fk_act_def integer constraint fk_act_def references test_constraints (id), + fk_act integer constraint fk_act references test_constraints (id) enforced, + fk_inact integer constraint fk_inact references test_constraints (id) not enforced, + check_act_def integer constraint check_act_def check(check_act_def=1), + check_act integer constraint check_act check(check_act=1) enforced, + check_inact integer constraint check_inact check(check_inact=1) not enforced +); +commit; +show table test_constraints; +show check test_constraints; +show index test_constraints; +""" + +act = isql_act('db', test_script, substitutions=[('CHECK_[0-9]+', '')]) + +expected_stdout = """ID INTEGER Not Null +UNQ_ACT_DEF INTEGER Nullable +UNQ_ACT INTEGER Nullable +UNQ_INACT INTEGER Nullable +NN_ACT_DEF INTEGER Not Null +NN_ACT INTEGER Not Null +NN_INACT INTEGER Nullable +FK_ACT_DEF INTEGER Nullable +FK_ACT INTEGER Nullable +FK_INACT INTEGER Nullable +CHECK_ACT_DEF INTEGER Nullable +CHECK_ACT INTEGER Nullable +CHECK_INACT INTEGER Nullable +CONSTRAINT FK_ACT: + Foreign key (FK_ACT) References TEST_CONSTRAINTS (ID) +CONSTRAINT FK_ACT_DEF: + Foreign key (FK_ACT_DEF) References TEST_CONSTRAINTS (ID) +CONSTRAINT FK_INACT: + Foreign key (FK_INACT) References TEST_CONSTRAINTS (ID) Not enforced +CONSTRAINT PK_C: + Primary key (ID) +CONSTRAINT UK_ACT: + Unique key (UNQ_ACT) +CONSTRAINT UK_ACT_DEF: + Unique key (UNQ_ACT_DEF) +CONSTRAINT UK_INACT: + Unique key (UNQ_INACT) Not enforced +CONSTRAINT NOT_NULL_ACT_DEF: + Not Null Column (NN_ACT_DEF) +CONSTRAINT NOT_NULL_ACT: + Not Null Column (NN_ACT) +CONSTRAINT NOT_NULL_INACT: + Not Null Column (NN_INACT) Not enforced +CONSTRAINT CHECK_ACT: + check(check_act=1) +CONSTRAINT CHECK_ACT_DEF: + check(check_act_def=1) +CONSTRAINT CHECK_INACT: + check(check_inact=1) Not enforced +CONSTRAINT CHECK_ACT: + check(check_act=1) +CONSTRAINT CHECK_ACT_DEF: + check(check_act_def=1) +CONSTRAINT CHECK_INACT: + check(check_inact=1) Not enforced +FK_ACT INDEX ON TEST_CONSTRAINTS(FK_ACT) +FK_ACT_DEF INDEX ON TEST_CONSTRAINTS(FK_ACT_DEF) +FK_INACT INDEX ON TEST_CONSTRAINTS(FK_INACT) (inactive) +PK_C UNIQUE INDEX ON TEST_CONSTRAINTS(ID) +UK_ACT UNIQUE INDEX ON TEST_CONSTRAINTS(UNQ_ACT) +UK_ACT_DEF UNIQUE INDEX ON TEST_CONSTRAINTS(UNQ_ACT_DEF) +UK_INACT UNIQUE INDEX ON TEST_CONSTRAINTS(UNQ_INACT) (inactive) +""" + +#-------------------------------------------- + +@pytest.mark.version('>=6') +def test_1(act: Action): + act.expected_stdout = expected_stdout + act.execute(combine_output = True) + assert act.clean_stdout == act.clean_expected_stdout diff --git a/tests/functional/table/alter/test_13.py b/tests/functional/table/alter/test_13.py new file mode 100644 index 00000000..f36923b2 --- /dev/null +++ b/tests/functional/table/alter/test_13.py @@ -0,0 +1,77 @@ +#coding:utf-8 + +""" +ID: table.alter-13 +TITLE: ALTER TABLE - ALTER CONSTRAINT +DESCRIPTION: +FBTEST: functional.table.alter.13 +NOTES: +""" + +import pytest +from firebird.qa import * + +db = db_factory() + +test_script = """RECREATE TABLE test_constraints( + id integer not null constraint pk_c primary key, + unq integer constraint uk unique, + nn integer constraint not_null not null, + fk integer constraint fk references test_constraints (id), + chk integer constraint chk check(chk=1) +); +-- Default activity of constraint is already checked in create/test_08 +insert into test_constraints values(1,1,1,1,1); +commit; +-- Check deactivation of constraints +alter table test_constraints + alter constraint uk not enforced, + alter constraint not_null not enforced, + alter constraint fk not enforced, + alter constraint chk not enforced; +alter table test_constraints + alter constraint pk_c not enforced; +commit; +-- check that none of these constraints are not enforced now +insert into test_constraints values(1,1,NULL,11,11); +rollback; +-- Check activation of constraints +alter table test_constraints + alter constraint pk_c enforced, + alter constraint uk enforced, + alter constraint not_null enforced, + alter constraint fk enforced, + alter constraint chk enforced; +commit; +-- Check that every one has been activated +insert into test_constraints values (1,2,2,1,1); -- pk_c violation +insert into test_constraints values (3,1,3,1,1); -- uk violation +insert into test_constraints values (4,4,NULL,1,1); -- nn violation +insert into test_constraints values (5,5,5,11,1); -- fk violation +insert into test_constraints values (6,6,6,1,11); -- chk violation +""" + +act = isql_act('db', test_script, substitutions=[('CHECK_[0-9]+', '')]) + +expected_stdout = """Statement failed, SQLSTATE = 23000 +violation of PRIMARY or UNIQUE KEY constraint "PK_C" on table "TEST_CONSTRAINTS" +-Problematic key value is ("ID" = 1) +Statement failed, SQLSTATE = 23000 +violation of PRIMARY or UNIQUE KEY constraint "UK" on table "TEST_CONSTRAINTS" +-Problematic key value is ("UNQ" = 1) +Statement failed, SQLSTATE = 23000 +validation error for column "TEST_CONSTRAINTS"."NN", value "*** null ***" +Statement failed, SQLSTATE = 23000 +violation of FOREIGN KEY constraint "FK" on table "TEST_CONSTRAINTS" +-Foreign key reference target does not exist +-Problematic key value is ("FK" = 11) +Statement failed, SQLSTATE = 23000 +Operation violates CHECK constraint CHK on view or table TEST_CONSTRAINTS +-At trigger 'CHECK_1' +""" + +@pytest.mark.version('>=6') +def test_1(act: Action): + act.expected_stdout = expected_stdout + act.execute(combine_output = True) + assert act.clean_stdout == act.clean_expected_stdout diff --git a/tests/functional/table/create/test_08.py b/tests/functional/table/create/test_08.py new file mode 100644 index 00000000..79ee5f91 --- /dev/null +++ b/tests/functional/table/create/test_08.py @@ -0,0 +1,94 @@ +#coding:utf-8 + +""" +ID: table.create-08 +TITLE: CREATE TABLE - enforced and not enforced constraints +DESCRIPTION: +FBTEST: functional.table.create.08 +""" + +import pytest +from firebird.qa import * + +db = db_factory() + +test_script = """RECREATE TABLE test_constraints( + id integer not null constraint pk_c primary key, + unq_act_def integer constraint uk_act_def unique, + unq_act integer constraint uk_act unique enforced, + unq_inact integer constraint uk_inact unique not enforced, + nn_act_def integer constraint not_null_act_def not null, + nn_act integer constraint not_null_act not null enforced, + nn_inact integer constraint not_null_inact not null not enforced, + fk_act_def integer constraint fk_act_def references test_constraints (id), + fk_act integer constraint fk_act references test_constraints (id) enforced, + fk_inact integer constraint fk_inact references test_constraints (id) not enforced, + check_act_def integer constraint check_act_def check(check_act_def=1), + check_act integer constraint check_act check(check_act=1) enforced, + check_inact integer constraint check_inact check(check_inact=1) not enforced +); +-- check that not enforced constraints are not enforced. These inserts must pass +insert into test_constraints values (1,2,2,2,3,3,NULL,NULL,NULL,NULL,1,1,2); +insert into test_constraints values (2,22,22,2,3,3,NULL,1,1,11,1,1,2); +-- check that enforced constraints are enforced. These inserts must fail +insert into test_constraints values (1,23,23,2,3,3,3,1,1,1,1,1,1); -- pk_c violation +insert into test_constraints values (3,2,23,23,3,3,3,1,1,1,1,1,1); -- uk_act_def violation +insert into test_constraints values (4,24,2,24,3,3,3,1,1,1,1,1,1); -- uk_act violation +insert into test_constraints values (5,25,25,25,NULL,3,3,1,1,1,1,1,1); -- not_null_act_def violation +insert into test_constraints values (6,26,26,26,3,NULL,3,1,1,1,1,1,1); -- not_null_act violation +insert into test_constraints values (7,27,27,27,3,3,3,37,1,1,1,1,1); -- fk_act_def violation +insert into test_constraints values (8,28,28,28,3,3,3,1,38,1,1,1,1); -- fk_act violation +insert into test_constraints values (9,29,29,29,3,3,3,1,1,1,49,1,1); -- check_act_def violation +insert into test_constraints values (10,29,29,29,3,3,3,1,1,1,1,4,1); -- check_act violation +commit; +-- Separate check for PK +RECREATE TABLE test_constraints_pk( + id integer not null constraint pk_c_enf primary key enforced); +insert into test_constraints_pk values(1); +insert into test_constraints_pk values(1); +rollback; +RECREATE TABLE test_constraints_pk( + id integer not null constraint pk_c_not_enf primary key not enforced); +insert into test_constraints_pk values(1); +insert into test_constraints_pk values(1); +""" + +act = isql_act('db', test_script, substitutions=[('CHECK_[0-9]+', '')]) + +expected_stderr = """Statement failed, SQLSTATE = 23000 +violation of PRIMARY or UNIQUE KEY constraint "PK_C" on table "TEST_CONSTRAINTS" +-Problematic key value is ("ID" = 1) +Statement failed, SQLSTATE = 23000 +violation of PRIMARY or UNIQUE KEY constraint "UK_ACT_DEF" on table "TEST_CONSTRAINTS" +-Problematic key value is ("UNQ_ACT_DEF" = 2) +Statement failed, SQLSTATE = 23000 +violation of PRIMARY or UNIQUE KEY constraint "UK_ACT" on table "TEST_CONSTRAINTS" +-Problematic key value is ("UNQ_ACT" = 2) +Statement failed, SQLSTATE = 23000 +validation error for column "TEST_CONSTRAINTS"."NN_ACT_DEF", value "*** null ***" +Statement failed, SQLSTATE = 23000 +validation error for column "TEST_CONSTRAINTS"."NN_ACT", value "*** null ***" +Statement failed, SQLSTATE = 23000 +violation of FOREIGN KEY constraint "FK_ACT_DEF" on table "TEST_CONSTRAINTS" +-Foreign key reference target does not exist +-Problematic key value is ("FK_ACT_DEF" = 37) +Statement failed, SQLSTATE = 23000 +violation of FOREIGN KEY constraint "FK_ACT" on table "TEST_CONSTRAINTS" +-Foreign key reference target does not exist +-Problematic key value is ("FK_ACT" = 38) +Statement failed, SQLSTATE = 23000 +Operation violates CHECK constraint CHECK_ACT_DEF on view or table TEST_CONSTRAINTS +-At trigger 'CHECK_41' +Statement failed, SQLSTATE = 23000 +Operation violates CHECK constraint CHECK_ACT on view or table TEST_CONSTRAINTS +-At trigger 'CHECK_43' +Statement failed, SQLSTATE = 23000 +violation of PRIMARY or UNIQUE KEY constraint "PK_C_ENF" on table "TEST_CONSTRAINTS_PK" +-Problematic key value is ("ID" = 1) +""" + +@pytest.mark.version('>=6.0') +def test_1(act: Action): + act.expected_stderr = expected_stderr + act.execute() + assert act.clean_stderr == act.clean_expected_stderr