!5006 修复存储过程或函数对象名中,含有奇数个单引号时,创建失败的问题

Merge pull request !5006 from yuchao/master
This commit is contained in:
opengauss_bot
2024-03-22 12:18:24 +00:00
committed by Gitee
6 changed files with 52 additions and 20 deletions

View File

@ -7917,7 +7917,7 @@ static bool IsDefaultSlice(StringInfo buf, RangePartitionDefState* sliceDef)
}
}
static char* EscapeQuotes(const char* src)
char* EscapeQuotes(const char* src)
{
int len = strlen(src), i, j;
char* result = (char*)palloc(len * 2 + 1);

View File

@ -178,6 +178,7 @@ void InsertGsSource(Oid objId, Oid nspid, const char* name, const char* type, bo
}
/* Execute autonomous transaction call for logging purpose */
StringInfoData str;
char* tmp = EscapeQuotes(name);
initStringInfo(&str);
appendStringInfoString(&str,
"declare\n"
@ -188,7 +189,7 @@ void InsertGsSource(Oid objId, Oid nspid, const char* name, const char* type, bo
"begin\n ");
appendStringInfo(&str,
"select count(*) from dbe_pldeveloper.gs_source into allNum where "
"nspid=%u and name=\'%s\' and type=\'%s\';", nspid, name, type);
"nspid=%u and name=\'%s\' and type=\'%s\';", nspid, tmp, type);
appendStringInfo(&str,
"if allNum > 0 then "
"select id from dbe_pldeveloper.gs_source into oldId where "
@ -196,38 +197,39 @@ void InsertGsSource(Oid objId, Oid nspid, const char* name, const char* type, bo
"objId := oldId; "
"else "
"objId := %u;"
"end if;", nspid, name, type, objId);
"end if;", nspid, tmp, type, objId);
appendStringInfo(&str,
"delete from DBE_PLDEVELOPER.gs_source where nspid=%u and name=\'%s\' and type = \'%s\';\n",
nspid, name, type);
nspid, tmp, type);
appendStringInfo(&str,
"delete from DBE_PLDEVELOPER.gs_source where nspid=%u and name=\'%s\' and type = \'%s\';\n",
nspid, name, type);
nspid, tmp, type);
if (!u_sess->attr.attr_common.plsql_show_all_error || status) {
appendStringInfo(&str,
"delete from DBE_PLDEVELOPER.gs_errors where "
"nspid=%u and name=\'%s\' and type = \'%s\';\n",
nspid, name, type);
nspid, tmp, type);
if (!strcmp(type, "package")) {
appendStringInfo(&str,
"delete from DBE_PLDEVELOPER.gs_errors where "
"nspid=%u and name=\'%s\' and type = \'package body\';\n",
nspid, name);
nspid, tmp);
}
}
if (status && !strcmp(type, "package")) {
appendStringInfo(&str,
"delete from DBE_PLDEVELOPER.gs_source where "
"nspid=%u and name=\'%s\' and type = \'package body\';\n",
nspid, name);
nspid, tmp);
}
appendStringInfo(&str,
"insert into DBE_PLDEVELOPER.gs_source values(objId, %u, %u,\'%s\', \'%s\', \'%c\', $gssource$%s$gssource$);\n",
userId, nspid, name, type, statusChr, source);
userId, nspid, tmp, type, statusChr, source);
appendStringInfoString(&str,
"EXCEPTION WHEN OTHERS THEN NULL; \n");
appendStringInfoString(&str, "end;");
List* rawParseList = raw_parser(str.data);
pfree_ext(tmp);
pfree_ext(str.data);
DoStmt* stmt = (DoStmt *)linitial(rawParseList);
int save_compile_status = getCompileStatus();

View File

@ -1477,6 +1477,7 @@ void InsertError(Oid objId)
ReleaseSysCache(tuple);
}
StringInfoData ds;
char* tmp = EscapeQuotes(name);
initStringInfo(&ds);
appendStringInfoString(&ds,
"declare\n"
@ -1487,7 +1488,7 @@ void InsertError(Oid objId)
"begin\n ");
appendStringInfo(&ds,
"select count(*) from dbe_pldeveloper.gs_source into allNum where "
"nspid=%u and name=\'%s\' and type=\'%s\';", nspid, name, type);
"nspid=%u and name=\'%s\' and type=\'%s\';", nspid, tmp, type);
appendStringInfo(&ds,
"if allNum > 0 then "
"select id from dbe_pldeveloper.gs_source into oldId where "
@ -1495,10 +1496,10 @@ void InsertError(Oid objId)
"objId := oldId; "
"else "
"objId := %u;"
"end if;", nspid, name, type, objId);
"end if;", nspid, tmp, type, objId);
appendStringInfo(&ds,
"delete from DBE_PLDEVELOPER.gs_errors where nspid=%u and name=\'%s\' and type = \'%s\';\n",
nspid, name, type);
nspid, tmp, type);
char* errmsg = NULL;
int line = 0;
if (rc != PLPGSQL_COMPILE_NULL) {
@ -1509,7 +1510,7 @@ void InsertError(Oid objId)
line = item->line;
appendStringInfoString(&ds, "insert into DBE_PLDEVELOPER.gs_errors ");
appendStringInfo(&ds, "values(objId,%u,%u,\'%s\',\'%s\',%d,$gserrors$%s$gserrors$);\n",
userId, nspid, name, type, line, errmsg);
userId, nspid, tmp, type, line, errmsg);
}
}
appendStringInfo(&ds, "end;");
@ -1550,6 +1551,7 @@ void InsertError(Oid objId)
MemoryContextSwitchTo(temp);
}
u_sess->plsql_cxt.insertError = false;
pfree_ext(tmp);
pfree_ext(ds.data);
list_free_deep(u_sess->plsql_cxt.errorList);
u_sess->plsql_cxt.errorList = NULL;
@ -1616,28 +1618,29 @@ void DropErrorByOid(int objtype, Oid objoid)
ReleaseSysCache(tuple);
}
StringInfoData ds;
char* tmp = EscapeQuotes(name);
initStringInfo(&ds);
appendStringInfoString(&ds, " declare begin ");
if (objtype == PLPGSQL_PACKAGE_BODY) {
appendStringInfo(&ds, " delete from DBE_PLDEVELOPER.gs_errors "
"where nspid=%u and name = \'%s\' and type = \'%s\';",
nspid, name, type);
nspid, tmp, type);
appendStringInfo(&ds, " delete from DBE_PLDEVELOPER.gs_source where "
"nspid=%u and name = \'%s\' and type = \'%s\';",
nspid, name, type);
nspid, tmp, type);
} else {
appendStringInfo(&ds, " delete from DBE_PLDEVELOPER.gs_errors "
"where nspid=%u and name = \'%s\' and type = \'%s\';",
nspid, name, type);
nspid, tmp, type);
appendStringInfo(&ds, " delete from DBE_PLDEVELOPER.gs_errors "
"where nspid=%u and name = \'%s\' and type = \'package body\';",
nspid, name);
nspid, tmp);
appendStringInfo(&ds, " delete from DBE_PLDEVELOPER.gs_source where "
"nspid=%u and name = \'%s\' and type = \'%s\';",
nspid, name, type);
nspid, tmp, type);
appendStringInfo(&ds, " delete from DBE_PLDEVELOPER.gs_source where "
"nspid=%u and name = \'%s\' and type = \'package body\';",
nspid, name);
nspid, tmp);
}
appendStringInfo(&ds, " EXCEPTION WHEN OTHERS THEN NULL; \n");
appendStringInfo(&ds, " END; ");
@ -1672,6 +1675,7 @@ void DropErrorByOid(int objtype, Oid objoid)
if (temp != NULL) {
MemoryContextSwitchTo(temp);
}
pfree_ext(tmp);
pfree_ext(ds.data);
#endif
}

View File

@ -43,5 +43,6 @@ extern char** get_next_snippet(
char** query_string_single, const char* query_string, List* query_string_locationlist, int* stmt_num);
extern void fixResTargetNameWithAlias(List* clause_list, const char* aliasname);
extern char* EscapeQuotes(const char* src);
#endif /* PARSER_H */

View File

@ -126,3 +126,15 @@ select test_create_function_ex_3('111.222');
drop function test_create_function_ex_1;
drop function test_create_function_ex_2;
drop function test_create_function_ex_3;
create or replace procedure "p_'''_1"() is
begin
null;
end;
/
drop procedure "p_'''_1";
create or replace function "p_'''_1"() return void
as
begin
null;
end;
drop function "p_'''_1";

View File

@ -112,4 +112,17 @@ select test_create_function_ex_3('111.222');
drop function test_create_function_ex_1;
drop function test_create_function_ex_2;
drop function test_create_function_ex_3;
drop function test_create_function_ex_3;
create or replace procedure "p_'''_1"() is
begin
null;
end;
/
drop procedure "p_'''_1";
create or replace function "p_'''_1"() return void
as
begin
null;
end;
drop function "p_'''_1";