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_2197_test.py

87 lines
2.5 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-21 18:49:26 +01:00
"""
ID: issue-2625
ISSUE: 2625
TITLE: Add support for -nodbtriggers switch in gbak into services API
DESCRIPTION:
We add two database triggers (on connect and on disconnect) and make them do real work only when
new attachment will be established (see trick with rdb$get_context('USER_SESSION', 'INIT_STATE') ).
After finish backup we restore database and check that there is no records in 'log' table.
(if option 'bkp_no_triggers' will be omitted then two records will be in that table).
JIRA: CORE-2197
"""
2021-04-26 20:07:00 +02:00
import pytest
2022-01-21 18:49:26 +01:00
from firebird.qa import *
2021-11-12 18:29:54 +01:00
from io import BytesIO
from firebird.driver import SrvRestoreFlag, SrvBackupFlag
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
init_script = """
2021-04-26 20:07:00 +02:00
recreate table log( att bigint default current_connection, event_name varchar(20) );
create sequence g;
set term ^;
create or alter trigger trg_attach inactive on connect as
begin
if ( rdb$get_context('USER_SESSION', 'INIT_STATE') is null ) then
insert into log(event_name) values ('attach');
end
^
create or alter trigger trg_detach inactive on disconnect as
begin
if ( rdb$get_context('USER_SESSION', 'INIT_STATE') is null ) then
insert into log(event_name) values ('detach');
end
^
set term ^;
commit;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
db = db_factory(init=init_script)
2021-11-12 18:29:54 +01:00
2022-01-21 18:49:26 +01:00
test_script = """
delete from log;
commit;
set term ^;
execute block as begin
rdb$set_context('USER_SESSION', 'INIT_STATE','1');
end
^
set term ;^
alter trigger trg_attach active;
alter trigger trg_detach active;
commit;
--set count on;
--select * from log;
"""
2021-11-12 18:29:54 +01:00
2022-01-21 18:49:26 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
Records affected: 0
2021-11-12 18:29:54 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-21 18:49:26 +01:00
@pytest.mark.version('>=3')
def test_1(act: Action):
2021-11-12 18:29:54 +01:00
check_sql = 'set list on; set count on; select 1, g.* from log g;'
2022-01-21 18:49:26 +01:00
act.execute()
2021-11-12 18:29:54 +01:00
backup = BytesIO()
2022-01-21 18:49:26 +01:00
with act.connect_server() as srv:
srv.database.local_backup(database=act.db.db_path, backup_stream=backup,
2021-11-12 18:29:54 +01:00
flags=SrvBackupFlag.NO_TRIGGERS)
backup.seek(0)
2022-01-21 18:49:26 +01:00
act.reset()
act.expected_stdout = expected_stdout
act.isql(switches=['-nod'], input=check_sql)
assert act.clean_stdout == act.clean_expected_stdout
srv.database.local_restore(backup_stream=backup, database=act.db.db_path,
2021-11-12 18:29:54 +01:00
flags=SrvRestoreFlag.REPLACE)
backup.close()
2022-01-21 18:49:26 +01:00
act.reset()
act.expected_stdout = expected_stdout
act.isql(switches=['-nod'], input=check_sql)
assert act.clean_stdout == act.clean_expected_stdout
2021-11-12 18:29:54 +01:00
2021-04-26 20:07:00 +02:00