#coding:utf-8 # # id: functional.session.alter_session_reset_decfloat # title: # ALTER SESSION RESET: DECFLOAT parameters must be returned to default values # # decription: # Test issue from CORE-5832 about ALTER SESSION RESET: # "DECFLOAT parameters (BIND, TRAP and ROUND) must be reset to default values". # # We change all three specified parameters and evaluate some expressions. # Then we run RESET SESSION and evaluate the same expressions. # Results must differ for all of them. # # NOTE-1. # FDB driver 2.0.1 does not support DEFCFLOAT datatype (at least version 2.0.1), # so test type must be ISQL. # # NOTE-2. *** SET AUTODDL OFF REQUIRED *** # Following is detailed explanation of this note: # ======== # Default ISQL behaviour is to start always *TWO* transactions (for DML and second for DDL) # after previous commit / rollback and before *ANY* further satement is to be executed, except # those which control ISQL itself (e.g. 'SET TERM'; 'IN ...'; 'SET BAIL' etc). # So, even when statement has nothing to change, ISQL will start TWO transactions # just before executing . # This means that these transactions will start even if want to run 'ALTER SESSION RESET'. # This, in turn, makes one of them (which must perform DDL) be 'active and NOT current' # from ALTER SESSION point of view (which is run within DML transaction). # # According to description given in CORE-5832, ALTER SESSION throws error isc_ses_reset_err # "if any open transaction exist in current conneciton, *except of current transaction* and # prepared 2PC transactions which is allowed and ignored by this check". # # So, we have to prohibit 'autostart' of DDL-transaction because otherwise ALTER SESSION will # throw: "SQLSTATE = 01002 / Cannot reset user session / -There are open transactions (2 active)". # This is done by 'SET AUTODDL OFF' statement at the beginning of this test script. # ======== # # Thanks to Vlad for explanations (discussed 18.01.2021). # Checked on 4.0.0.2307 SS/CS. # # tracker_id: # min_versions: ['4.0.0'] # versions: 4.0 # qmid: None import pytest from firebird.qa import db_factory, isql_act, Action # version: 4.0 # resources: None substitutions_1 = [('^((?!(sqltype|before_reset|after_reset)).)*$', ''), ('[ \t]+', ' '), ('.*alias.*', '')] init_script_1 = """""" db_1 = db_factory(sql_dialect=3, init=init_script_1) test_script_1 = """ recreate table test(a decfloat, b decfloat, c decfloat); insert into test(a,b,c) values(1608.90, 5.00, 100.00); commit; set list on; set autoddl off; commit; set bind of decfloat to smallint; set decfloat traps to; set decfloat round ceiling; set sqlda_display on; select cast(1234.5678 as decfloat(16)) as "before_reset: check datatype" from rdb$database; set sqlda_display off; -- Should issue: Infinity select 1/1e-9999 as "before_reset: check division result" from rdb$database; select a * b / c as "before_reset: check round result" from test; -------------------- alter session reset; -------------------- set sqlda_display on; select cast(1234.5678 as decfloat(16)) as "after_reset: check datatype" from rdb$database; set sqlda_display off; -- Should issue: -- Statement failed, SQLSTATE = 22012 -- Decimal float divide by zero. The code attempted to divide a DECFLOAT value by zero. select 1/1e-9999 "after_reset: check division result" from rdb$database; select a * b / c as "after_reset: check round result" from test; """ act_1 = isql_act('db_1', test_script_1, substitutions=substitutions_1) expected_stdout_1 = """ 01: sqltype: 500 SHORT scale: 0 subtype: 0 len: 2 before_reset: check datatype 1235 before_reset: check division result 0 before_reset: check round result 81 01: sqltype: 32760 DECFLOAT(16) scale: 0 subtype: 0 len: 8 after_reset: check datatype 1234.5678 after_reset: check round result 80.445 """ expected_stderr_1 = """ Statement failed, SQLSTATE = 22012 Decimal float divide by zero. The code attempted to divide a DECFLOAT value by zero. """ @pytest.mark.version('>=4.0') def test_1(act_1: Action): act_1.expected_stdout = expected_stdout_1 act_1.expected_stderr = expected_stderr_1 act_1.execute() assert act_1.clean_stderr == act_1.clean_expected_stderr assert act_1.clean_stdout == act_1.clean_expected_stdout