6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 21:43:06 +01:00
firebird-qa/tests/bugs/core_0119_test.py

106 lines
4.0 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-18 20:45:21 +01:00
"""
ID: issue-441
ISSUE: https://github.com/FirebirdSQL/firebird/issues/441
2022-01-18 20:45:21 +01:00
TITLE: Numeric div in dialect 3 mangles data
DESCRIPTION:
NOTES:
Results for FB 4.0 become differ from old one. Discussed with Alex, 30.10.2019.
Precise value of 70000 / 1.95583 is: 35790.431683735296 (checked on https://www.wolframalpha.com )
Section 'expected-stdout' was adjusted to be match for results that are issued in recent FB.
2022-01-18 20:45:21 +01:00
JIRA: CORE-119
FBTEST: bugs.core_0119
NOTES:
Discussed with Alex see in e-mail, letters 30.10.2019.
[21.06.2020] pzotov
4.0.0.2068 (see also: CORE-6337):
changed subtype from 0 to 1 for cast (-70000 as numeric (18,5)) / cast (1.95583 as numeric (18,5))
(after discuss with dimitr, letter 21.06.2020 08:43).
[25.06.2020] pzotov
4.0.0.2076: changed types in SQLDA from numeric to int128 // after discuss with Alex about CORE-6342.
[27.07.2021] pzotov
adjusted expected* sections to results in current snapshots FB 4.x and 5.x: this is needed since fix #6874
("Literal 65536 (interpreted as int) can not be multiplied by itself w/o cast if result more than 2^63-1") because
division -4611686018427387904/-0.5 does not issue error since this fix.
Checked on 5.0.0.113, 4.0.1.2539.
[10.12.2023] pzotov
Added 'SQLSTATE' in substitutions: runtime error must not be filtered out by '?!(...)' pattern
("negative lookahead assertion", see https://docs.python.org/3/library/re.html#regular-expression-syntax).
Added 'combine_output = True' in order to see SQLSTATE if any error occurs.
2022-01-18 20:45:21 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-18 20:45:21 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-18 20:45:21 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-18 20:45:21 +01:00
# version: 3.0
2021-04-26 20:07:00 +02:00
2022-01-18 20:45:21 +01:00
substitutions_1 = [('[ \t]+', ' ')]
2021-04-26 20:07:00 +02:00
test_script_1 = """
-- Stdout and stderr are OK in WI-V1.5.6.5026 and all above.
-- Number of digits in mantiss is the same both on WI- and LI-.
set list on;
select cast (-70000 as numeric (18,5)) / cast (1.95583 as numeric (18,5)) as result from rdb$database;
select (-4611686018427387904)/-0.5 from rdb$database;
"""
2022-01-18 20:45:21 +01:00
act_1 = isql_act('db', test_script_1, substitutions=substitutions_1)
expected_stdout_1 = """
RESULT -35790.4316837350
"""
2021-12-31 12:06:51 +01:00
expected_stderr_1 = """
Statement failed, SQLSTATE = 22003
arithmetic exception, numeric overflow, or string truncation
-numeric value is out of range
"""
2022-01-18 20:45:21 +01:00
@pytest.mark.version('>=3,<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()
2022-01-18 20:45:21 +01:00
assert (act_1.clean_stderr == act_1.clean_expected_stderr and
act_1.clean_stdout == act_1.clean_expected_stdout)
# version: 4.0
substitutions_2 = [('^((?!(SQLSTATE|sqltype|DIV_RESULT)).)*$', ''), ('[ \t]+', ' '), ('.*alias.*', '')]
test_script_2 = """
set bail on;
2021-04-26 20:07:00 +02:00
set list on;
set sqlda_display on;
select cast (-70000 as numeric (18,5)) / cast (1.95583 as numeric (18,5)) as div_result_1 from rdb$database;
-- doc\\sql.extensions\\README.data_types:
-- - QUANTIZE - has two DECFLOAT arguments. The returned value is first argument scaled using
-- second value as a pattern. For example QUANTIZE(1234, 9.999) returns 1234.000.
select QUANTIZE(cast(-70000 as decfloat(34)) / cast (1.95583 as decfloat(34)), 9.9999999999) as div_result_2 from rdb$database;
select (-4611686018427387904)/-0.5 div_result_3 from rdb$database;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-18 20:45:21 +01:00
act_2 = isql_act('db', test_script_2, substitutions=substitutions_2)
2021-04-26 20:07:00 +02:00
expected_stdout_2 = """
2021-04-26 20:07:00 +02:00
01: sqltype: 32752 INT128 scale: -10 subtype: 1 len: 16
DIV_RESULT_1 -35790.4316837352
01: sqltype: 32762 DECFLOAT(34) scale: 0 subtype: 0 len: 16
DIV_RESULT_2 -35790.4316837353
01: sqltype: 32752 INT128 scale: -1 subtype: 0 len: 16
DIV_RESULT_3 9223372036854775808.0
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
def test_2(act_2: Action):
act_2.expected_stdout = expected_stdout_2
act_2.execute(combine_output = True)
assert act_2.clean_stdout == act_2.clean_expected_stdout