6
0
mirror of https://github.com/FirebirdSQL/firebird-qa.git synced 2025-01-22 13:33:07 +01:00
firebird-qa/tests/bugs/core_6398_test.py

87 lines
2.6 KiB
Python
Raw Permalink Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-27 20:08:36 +01:00
"""
ID: issue-6636
ISSUE: 6636
TITLE: Error converting string with hex representation of integer to smallint
DESCRIPTION:
Bug initially was detected when adapted some of GTCS-tests which tries to convert
numeric values from all possible combinations of datatypes.
Particularly, conversion error was when try to cast "0x7fffffffffffffff" to bigint.
See letter to Alex et al, 08-JUN-2020 15:38.
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
It was decided to check here not only cast to smallint but also to other integer dadatypes.
JIRA: CORE-6398
FBTEST: bugs.core_6398
2022-01-27 20:08:36 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
test_script = """
2021-04-26 20:07:00 +02:00
set term ^;
create or alter procedure "blob_smallint_explicit_cast" ( a blob ) returns ( b smallint ) as
begin
b = cast(a as smallint);
suspend;
end
^
create or alter procedure "blob_int_explicit_cast" ( a blob ) returns ( b int ) as
begin
b = cast(a as int);
suspend;
end
^
create or alter procedure "blob_bigint_explicit_cast" ( a blob ) returns ( b bigint ) as
begin
b = cast(a as bigint);
suspend;
end
^
create or alter procedure "blob_int128_explicit_cast" ( a blob ) returns ( b int128 ) as
begin
b = cast(a as int128);
suspend;
end
^
set term ;^
commit;
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
set heading off;
select p.b as "blob_smallint_explicit_cast" from "blob_smallint_explicit_cast"('0x7fff') p;
-- FAILED before fix: "numeric value is out of range":
select p.b as "blob_smallint_explicit_cast" from "blob_smallint_explicit_cast"('0x8000') p;
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
select p.b as "blob_int_explicit_cast" from "blob_int_explicit_cast"('0x7fffffff') p;
select p.b as "blob_int_explicit_cast" from "blob_int_explicit_cast"('0x80000000') p;
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
select p.b as "blob_bigint_explicit_cast" from "blob_bigint_explicit_cast"('0x7fffffffffffffff') p;
select p.b as "blob_bigint_explicit_cast" from "blob_bigint_explicit_cast"('0x8000000000000000') p;
2022-01-27 20:08:36 +01:00
2021-04-26 20:07:00 +02:00
select p.b as "blob_int128_explicit_cast" from "blob_int128_explicit_cast"('0x7fffffffffffffffffffffffffffffff') p;
select p.b as "blob_int128_explicit_cast" from "blob_int128_explicit_cast"('0x80000000000000000000000000000000') p;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
act = isql_act('db', test_script)
2021-04-26 20:07:00 +02:00
2022-01-27 20:08:36 +01:00
expected_stdout = """
2021-04-26 20:07:00 +02:00
32767
-32768
2147483647
-2147483648
9223372036854775807
-9223372036854775808
170141183460469231731687303715884105727
-170141183460469231731687303715884105728
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
2022-01-27 20:08:36 +01:00
def test_1(act: Action):
act.expected_stdout = expected_stdout
act.execute()
assert act.clean_stdout == act.clean_expected_stdout