【标题】:修复创建package同时存在不同参数mode的同名重载proc和func,创建成功,但pg_proc中仅一条记录的问题

【实现内容】: 修复创建package同时存在不同参数mode的同名重载proc和func,创建成功,但pg_proc中仅一条记录的问题.
【根因分析】: 此场景下之前没报错,当前直接报错处理.
【实现方案】: 此场景下直接报错处理
【关联需求或issue】: https://e.gitee.com/opengaussorg/dashboard?issue=IAROUT
This commit is contained in:
wangfeihuo
2024-11-25 10:27:24 +08:00
parent 107b582554
commit 5fd2674dcf
3 changed files with 64 additions and 2 deletions

View File

@ -1831,6 +1831,7 @@ bool isSameArgList(CreateFunctionStmt* stmt1, CreateFunctionStmt* stmt2)
int inLoc1 = 0;
int inLoc2 = 0;
int length = 0;
int sameParamtypNum = 0;
foreach(cell, argList1) {
arr1[length] = (FunctionParameter*)lfirst(cell);
if (arr1[length]->mode != FUNC_PARAM_OUT) {
@ -1956,7 +1957,21 @@ bool isSameArgList(CreateFunctionStmt* stmt1, CreateFunctionStmt* stmt2)
pfree(arr2);
return false;
}
} else if (toid1 != toid2 || fp1->mode != fp2->mode) {
}
if (toid1 != toid2) {
pfree(arr1);
pfree(arr2);
return false;
}
if ((stmt1->isProcedure || stmt2->isProcedure) && (fp1->mode != fp2->mode)) {
if (enable_outparam_override && length1 == length2) {
sameParamtypNum += 1;
} else {
pfree(arr1);
pfree(arr2);
return false;
}
} else if (stmt1->isFunctionDeclare != stmt2->isFunctionDeclare && fp1->mode != fp2->mode) {
pfree(arr1);
pfree(arr2);
return false;
@ -1978,6 +1993,16 @@ bool isSameArgList(CreateFunctionStmt* stmt1, CreateFunctionStmt* stmt2)
}
pfree(arr1);
pfree(arr2);
if (enable_outparam_override && length1 == length2 && sameParamtypNum == length1 && sameParamtypNum != 0) {
ereport(ERROR,
(errcode(ERRCODE_UNDEFINED_FUNCTION),
errmodule(MOD_PLSQL),
errmsg("can not override param:%s", NameListToString(stmt1->funcname)),
errcause("param's length is unequal."),
erraction("please check the param's length.")));
}
/* function delcare in package specification and define in package body must be same */
if (!isSameName && (stmt1->isFunctionDeclare^stmt2->isFunctionDeclare)) {
ereport(ERROR,

View File

@ -953,6 +953,27 @@ call test_function2('','');
<unnamed portal 2> | <unnamed portal 1> | <unnamed portal 2>
(1 row)
set behavior_compat_options = 'proc_outparam_override';
create or replace package pck2 is
FUNCTION pkg_mem_case(a int,self1 int) RETURN VARCHAR2;
procedure pkg_mem_case(a int,self1 inout int);
end pck2;
/
ERROR: function declared in package specification and package body must be the same, function: pkg_mem_case
set behavior_compat_options = '';
create or replace package pck2 is
FUNCTION pkg_mem_case(a int,self1 int) RETURN VARCHAR2;
procedure pkg_mem_case(a int,self1 inout int);
end pck2;
/
select count(*) from pg_proc where proname = 'pkg_mem_case';
count
-------
1
(1 row)
drop package pck2;
NOTICE: drop cascades to function plpgsql_override_out.pkg_mem_case(integer,integer)
set plsql_compile_check_options='';
drop package body if exists pck1;
drop package body pck1;
@ -979,7 +1000,7 @@ drop cascades to function f1(integer)
drop cascades to function f3()
drop cascades to function pro2()
drop cascades to function plpgsql_override_out.p11()
drop cascades to function p11()
--?.*
drop cascades to function plpgsql_override_out.p11()
drop cascades to function p11(integer)
drop cascades to table test_table2

View File

@ -710,6 +710,22 @@ $$
LANGUAGE 'plpgsql';
call test_function2('','');
set behavior_compat_options = 'proc_outparam_override';
create or replace package pck2 is
FUNCTION pkg_mem_case(a int,self1 int) RETURN VARCHAR2;
procedure pkg_mem_case(a int,self1 inout int);
end pck2;
/
set behavior_compat_options = '';
create or replace package pck2 is
FUNCTION pkg_mem_case(a int,self1 int) RETURN VARCHAR2;
procedure pkg_mem_case(a int,self1 inout int);
end pck2;
/
select count(*) from pg_proc where proname = 'pkg_mem_case';
drop package pck2;
set plsql_compile_check_options='';
drop package body if exists pck1;
drop package body pck1;