2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-26 21:10:46 +01:00
|
|
|
"""
|
|
|
|
ID: issue-6179
|
|
|
|
ISSUE: 6179
|
2022-02-02 15:46:19 +01:00
|
|
|
TITLE: Provide information about Global Commit Number, Commit Number of currently used
|
|
|
|
database snapshot (if any) and Commit Numbers assigned to the committed transactions
|
2022-01-26 21:10:46 +01:00
|
|
|
DESCRIPTION:
|
|
|
|
From doc\\sql.extensions\\README.builtin_functions.txt about rdb$get_transaction_cn() function:
|
|
|
|
===
|
|
|
|
... numbers returned by RDB$GET_TRANSACTION_CN could have values below:
|
|
|
|
-2 - transaction is dead (rolled back)
|
|
|
|
-1 - transaction is in limbo
|
|
|
|
0 - transaction is active,
|
|
|
|
1 - transaction committed before database started or less than OIT
|
|
|
|
>1 - transaction committed after database started
|
|
|
|
NULL - given transaction number is NULL or greater than database Next Transaction
|
|
|
|
===
|
|
|
|
|
|
|
|
This ISQL-based test does NOT verify cases when tx is dead or in limbo.
|
|
|
|
Perhaps, Python-based implementation is required and will be created later.
|
|
|
|
NOTES:
|
|
|
|
[05.03.2019]
|
|
|
|
renamed RDB$GET_CONTEXT('SYSTEM', 'SNAPSHOT_CN') to RDB$GET_CONTEXT('SYSTEM', 'SNAPSHOT_NUMBER')
|
|
|
|
-- see CORE-6016. Checked on 4.0.0.1455
|
|
|
|
[09.11.2019]
|
|
|
|
added section with substitutions because GET_OIT_CN can differ in SS vs CS: 9 and 10.
|
2022-02-07 18:03:19 +01:00
|
|
|
[07.02.2022] pcisar
|
|
|
|
Test fails on 4.0.1, because expected output differs:
|
|
|
|
real:
|
|
|
|
MSG_B For TX > OIT
|
|
|
|
GET_TX_B_CN 7
|
|
|
|
expected:
|
|
|
|
MSG_B For TX < OIT
|
|
|
|
GET_TX_B_CN 1
|
2022-01-26 21:10:46 +01:00
|
|
|
JIRA: CORE-5921
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_5921
|
2022-01-26 21:10:46 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-26 21:10:46 +01:00
|
|
|
import pytest
|
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-26 21:10:46 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-26 21:10:46 +01:00
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
set list on;
|
|
|
|
set term ^;
|
|
|
|
create or alter procedure sp_set_tx_ctx( a_ctx_var_name varchar(80) ) as
|
|
|
|
begin
|
|
|
|
rdb$set_context('USER_SESSION', :a_ctx_var_name, current_transaction);
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
|
|
|
|
|
|
|
set list on;
|
|
|
|
execute procedure sp_set_tx_ctx('tx_a');
|
|
|
|
|
2022-01-26 21:10:46 +01:00
|
|
|
select
|
2021-04-26 20:07:00 +02:00
|
|
|
iif( tx_a < tx_oit, 'For TX < OIT', iif( tx_a = tx_oit, 'For OIT', 'For TX > OIT') ) as msg_a
|
|
|
|
,rdb$get_transaction_cn( tx_a ) as get_tx_a_cn
|
|
|
|
from (
|
2022-01-26 21:10:46 +01:00
|
|
|
select
|
2021-04-26 20:07:00 +02:00
|
|
|
d.mon$oldest_transaction as tx_oit
|
|
|
|
,cast( rdb$get_context('USER_SESSION','tx_a') as int ) as tx_a
|
|
|
|
from mon$database d
|
|
|
|
)
|
|
|
|
;
|
|
|
|
rollback;
|
|
|
|
|
|
|
|
execute procedure sp_set_tx_ctx('tx_b');
|
|
|
|
commit;
|
|
|
|
|
2022-01-26 21:10:46 +01:00
|
|
|
select
|
2021-04-26 20:07:00 +02:00
|
|
|
iif( tx_b < tx_oit, 'For TX < OIT', iif( tx_b = tx_oit, 'For OIT', 'For TX > OIT') ) as msg_b
|
|
|
|
,rdb$get_transaction_cn( tx_b ) as get_tx_b_cn
|
|
|
|
from (
|
2022-01-26 21:10:46 +01:00
|
|
|
select
|
2021-04-26 20:07:00 +02:00
|
|
|
d.mon$oldest_transaction as tx_oit
|
|
|
|
,cast( rdb$get_context('USER_SESSION','tx_b') as int ) as tx_b
|
|
|
|
from mon$database d
|
|
|
|
)
|
|
|
|
;
|
|
|
|
|
|
|
|
select
|
|
|
|
rdb$get_transaction_cn( d.mon$oldest_transaction ) as get_oit_cn
|
|
|
|
,rdb$get_transaction_cn( current_transaction ) as get_tx_c_cn
|
|
|
|
,rdb$get_transaction_cn( null ) as get_tx_nul_cn
|
|
|
|
,rdb$get_transaction_cn( mon$next_transaction + 1 ) as get_tx_nxx_cn
|
2022-01-26 21:10:46 +01:00
|
|
|
-- added 25.09.2018, after commit
|
2021-04-26 20:07:00 +02:00
|
|
|
-- https://github.com/FirebirdSQL/firebird/commit/7610a76ff3f263177d0a9f7b02cdc1784a0f3402
|
|
|
|
-- all of these columns must contain NULL:
|
|
|
|
,rdb$get_transaction_cn( mon$next_transaction + (9223372036854775807-mon$next_transaction) ) as get_tx_001_cn
|
|
|
|
,rdb$get_transaction_cn( 9223372036854775807 ) as get_tx_002_cn
|
|
|
|
,rdb$get_transaction_cn(-9223372036854775808) as get_tx_003_cn
|
|
|
|
from mon$database d;
|
2022-01-26 21:10:46 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set term ^;
|
|
|
|
execute block returns( global_cn_sign smallint, snapshot_cn smallint ) as
|
|
|
|
begin
|
|
|
|
global_cn_sign = sign( rdb$get_context('SYSTEM', 'GLOBAL_CN') );
|
|
|
|
snapshot_cn = sign( rdb$get_context('SYSTEM', 'SNAPSHOT_NUMBER') );
|
|
|
|
suspend;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-26 21:10:46 +01:00
|
|
|
act = isql_act('db', test_script, substitutions=[('GET_OIT_CN[ \t]+[\\d]+', 'GET_OIT_CN <digit>'),
|
|
|
|
('[ \t]+', ' ')])
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-26 21:10:46 +01:00
|
|
|
expected_stdout = """
|
2021-04-26 20:07:00 +02:00
|
|
|
MSG_A For TX > OIT
|
|
|
|
GET_TX_A_CN 0
|
|
|
|
|
|
|
|
MSG_B For TX < OIT
|
|
|
|
GET_TX_B_CN 1
|
|
|
|
|
|
|
|
GET_OIT_CN 9
|
|
|
|
GET_TX_C_CN 0
|
|
|
|
|
|
|
|
GET_TX_NUL_CN <null>
|
|
|
|
GET_TX_NXX_CN <null>
|
|
|
|
GET_TX_001_CN <null>
|
|
|
|
GET_TX_002_CN <null>
|
|
|
|
GET_TX_003_CN <null>
|
|
|
|
|
|
|
|
GLOBAL_CN_SIGN 1
|
|
|
|
SNAPSHOT_CN 1
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-02-07 18:03:19 +01:00
|
|
|
@pytest.mark.skip("FIXME: see notes")
|
2021-04-26 20:07:00 +02:00
|
|
|
@pytest.mark.version('>=4.0')
|
2022-01-26 21:10:46 +01:00
|
|
|
def test_1(act: Action):
|
|
|
|
act.expected_stdout = expected_stdout
|
|
|
|
act.execute()
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|