6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00

Added/Updated tests\bugs\core_0790_test.py: refactored, see notes.

This commit is contained in:
pavel-zotov 2023-10-04 20:38:53 +03:00
parent bf5e325eed
commit 05c9349c8f

View File

@ -2,71 +2,126 @@
""" """
ID: issue-1175 ID: issue-1175
ISSUE: 1175 ISSUE: https://github.com/FirebirdSQL/firebird/issues/1175
TITLE: Alter view TITLE: Ability to run ALTER VIEW statement without dropping dependencies
DESCRIPTION: DESCRIPTION:
Test creates a table and view ('v_words') based on it.
Then we create several PSQL units and views which depend on that view v_words and on each other.
After this, we run ALTER VIEW V_WORDS and change expression for one of it column - it must be performed without errors.
Finally, we check data that is shown by each of dependent views.
JIRA: CORE-790 JIRA: CORE-790
FBTEST: bugs.core_0790 FBTEST: bugs.core_0790
NOTES:
[04.10.2023] pzotov
RECONNECT is required after altering V_WORDS! Otherwise PSQL objects remain show 'old' data.
Checked on fresh 3.x, 4.x, 5.x and 6.x.
""" """
import pytest import pytest
from firebird.qa import * from firebird.qa import *
init_script = """create table users ( init_script = """
id integer, create table words (
name varchar(20), id int
passwd varchar(20) ,name varchar(20)
); );
commit;
create view v_users as insert into words(id, name) values(2, 'tab');
select name from users; insert into words(id, name) values(3, 'case');
commit;""" insert into words(id, name) values(0, 'war');
insert into words(id, name) values(1, 'flow');
commit;
"""
db = db_factory(init=init_script) db = db_factory(init=init_script)
test_script = """alter view v_users (id, name, passwd ) as test_script = """
select id, name, passwd from users; set bail on;
commit; set term ^;
show view v_users; create view v_words as select id, name from words
create view v_users_name as ^
select name from v_users; create procedure sp_get_word_by_pattern(a_name_pattern varchar(50)) returns(name type of column words.name) as
commit; begin
alter view v_users (id, name ) as for
select id, name from users; execute statement ('select v.name from v_words v where v.name similar to ?') (:a_name_pattern)
commit; into name
show view v_users; do suspend;
show view v_users_name; end
^
create procedure sp_get_word_by_id(a_id type of column words.id) returns (name type of column words.name) as
begin
for select v.name from v_words v where v.id = :a_id into name do suspend;
end
^
create function fn_get_word_by_id(a_id type of column words.id) returns type of column words.name as
begin
return (select v.name from v_words v where v.id = :a_id);
end
^
create view v_words_similar_to_o as select p.name as name_similar_to_o from sp_get_word_by_pattern('%(wolf)%') p
^
create view v_sp_get_word_by_id as select name as name_by_id_using_sp from sp_get_word_by_id(1)
^
create view v_fn_get_word_by_id as select fn_get_word_by_id(1) as name_by_id_using_fn from rdb$database
^
create function fn_count_words_by_pattern(a_name_pattern varchar(50)) returns int as
begin
return (select count(*) from sp_get_word_by_pattern(:a_name_pattern));
end
^
create view v_count_words_similar_to_a as select fn_count_words_by_pattern('%(raw|esac|bat)%') as cnt from rdb$database
^
set term ;^
commit;
-- Result: view V_words has 5 dependencies.
-- We can not drop columns 'id' and 'name' but we *must* have ability change expression based on them
alter view v_words as
select reverse(name) as name, id
from words;
commit;
connect '$(DSN)'; -- ::: NB ::: this is mandatory! Otherwise PSQL objects based on this view will show 'old' data ('flow' instead of 'wolf' etc).
set list on;
set count on;
set echo on;
select * from v_count_words_similar_to_a;
select * from v_words_similar_to_o order by 1;
select * from v_sp_get_word_by_id;
select * from v_fn_get_word_by_id;
select v.name from v_words v where v.id = 1;
""" """
act = isql_act('db', test_script) act = isql_act('db', test_script)
expected_stdout = """Database: test.fdb, User: SYSDBA expected_stdout = """
SQL> CON> SQL> SQL> ID INTEGER Nullable select * from v_count_words_similar_to_a;
NAME VARCHAR(20) Nullable CNT 3
PASSWD VARCHAR(20) Nullable Records affected: 1
View Source: select * from v_words_similar_to_o order by 1;
==== ====== NAME_SIMILAR_TO_O wolf
Records affected: 1
select id, name, passwd from users select * from v_sp_get_word_by_id;
SQL> CON> SQL> SQL> CON> SQL> SQL> ID INTEGER Nullable NAME_BY_ID_USING_SP wolf
NAME VARCHAR(20) Nullable Records affected: 1
View Source: select * from v_fn_get_word_by_id;
==== ====== NAME_BY_ID_USING_FN wolf
Records affected: 1
select id, name from users select v.name from v_words v where v.id = 1;
SQL> NAME VARCHAR(20) Nullable NAME wolf
View Source: Records affected: 1
==== ======
select name from v_users
SQL> SQL> SQL> SQL>
""" """
@pytest.mark.version('>=3') @pytest.mark.version('>=3')
def test_1(act: Action): def test_1(act: Action):
act.expected_stdout = expected_stdout act.expected_stdout = expected_stdout
act.execute() act.execute(combine_output = True)
assert act.clean_stdout == act.clean_expected_stdout assert act.clean_stdout == act.clean_expected_stdout