6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 05:53:06 +01:00
firebird-qa/tests/bugs/core_5463_test.py

113 lines
4.4 KiB
Python

#coding:utf-8
"""
ID: issue-5733
ISSUE: 5733
TITLE: Support GENERATED ALWAYS identity columns and OVERRIDE clause
DESCRIPTION:
JIRA: CORE-5463
FBTEST: bugs.core_5463
"""
import pytest
from firebird.qa import *
db = db_factory()
test_script = """
set list on;
recreate table test_always(
id_always int generated ALWAYS as identity (start with 11 increment 22) unique
);
recreate table test_default(
id_default int generated BY DEFAULT as identity (start with -11 increment -22) unique
);
insert into test_default default values returning id_default; -- expected: -33
insert into test_always default values returning id_always; -- expected: 33
-- Comments taken from doc\\sql.extensions\\README.identity_columns.txt
-- ==================================================================
-- ........................................
-- Identity columns are implicitly NOT NULL
-- ........................................
-- Statement failed, SQLSTATE = 42000
-- OVERRIDING SYSTEM VALUE should be used to override the value of an identity column defined as 'GENERATED ALWAYS' in ta
insert into test_always(id_always) values(null);
-- Statement failed, SQLSTATE = 23000
-- validation error for column "TEST"."id_default", value "*** null ***"
insert into test_default(id_default) values(null);
-- ........................................................................
-- BY DEFAULT identity columns can be overriden in INSERT statements
-- just specifying the value in the values list
-- ........................................................................
insert into test_default(id_default) values(-7654321) returning id_default;
-- insert into test_default default values returning id_default; ==> -99 !
-- ........................................................................
-- However, for ALWAYS identity columns that is not allowed.
-- To use the value passed in the INSERT statement for an ALWAYS column, you should pass
-- OVERRIDING SYSTEM VALUE:
-- ........................................................................
-- 1) check that OVERRIDING SYSTEM VALUE clause does not affect on NOT_NULL constraint:
-- Statement failed, SQLSTATE = 23000
-- validation error for column "test_always"."ID_ALWAYS", value "*** null ***"
insert into test_always(id_always) overriding system value values (null) returning id_always;
-- 2) check ability to override system value by providing our own:
insert into test_always(id_always) overriding system value values (7654321) returning id_always;
-- .........................................................................
-- OVERRIDING also supports a subclause to be used with BY DEFAULT columns,
-- to ignore the value passed in INSERT and use the defined sequence:
-- .........................................................................
-- 1) check that attempt to pass NULL into VALUES list has no effect:
insert into test_default(id_default) overriding user value values(null) returning id_default; -- expected: -99
-- 2) check ability to pass allowed value but it also must be overriden by default one:
insert into test_default(id_default) overriding user value values(-7654322) returning id_default; -- expected: -121
"""
act = isql_act('db', test_script, substitutions=[('OVERRIDING SYSTEM VALUE should be used.*',
'OVERRIDING SYSTEM VALUE should be used')])
expected_stdout = """
ID_DEFAULT -11
ID_ALWAYS 11
ID_DEFAULT -7654321
ID_ALWAYS 7654321
ID_DEFAULT -33
ID_DEFAULT -55
"""
expected_stderr = """
Statement failed, SQLSTATE = 42000
OVERRIDING SYSTEM VALUE should be used
Statement failed, SQLSTATE = 23000
validation error for column "TEST_DEFAULT"."ID_DEFAULT", value "*** null ***"
Statement failed, SQLSTATE = 23000
validation error for column "TEST_ALWAYS"."ID_ALWAYS", value "*** null ***"
"""
@pytest.mark.version('>=4.0')
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)