2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
"""
|
|
|
|
ID: computed-fields-14
|
|
|
|
FBTEST: functional.gtcs.computed_fields_14
|
|
|
|
TITLE: Computed fields
|
|
|
|
DESCRIPTION:
|
|
|
|
Original test see in:
|
|
|
|
https://github.com/FirebirdSQL/fbtcs/blob/master/GTCS/tests/CF_ISQL_14.script
|
|
|
|
SQL script for creating test database ('gtcs_sp1.fbk') and fill it with some data:
|
|
|
|
https://github.com/FirebirdSQL/fbtcs/blob/master/GTCS/tests/PROCS_QA_INIT_ISQL.script
|
|
|
|
"""
|
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
|
|
|
db = db_factory()
|
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
|
|
|
set heading off;
|
|
|
|
/*---------------------------------------------*/
|
|
|
|
/* Create a table with computed field. */
|
|
|
|
/*---------------------------------------------*/
|
|
|
|
create table t0 (a integer, af computed by (a*3));
|
|
|
|
insert into t0(a) values(10);
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------*/
|
|
|
|
/* Insert a value into computed-field column, which should fail. */
|
|
|
|
/*---------------------------------------------------------------*/
|
|
|
|
insert into t0(af) values(11);
|
|
|
|
select 'point-1' msg, p.* from t0 p;
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------*/
|
|
|
|
/* Update the computed-field column directly, which should fail. */
|
|
|
|
/*---------------------------------------------------------------*/
|
|
|
|
update t0 set af = 99 where a = 10;
|
|
|
|
select 'point-2' msg, p.* from t0 p;
|
|
|
|
|
|
|
|
/*---------------------------------------------------------------*/
|
|
|
|
/* Create a table with only a computed-field should fail. */
|
|
|
|
/*---------------------------------------------------------------*/
|
|
|
|
create table t5 (af computed by (1+2));
|
|
|
|
|
|
|
|
/*-----------------------------------------------------------------*/
|
|
|
|
/* Create a table with a computed-field, which has constant value. */
|
|
|
|
/* Trying to insert a value in it should fail. */
|
|
|
|
/*-----------------------------------------------------------------*/
|
|
|
|
create table t6 (af int, bf computed by (1+2));
|
|
|
|
insert into t6 values(10, 12);
|
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=[('=', ''), ('[ \t]+', ' '),
|
|
|
|
('attempted update of read-only column.*',
|
|
|
|
'attempted update of read-only column')])
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
expected_stdout = """
|
2021-04-26 20:07:00 +02:00
|
|
|
point-1 10 30
|
|
|
|
point-2 10 30
|
2021-12-22 20:25:10 +01:00
|
|
|
"""
|
2022-02-04 19:05:19 +01:00
|
|
|
|
|
|
|
expected_stderr = """
|
2021-04-26 20:07:00 +02:00
|
|
|
Statement failed, SQLSTATE 42000
|
|
|
|
attempted update of read-only column
|
|
|
|
|
|
|
|
Statement failed, SQLSTATE 42000
|
|
|
|
attempted update of read-only column
|
|
|
|
|
|
|
|
Statement failed, SQLSTATE 42000
|
|
|
|
unsuccessful metadata update
|
|
|
|
-TABLE T5
|
|
|
|
-Can't have relation with only computed fields or constraints
|
|
|
|
|
|
|
|
Statement failed, SQLSTATE 21S01
|
|
|
|
Dynamic SQL Error
|
|
|
|
-SQL error code -804
|
|
|
|
-Count of read-write columns does not equal count of values
|
2021-12-22 20:25:10 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-04 19:05:19 +01:00
|
|
|
@pytest.mark.version('>=3')
|
|
|
|
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)
|