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

View File

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

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_1;
drop function test_create_function_ex_2; 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";