From 5742a12780391fea2ebdf46a6a8715fbe2ca44e7 Mon Sep 17 00:00:00 2001 From: yuchao Date: Thu, 21 Mar 2024 11:58:28 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=AD=98=E5=82=A8=E8=BF=87?= =?UTF-8?q?=E7=A8=8B=E6=88=96=E5=87=BD=E6=95=B0=E5=AF=B9=E8=B1=A1=E5=90=8D?= =?UTF-8?q?=E4=B8=AD=EF=BC=8C=E5=90=AB=E6=9C=89=E5=A5=87=E6=95=B0=E4=B8=AA?= =?UTF-8?q?=E5=8D=95=E5=BC=95=E5=8F=B7=E6=97=B6=EF=BC=8C=E5=88=9B=E5=BB=BA?= =?UTF-8?q?=E5=A4=B1=E8=B4=A5=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/backend/utils/adt/ruleutils.cpp | 2 +- src/common/pl/plpgsql/src/pl_handler.cpp | 18 +++++++------- src/common/pl/plpgsql/src/pl_package.cpp | 24 +++++++++++-------- src/include/parser/parser.h | 1 + src/test/regress/expected/create_function.out | 12 ++++++++++ src/test/regress/sql/create_function.sql | 15 +++++++++++- 6 files changed, 52 insertions(+), 20 deletions(-) diff --git a/src/common/backend/utils/adt/ruleutils.cpp b/src/common/backend/utils/adt/ruleutils.cpp index 852e0dc56..e90fe06cf 100644 --- a/src/common/backend/utils/adt/ruleutils.cpp +++ b/src/common/backend/utils/adt/ruleutils.cpp @@ -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); diff --git a/src/common/pl/plpgsql/src/pl_handler.cpp b/src/common/pl/plpgsql/src/pl_handler.cpp index 48d2215ee..88898a4de 100755 --- a/src/common/pl/plpgsql/src/pl_handler.cpp +++ b/src/common/pl/plpgsql/src/pl_handler.cpp @@ -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(); diff --git a/src/common/pl/plpgsql/src/pl_package.cpp b/src/common/pl/plpgsql/src/pl_package.cpp index 238d88259..cd5772fff 100644 --- a/src/common/pl/plpgsql/src/pl_package.cpp +++ b/src/common/pl/plpgsql/src/pl_package.cpp @@ -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 } diff --git a/src/include/parser/parser.h b/src/include/parser/parser.h index 397b7289f..db2a74cda 100644 --- a/src/include/parser/parser.h +++ b/src/include/parser/parser.h @@ -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 */ diff --git a/src/test/regress/expected/create_function.out b/src/test/regress/expected/create_function.out index 45118200b..92caf056c 100644 --- a/src/test/regress/expected/create_function.out +++ b/src/test/regress/expected/create_function.out @@ -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"; diff --git a/src/test/regress/sql/create_function.sql b/src/test/regress/sql/create_function.sql index fed8f20bf..081e63247 100644 --- a/src/test/regress/sql/create_function.sql +++ b/src/test/regress/sql/create_function.sql @@ -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; \ No newline at end of file +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";