2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
2022-01-23 20:41:55 +01:00
|
|
|
|
|
|
|
"""
|
|
|
|
ID: issue-4498
|
|
|
|
ISSUE: 4498
|
|
|
|
TITLE: Creating external function (udf) to not existing dll - and then procedure with it - crash server
|
|
|
|
DESCRIPTION:
|
|
|
|
*** FOR FB 4.X AND ABOVE ***
|
|
|
|
Added separate code for running on FB 4.0.x: we use create UDR function statement and specify
|
|
|
|
non-existent library 'unknown_udf!UC_div'. The statement per se will pass and rdb$functions
|
|
|
|
*will* contain record for just created function. But following COMMT will raise exception:
|
|
|
|
Statement failed, SQLSTATE = HY000
|
|
|
|
UDR module not loaded
|
|
|
|
<localized message here>
|
|
|
|
Then we rollback and query rdb$functions again. No record about this function must be there.
|
|
|
|
|
|
|
|
STDERR is ignored in this test because of localized message about missed library.
|
|
|
|
JIRA: CORE-4172
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_4172
|
2022-01-23 20:41:55 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
import pytest
|
2021-11-18 20:15:37 +01:00
|
|
|
import re
|
|
|
|
from pathlib import Path
|
2022-01-23 20:41:55 +01:00
|
|
|
from firebird.qa import *
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
db = db_factory()
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
# version: 3.0
|
2021-11-18 20:15:37 +01:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
act_1 = python_act('db', substitutions=[('.* at offset.*', '.* at offset')])
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
expected_stdout_1 = """
|
|
|
|
X 1
|
2021-11-18 20:15:37 +01:00
|
|
|
"""
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
expected_stderr_1 = """
|
2021-12-22 20:23:11 +01:00
|
|
|
Rolling back work.
|
2021-04-26 20:07:00 +02:00
|
|
|
Statement failed, SQLSTATE = 39000
|
|
|
|
invalid request BLR at offset
|
|
|
|
-function DUMMY_EXT is not defined
|
|
|
|
-module name or entrypoint could not be found
|
2021-11-18 20:15:37 +01:00
|
|
|
"""
|
|
|
|
|
|
|
|
temp_db_1_a = temp_file('tmp_4172_1.fdb')
|
|
|
|
temp_db_1_b = temp_file('tmp_4172_2.fdb')
|
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0,<4')
|
|
|
|
def test_1(act_1: Action, temp_db_1_a: Path, temp_db_1_b: Path):
|
|
|
|
test_script = f"""
|
|
|
|
create database '{str(temp_db_1_b)}';
|
|
|
|
commit;
|
2021-12-19 22:25:36 +01:00
|
|
|
create database '{str(temp_db_1_a)}';
|
2021-11-18 20:15:37 +01:00
|
|
|
|
|
|
|
set autoddl off;
|
|
|
|
commit;
|
|
|
|
|
|
|
|
declare external function dummy_ext
|
|
|
|
integer
|
|
|
|
returns integer by value
|
|
|
|
entry_point 'dummy_ext'
|
|
|
|
module_name 'non_existing_udf.dll';
|
|
|
|
commit;
|
|
|
|
|
|
|
|
set term ^;
|
|
|
|
create procedure sp_test ( a_id integer ) returns ( o_name integer ) as
|
|
|
|
begin
|
|
|
|
o_name = dummy_ext(a_id);
|
|
|
|
suspend;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2021-11-18 20:15:37 +01:00
|
|
|
rollback;
|
|
|
|
|
|
|
|
connect '{str(temp_db_1_b)}';
|
|
|
|
set list on;
|
|
|
|
select 1 as x from rdb$database;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-11-18 20:15:37 +01:00
|
|
|
act_1.expected_stdout = expected_stdout_1
|
|
|
|
act_1.expected_stderr = expected_stderr_1
|
|
|
|
act_1.isql(switches=['-q'], input=test_script)
|
2022-01-23 20:41:55 +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
|
2021-11-18 20:15:37 +01:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
act_2 = python_act('db')
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
test_script_2 = """
|
2021-11-18 20:15:37 +01:00
|
|
|
recreate view v_check as
|
|
|
|
select rdb$function_name, rdb$entrypoint, rdb$engine_name, rdb$legacy_flag
|
|
|
|
from rdb$functions
|
|
|
|
where rdb$system_flag is distinct from 1 and rdb$function_name starting with upper( 'the_' )
|
|
|
|
;
|
|
|
|
commit;
|
|
|
|
|
|
|
|
set list on;
|
|
|
|
set term ^;
|
|
|
|
execute block returns( o_gdscode int ) as
|
|
|
|
begin
|
|
|
|
begin
|
|
|
|
execute statement
|
|
|
|
q'{
|
|
|
|
create function the_div (
|
|
|
|
n1 integer,
|
|
|
|
n2 integer
|
|
|
|
) returns double precision
|
|
|
|
external name 'unknown_udf!UC_div'
|
|
|
|
engine udr
|
|
|
|
}';
|
|
|
|
-- was: external name 'udf_compat!UC_div'
|
|
|
|
|
|
|
|
when any do
|
|
|
|
begin
|
|
|
|
o_gdscode = gdscode;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
suspend;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
|
|
|
|
commit;
|
|
|
|
|
|
|
|
set blob all;
|
|
|
|
set count on;
|
|
|
|
|
|
|
|
select * from v_check;
|
|
|
|
rollback;
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2021-11-18 20:15:37 +01:00
|
|
|
select * from v_check;
|
|
|
|
rollback;
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2022-01-23 20:41:55 +01:00
|
|
|
|
|
|
|
expected_stdout_2 = """
|
|
|
|
O_GDSCODE <null>
|
|
|
|
RDB$FUNCTION_NAME THE_DIV
|
|
|
|
RDB$ENTRYPOINT unknown_udf!UC_div
|
|
|
|
RDB$ENGINE_NAME UDR
|
|
|
|
RDB$LEGACY_FLAG 0
|
|
|
|
Records affected: 1
|
|
|
|
Records affected: 0
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
@pytest.mark.version('>=4.0')
|
|
|
|
def test_2(act_2: Action):
|
2021-11-18 20:15:37 +01:00
|
|
|
act_2.expected_stderr = 'We expect error, but ignore it'
|
|
|
|
act_2.expected_stdout = expected_stdout_2
|
2022-01-23 20:41:55 +01:00
|
|
|
act_2.isql(switches=[], input=test_script_2)
|
2021-11-18 20:15:37 +01:00
|
|
|
assert act_2.clean_stdout == act_2.clean_expected_stdout
|
2021-04-26 20:07:00 +02:00
|
|
|
|