处理issue:创建package的时候,校验package内的函数schema与package的schema是否一致

This commit is contained in:
lukeman
2024-04-18 20:43:39 +08:00
committed by yaoxin
parent 78f318f955
commit 3dd0cdc569
3 changed files with 104 additions and 0 deletions

View File

@ -1080,6 +1080,13 @@ ObjectAddress CreateFunction(CreateFunctionStmt* stmt, const char* queryString,
if (HeapTupleIsValid(tuple)) {
Form_gs_package pkgform = (Form_gs_package)GETSTRUCT(tuple);
namespaceId = pkgform->pkgnamespace;
if (schemaname != NULL) {
Oid func_namespaceid = get_namespace_oid(schemaname, true);
if (namespaceId != func_namespaceid) {
ereport(ERROR, (errcode(ERRCODE_INVALID_SCHEMA_NAME),
errmsg("The namespace of functions or procedures within a package needs to be consistent with the package it belongs.")));
}
}
} else {
ereport(ERROR, (errcode(ERRCODE_UNDEFINED_PACKAGE), errmsg("package not found")));
}

View File

@ -2745,6 +2745,56 @@ end pck3;
/
create user package_user password 'gauss@123';
alter package pck3 owner to package_user;
-- test methods schema not consistent with object
create schema multi_schema_001;
-- failed
create or replace package public.multi_shema_package is
var1 int:=1; --公有变量
var2 int:=2;
procedure multi_schema_001.testpro1(var3 int); --公有存储过程,可以被外部调用
end multi_shema_package;
/
ERROR: The namespace of functions or procedures within a package needs to be consistent with the package it belongs.
-- failed
create or replace package multi_schema_001.multi_shema_package is
var1 int:=1; --公有变量
var2 int:=2;
procedure public.testpro1(var3 int); --公有存储过程,可以被外部调用
end multi_shema_package;
/
ERROR: The namespace of functions or procedures within a package needs to be consistent with the package it belongs.
-- succeed
create or replace package multi_schema_001.multi_shema_package is
var1 int:=1; --公有变量
var2 int:=2;
procedure multi_schema_001.testpro1(var3 int); --公有存储过程,可以被外部调用
end multi_shema_package;
/
-- failed
create or replace package body multi_schema_001.multi_shema_package is
var3 int:=3;
var4 int:=4;
procedure public.testpro1(var3 int)
is
begin
end;
end multi_shema_package;
/
ERROR: The namespace of functions or procedures within a package needs to be consistent with the package it belongs.
-- succeed
create or replace package body multi_schema_001.multi_shema_package is
var3 int:=3;
var4 int:=4;
procedure multi_schema_001.testpro1(var3 int)
is
begin
end;
end multi_shema_package;
/
-- clean
drop package multi_schema_001.multi_shema_package;
NOTICE: drop cascades to function multi_schema_001.testpro1(integer)
drop schema multi_schema_001;
drop package pck1;
NOTICE: drop cascades to function pkgsch059.f1(integer,test_tb)
drop package pck2;

View File

@ -2303,6 +2303,53 @@ end pck3;
create user package_user password 'gauss@123';
alter package pck3 owner to package_user;
-- test methods schema not consistent with object
create schema multi_schema_001;
-- failed
create or replace package public.multi_shema_package is
var1 int:=1; --
var2 int:=2;
procedure multi_schema_001.testpro1(var3 int); --
end multi_shema_package;
/
-- failed
create or replace package multi_schema_001.multi_shema_package is
var1 int:=1; --
var2 int:=2;
procedure public.testpro1(var3 int); --
end multi_shema_package;
/
-- succeed
create or replace package multi_schema_001.multi_shema_package is
var1 int:=1; --
var2 int:=2;
procedure multi_schema_001.testpro1(var3 int); --
end multi_shema_package;
/
-- failed
create or replace package body multi_schema_001.multi_shema_package is
var3 int:=3;
var4 int:=4;
procedure public.testpro1(var3 int)
is
begin
end;
end multi_shema_package;
/
-- succeed
create or replace package body multi_schema_001.multi_shema_package is
var3 int:=3;
var4 int:=4;
procedure multi_schema_001.testpro1(var3 int)
is
begin
end;
end multi_shema_package;
/
-- clean
drop package multi_schema_001.multi_shema_package;
drop schema multi_schema_001;
drop package pck1;
drop package pck2;
drop package pck3;