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_5876_test.py

102 lines
2.7 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-26 21:10:46 +01:00
"""
ID: issue-6135
ISSUE: 6135
TITLE: Provide name of udf function for "arithmetic exception, numeric overflow, or string truncation"
DESCRIPTION:
*** FOR FB 3.X ONLY ***
Test uses UDF 'sright' declared in ib_udf.sql script which for sure present in every FB snapshot.
After this, we try to create PSQL function with the same signature.
*** FOR FB 4.X AND ABOVE ***
Added separate code for running on FB 4.0.x: use udf_compat!UC_div from UDR engine.
It seems that this UDR function is the only wich we can force to raise exception by passing invalid
argument #2 that will cause zero divide.
UDF usage is deprecated in FB 4+, see: ".../doc/README.incompatibilities.3to4.txt".
Functions div, frac, dow, sdow, getExactTimestampUTC and isLeapYear got safe replacement
in UDR library "udf_compat", see it in folder: ../plugins/udr/
JIRA: CORE-5876
FBTEST: bugs.core_5876
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
# version: 3.0
2021-04-26 20:07:00 +02:00
test_script_1 = """
set term ^;
execute block as
begin
execute statement 'drop function substr';
when any do begin end
end
^
set term ;^
commit;
declare external function substr
cstring(80), smallint, smallint
returns cstring(80)
entry_point 'IB_UDF_substr'
module_name 'ib_udf'
;
commit;
set heading off;
select substr(cast('abc' as char(1500)) || '123', 1, 1000)
2022-01-26 21:10:46 +01:00
from rdb$database
2021-04-26 20:07:00 +02:00
;
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_1 = isql_act('db', test_script_1)
2021-04-26 20:07:00 +02:00
expected_stderr_1 = """
Statement failed, SQLSTATE = 22001
arithmetic exception, numeric overflow, or string truncation
-string right truncation
-expected length 80, actual 1503
-UDF: SUBSTR
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0.4,<4.0')
2021-04-28 12:42:11 +02:00
def test_1(act_1: Action):
2021-04-26 20:07:00 +02:00
act_1.expected_stderr = expected_stderr_1
act_1.execute()
2021-12-22 20:23:11 +01:00
assert act_1.clean_stderr == act_1.clean_expected_stderr
2021-04-26 20:07:00 +02:00
# version: 4.0
test_script_2 = """
create function UDR40_div (
n1 integer,
n2 integer
) returns double precision
external name 'udf_compat!UC_div'
engine udr;
commit;
set list on;
select UDR40_div( 1, 0) from rdb$database;
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_2 = isql_act('db', test_script_2)
2021-04-26 20:07:00 +02:00
expected_stderr_2 = """
Statement failed, SQLSTATE = 22012
arithmetic exception, numeric overflow, or string truncation
-Integer divide by zero. The code attempted to divide an integer value by an integer divisor of zero.
-At function 'UDR40_DIV'
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=4.0')
2021-04-28 12:42:11 +02:00
def test_2(act_2: Action):
2021-04-26 20:07:00 +02:00
act_2.expected_stderr = expected_stderr_2
act_2.execute()
2021-12-22 20:23:11 +01:00
assert act_2.clean_stderr == act_2.clean_expected_stderr