6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-23 14:03:06 +01:00
firebird-qa/tests/functional/trigger/database/test_transactioncommit_01.py

72 lines
1.6 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-02-04 19:05:19 +01:00
"""
ID: trigger.database.transaction-commit
TITLE: Trigger on commit transaction. See also CORE-645
DESCRIPTION:
Test trigger on commit transaction
FBTEST: functional.trigger.database.transactioncommit_01
"""
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
init_script = """
2021-04-26 20:07:00 +02:00
SET AUTODDL OFF;
CREATE TABLE T1
(
T1_ID BIGINT NOT NULL,
T1_VAL CHAR(10) ,
CONSTRAINT PK_T1 PRIMARY KEY (T1_ID)
);
CREATE SEQUENCE S_TRANSACTION;
SET TERM ^ ;
RECREATE TRIGGER TRIG_TRANSAC ACTIVE
ON TRANSACTION COMMIT
POSITION 0
AS
BEGIN
RDB$SET_CONTEXT('USER_SESSION', 'Trn_ID', (NEXT VALUE FOR S_TRANSACTION));
END^
SET TERM ; ^
COMMIT;
2022-02-04 19:05:19 +01:00
"""
db = db_factory(init=init_script)
test_script = """SET AUTODDL OFF;
2021-04-26 20:07:00 +02:00
SET LIST ON;
2022-02-04 19:05:19 +01:00
2021-04-26 20:07:00 +02:00
INSERT INTO T1 VALUES (1,'val1');
SELECT RDB$GET_CONTEXT('USER_SESSION', 'Trn_ID') AS CTX_VAR FROM RDB$DATABASE;
COMMIT;
UPDATE T1 SET T1_VAL='val1mod' WHERE T1_ID=1;
SELECT RDB$GET_CONTEXT('USER_SESSION', 'Trn_ID') AS CTX_VAR FROM RDB$DATABASE;
ROLLBACK;
DELETE FROM T1 WHERE T1_ID=1;
SELECT RDB$GET_CONTEXT('USER_SESSION', 'Trn_ID') AS CTX_VAR FROM RDB$DATABASE;
COMMIT;
SELECT RDB$GET_CONTEXT('USER_SESSION', 'Trn_ID') AS CTX_VAR FROM RDB$DATABASE;
"""
2021-04-26 20:07:00 +02:00
2022-02-04 19:05:19 +01:00
act = isql_act('db', test_script, substitutions=[('[ \t]+', ' ')])
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
CTX_VAR <null>
CTX_VAR 3
CTX_VAR 3
2022-02-04 19:05:19 +01:00
CTX_VAR 4
"""
2021-04-26 20:07:00 +02:00
2022-02-04 19:05:19 +01:00
@pytest.mark.version('>=3.0')
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout