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

223 lines
5.4 KiB
Python
Raw Normal View History

2021-04-26 20:07:00 +02:00
#coding:utf-8
2022-01-22 21:59:15 +01:00
"""
ID: issue-4296
ISSUE: 4296
TITLE: isql doesn't know the difference between UDF's and psql-functions
DESCRIPTION:
* FOR FB 3.X ONLY *
Test uses UDF 'strlen' 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 but evaluate its returning value
as double size of input argument (in order to distinguish these functions by their results).
* FOR FB 4.X AND ABOVE *
Added separate code for running on FB 4.0.x.
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-3963
FBTEST: bugs.core_3963
2022-01-22 21:59:15 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
import pytest
from firebird.qa import *
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
db = db_factory()
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
# version: 3.0
2021-04-26 20:07:00 +02:00
test_script_1 = """
set list on;
--set echo on;
-- Should PASS:
2022-01-22 21:59:15 +01:00
set term ^;
2021-04-26 20:07:00 +02:00
create function strlen(s varchar(32765)) returns int as begin return 2 * char_length(s); end
2022-01-22 21:59:15 +01:00
^
2021-04-26 20:07:00 +02:00
set term ;^
select strlen('tratata') from rdb$database;
commit;
-- Should FAIL:
DECLARE EXTERNAL FUNCTION strlen CSTRING(32767) RETURNS INTEGER BY VALUE ENTRY_POINT 'IB_UDF_strlen' MODULE_NAME 'ib_udf';
2022-01-22 21:59:15 +01:00
drop function strlen; -- kill PSQL function
2021-04-26 20:07:00 +02:00
commit;
-- Should PASS:
DECLARE EXTERNAL FUNCTION strlen CSTRING(32767) RETURNS INTEGER BY VALUE ENTRY_POINT 'IB_UDF_strlen' MODULE_NAME 'ib_udf';
select strlen('tratata') from rdb$database;
commit;
-- Should FAIL:
2022-01-22 21:59:15 +01:00
set term ^;
2021-04-26 20:07:00 +02:00
create function strlen(s varchar(32765)) returns int as begin return 2 * char_length(s); end
2022-01-22 21:59:15 +01:00
^
2021-04-26 20:07:00 +02:00
set term ;^
select strlen('tratata') from rdb$database;
commit;
drop function strlen; -- kill UDF function
commit;
-- Should PASS:
2022-01-22 21:59:15 +01:00
set term ^;
2021-04-26 20:07:00 +02:00
create function strlen(s varchar(32765)) returns int as begin return 2 * char_length(s); end
2022-01-22 21:59:15 +01:00
^
2021-04-26 20:07:00 +02:00
set term ;^
select strlen('tratata') from rdb$database;
commit;
drop function strlen;
commit;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
act_1 = isql_act('db', test_script_1)
2021-04-26 20:07:00 +02:00
expected_stdout_1 = """
STRLEN 14
STRLEN 7
STRLEN 7
STRLEN 14
2021-12-22 20:23:11 +01:00
"""
2022-01-22 21:59:15 +01:00
2021-04-26 20:07:00 +02:00
expected_stderr_1 = """
Statement failed, SQLSTATE = 42000
unsuccessful metadata update
-CREATE FUNCTION STRLEN failed
-Function STRLEN already exists
Statement failed, SQLSTATE = 42000
unsuccessful metadata update
-CREATE FUNCTION STRLEN failed
-Function STRLEN already exists
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
@pytest.mark.version('>=3.0,<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_stdout = expected_stdout_1
act_1.expected_stderr = expected_stderr_1
act_1.execute()
2022-01-22 21:59:15 +01:00
assert (act_1.clean_stderr == act_1.clean_expected_stderr and
act_1.clean_stdout == act_1.clean_expected_stdout)
2021-04-26 20:07:00 +02:00
# version: 4.0
test_script_2 = """
set list on;
-- See declaration sample in plugins\\udr\\UdfBackwardCompatibility.sql:
create function the_frac(
val double precision
) returns double precision
external name 'udf_compat!UC_frac'
engine udr;
commit;
set sqlda_display on;
select the_frac( -pi() ) from rdb$database;
commit;
-- should FAIL:
2022-01-22 21:59:15 +01:00
set term ^;
create function the_frac( val double precision ) returns double precision as
begin
return val - cast(val as int);
2021-04-26 20:07:00 +02:00
end
2022-01-22 21:59:15 +01:00
^
2021-04-26 20:07:00 +02:00
set term ;^
commit;
-- should PASS:
drop function the_frac;
commit;
-- should FAIL:
select the_frac( -pi() ) from rdb$database;
commit;
-- should PASS:
2022-01-22 21:59:15 +01:00
set term ^;
create function the_frac( val double precision ) returns double precision as
begin
return val - cast(val as int);
2021-04-26 20:07:00 +02:00
end
2022-01-22 21:59:15 +01:00
^
2021-04-26 20:07:00 +02:00
set term ;^
commit;
-- should PASS:
select the_frac( -pi() ) from rdb$database;
commit;
-- should FAIL:
create function the_frac(
val double precision
) returns double precision
external name 'udf_compat!UC_frac'
engine udr;
commit;
2021-12-22 20:23:11 +01:00
"""
2021-04-26 20:07:00 +02:00
2022-01-22 21:59:15 +01:00
act_2 = isql_act('db', test_script_2)
2021-04-26 20:07:00 +02:00
expected_stdout_2 = """
INPUT message field count: 0
OUTPUT message field count: 1
01: sqltype: 480 DOUBLE Nullable scale: 0 subtype: 0 len: 8
: name: THE_FRAC alias: THE_FRAC
2022-01-22 21:59:15 +01:00
: table: owner:
2021-04-26 20:07:00 +02:00
THE_FRAC -0.1415926535897931
INPUT message field count: 0
OUTPUT message field count: 1
01: sqltype: 480 DOUBLE Nullable scale: 0 subtype: 0 len: 8
: name: THE_FRAC alias: THE_FRAC
2022-01-22 21:59:15 +01:00
: table: owner:
2021-04-26 20:07:00 +02:00
THE_FRAC -0.1415926535897931
2021-12-22 20:23:11 +01:00
"""
2022-01-22 21:59:15 +01:00
2021-04-26 20:07:00 +02:00
expected_stderr_2 = """
Statement failed, SQLSTATE = 42000
unsuccessful metadata update
-CREATE FUNCTION THE_FRAC failed
-Function THE_FRAC already exists
Statement failed, SQLSTATE = 39000
Dynamic SQL Error
-SQL error code = -804
-Function unknown
-THE_FRAC
Statement failed, SQLSTATE = 42000
unsuccessful metadata update
-CREATE FUNCTION THE_FRAC failed
-Function THE_FRAC already exists
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_stdout = expected_stdout_2
act_2.expected_stderr = expected_stderr_2
act_2.execute()
2022-01-22 21:59:15 +01:00
assert (act_2.clean_stderr == act_2.clean_expected_stderr and
act_2.clean_stdout == act_2.clean_expected_stdout)
2021-04-26 20:07:00 +02:00