2021-04-26 20:07:00 +02:00
|
|
|
#coding:utf-8
|
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
"""
|
|
|
|
ID: issue-4807
|
|
|
|
ISSUE: 4807
|
|
|
|
TITLE: Maintain package body after ALTER/RECREATE PACKAGE
|
|
|
|
DESCRIPTION:
|
|
|
|
JIRA: CORE-4487
|
2022-02-02 15:46:19 +01:00
|
|
|
FBTEST: bugs.core_4487
|
2022-01-23 20:41:55 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
import pytest
|
|
|
|
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
|
|
|
test_script = """
|
2021-04-26 20:07:00 +02:00
|
|
|
create or alter view v_pg_meta as
|
2022-01-23 20:41:55 +01:00
|
|
|
select
|
2021-04-26 20:07:00 +02:00
|
|
|
rp.rdb$package_header_source hdr_source
|
|
|
|
,rp.rdb$package_body_source body_source
|
|
|
|
,rp.rdb$valid_body_flag body_valid
|
2022-01-23 20:41:55 +01:00
|
|
|
from rdb$packages rp
|
2021-04-26 20:07:00 +02:00
|
|
|
where rp.rdb$package_name = upper('pg_test');
|
2022-01-23 20:41:55 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set list on;
|
|
|
|
set blob all;
|
2022-01-23 20:41:55 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set term ^;
|
|
|
|
create or alter package pg_test
|
|
|
|
as
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint;
|
|
|
|
function fn_test_02 returns smallint;
|
|
|
|
end
|
|
|
|
^
|
2022-01-23 20:41:55 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
recreate package body pg_test
|
|
|
|
as
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint as
|
|
|
|
begin
|
|
|
|
return 1;
|
|
|
|
end
|
2022-01-23 20:41:55 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
function fn_test_02 returns smallint as
|
|
|
|
begin
|
|
|
|
return 2;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
|
|
|
-----------------------------------------
|
|
|
|
select 1 as step, v.* from v_pg_meta v;
|
|
|
|
------------------------------------------
|
2022-01-23 20:41:55 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set term ^;
|
|
|
|
create or alter package pg_test
|
|
|
|
as
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint;
|
|
|
|
function fn_test_02(a_val smallint) returns smallint;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
|
|
|
-----------------------------------------
|
|
|
|
set term ^;
|
|
|
|
create or alter package pg_test
|
|
|
|
as
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint;
|
|
|
|
-- Adding IN-argument to func must lead package body to invalid state:
|
|
|
|
function fn_test_02(a_val smallint) returns smallint;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
|
|
|
-----------------------------------------
|
|
|
|
select 2 as step, v.* from v_pg_meta v;
|
|
|
|
------------------------------------------
|
2022-01-23 20:41:55 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set term ^;
|
|
|
|
create or alter package pg_test
|
|
|
|
as
|
|
|
|
begin
|
|
|
|
function fn_test_03 returns bigint;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
|
|
|
-----------------------------------------
|
|
|
|
select 3 as step, v.* from v_pg_meta v;
|
|
|
|
------------------------------------------
|
2022-01-23 20:41:55 +01:00
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
set term ^;
|
|
|
|
create or alter package pg_test
|
|
|
|
as
|
|
|
|
begin
|
|
|
|
-- Restoring exactly the same singnatures of both functions
|
|
|
|
-- does NOT make package body to VALID state:
|
|
|
|
function fn_test_01 returns smallint;
|
|
|
|
function fn_test_02 returns smallint;
|
|
|
|
end
|
|
|
|
^
|
|
|
|
set term ;^
|
|
|
|
commit;
|
|
|
|
-----------------------------------------
|
|
|
|
select 4 as step, v.* from v_pg_meta v;
|
|
|
|
------------------------------------------
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
act = isql_act('db', test_script, substitutions=[('HDR_SOURCE.*', ''), ('BODY_SOURCE.*', '')])
|
2021-04-26 20:07:00 +02:00
|
|
|
|
2022-01-23 20:41:55 +01:00
|
|
|
expected_stdout = """
|
2021-04-26 20:07:00 +02:00
|
|
|
STEP 1
|
|
|
|
HDR_SOURCE 2a:1
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint;
|
|
|
|
function fn_test_02 returns smallint;
|
|
|
|
end
|
|
|
|
BODY_SOURCE 2a:4
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint as
|
|
|
|
begin
|
|
|
|
return 1;
|
|
|
|
end
|
|
|
|
function fn_test_02 returns smallint as
|
|
|
|
begin
|
|
|
|
return 2;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
BODY_VALID 1
|
2022-01-23 20:41:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
STEP 2
|
|
|
|
HDR_SOURCE 2a:1
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint;
|
|
|
|
-- Adding IN-argument to func must lead package body to invalid state:
|
|
|
|
function fn_test_02(a_val smallint) returns smallint;
|
|
|
|
end
|
|
|
|
BODY_SOURCE 2a:4
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint as
|
|
|
|
begin
|
|
|
|
return 1;
|
|
|
|
end
|
|
|
|
function fn_test_02 returns smallint as
|
|
|
|
begin
|
|
|
|
return 2;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
BODY_VALID 0
|
2022-01-23 20:41:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
STEP 3
|
|
|
|
HDR_SOURCE 2a:2
|
|
|
|
begin
|
|
|
|
function fn_test_03 returns bigint;
|
|
|
|
end
|
|
|
|
BODY_SOURCE 2a:4
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint as
|
|
|
|
begin
|
|
|
|
return 1;
|
|
|
|
end
|
|
|
|
function fn_test_02 returns smallint as
|
|
|
|
begin
|
|
|
|
return 2;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
BODY_VALID 0
|
2022-01-23 20:41:55 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
2021-04-26 20:07:00 +02:00
|
|
|
STEP 4
|
|
|
|
HDR_SOURCE 2a:1
|
|
|
|
begin
|
|
|
|
-- Restoring exactly the same singnatures of both functions
|
|
|
|
-- does NOT make package body to VALID state:
|
|
|
|
function fn_test_01 returns smallint;
|
|
|
|
function fn_test_02 returns smallint;
|
|
|
|
end
|
|
|
|
BODY_SOURCE 2a:4
|
|
|
|
begin
|
|
|
|
function fn_test_01 returns smallint as
|
|
|
|
begin
|
|
|
|
return 1;
|
|
|
|
end
|
|
|
|
function fn_test_02 returns smallint as
|
|
|
|
begin
|
|
|
|
return 2;
|
|
|
|
end
|
|
|
|
end
|
|
|
|
BODY_VALID 0
|
2021-12-22 20:23:11 +01:00
|
|
|
"""
|
2021-04-26 20:07:00 +02:00
|
|
|
|
|
|
|
@pytest.mark.version('>=3.0')
|
2022-01-23 20:41:55 +01:00
|
|
|
def test_1(act: Action):
|
|
|
|
act.expected_stdout = expected_stdout
|
|
|
|
act.execute()
|
|
|
|
assert act.clean_stdout == act.clean_expected_stdout
|
2021-04-26 20:07:00 +02:00
|
|
|
|