2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-18 20:45:21 +01:00
|
|
|
"""
|
|
|
|
ID: issue-1236
|
|
|
|
ISSUE: 1236
|
|
|
|
TITLE: Computed field can't be changed to non-computed using 'alter table alter column type xy'
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-847
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_0847
|
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
|
|
|
init_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate table t (
|
|
|
|
f1 varchar(10),
|
|
|
|
f2 varchar(10),
|
|
|
|
cf computed by (f1 || ' - ' || f2)
|
|
|
|
);
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
insert into t (f1,f2) values ('0123456789','abcdefghij');
|
|
|
|
commit;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-18 20:45:21 +01:00
|
|
|
db = db_factory(init=init_script)
|
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
|
|
|
set blob off;
|
|
|
|
set list on;
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select f1,f2,cf as cf_before_altering from t;
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select b.rdb$field_name field_name, cast(a.rdb$computed_source as varchar(80)) computed_source_before_altering
|
2022-01-18 20:45:21 +01:00
|
|
|
from rdb$fields a
|
2021-04-26 20:07:00 +02:00
|
|
|
join rdb$relation_fields b on a.rdb$field_name = b.rdb$field_source
|
|
|
|
where b.rdb$field_name = upper('CF');
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
alter table t alter cf type varchar(30);
|
|
|
|
commit;
|
|
|
|
|
|
|
|
select f1,f2,cf as cf_after_altering from t;
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
select b.rdb$field_name field_name, cast(a.rdb$computed_source as varchar(80)) computed_source_after_altering
|
2022-01-18 20:45:21 +01:00
|
|
|
from rdb$fields a
|
2021-04-26 20:07:00 +02:00
|
|
|
join rdb$relation_fields b on a.rdb$field_name = b.rdb$field_source
|
|
|
|
where b.rdb$field_name = upper('CF');
|
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)
|
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
|
|
|
F1 0123456789
|
|
|
|
F2 abcdefghij
|
|
|
|
CF_BEFORE_ALTERING 0123456789 - abcdefghij
|
2022-01-18 20:45:21 +01:00
|
|
|
|
|
|
|
FIELD_NAME CF
|
2021-04-26 20:07:00 +02:00
|
|
|
COMPUTED_SOURCE_BEFORE_ALTERING (f1 || ' - ' || f2)
|
2022-01-18 20:45:21 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
F1 0123456789
|
|
|
|
F2 abcdefghij
|
|
|
|
CF_AFTER_ALTERING 0123456789 - abcdefghij
|
2022-01-18 20:45:21 +01:00
|
|
|
|
|
|
|
FIELD_NAME CF
|
2021-04-26 20:07:00 +02:00
|
|
|
COMPUTED_SOURCE_AFTER_ALTERING (f1 || ' - ' || f2)
|
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 = 42000
|
|
|
|
unsuccessful metadata update
|
|
|
|
-ALTER TABLE T failed
|
|
|
|
-Cannot add or remove COMPUTED from column CF
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2022-01-18 20:45:21 +01:00
|
|
|
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
|
|
|
|