Hi, The proposed patch places some repetitive code in a helper function. The value of this change is arguably not that high but it makes the code a bit neater IMO.
-- Best regards, Aleksander Alekseev
From af051406d09dedf87bde8802d7f7dea0ab4458ec Mon Sep 17 00:00:00 2001 From: Aleksander Alekseev <[email protected]> Date: Wed, 8 Oct 2025 16:54:17 +0300 Subject: [PATCH v1] Refactor portalcmds.c Place some repetitive code in a helper function. Author: Aleksander Alekseev <[email protected]> Reviewed-by: TODO FIXME Discussion: TODO FIXME --- src/backend/commands/portalcmds.c | 40 +++++++++++++------------------ 1 file changed, 16 insertions(+), 24 deletions(-) diff --git a/src/backend/commands/portalcmds.c b/src/backend/commands/portalcmds.c index ec96c2efcd3..d74a01c01a3 100644 --- a/src/backend/commands/portalcmds.c +++ b/src/backend/commands/portalcmds.c @@ -36,6 +36,19 @@ #include "utils/memutils.h" #include "utils/snapmgr.h" +/* + * Check that cursor name is not empty, which would conflict with protocol-level + * unnamed portal. + */ +static void +check_cursor_name(const char *name) +{ + if (!name || name[0] == '\0') + ereport(ERROR, + (errcode(ERRCODE_INVALID_CURSOR_NAME), + errmsg("invalid cursor name: must not be empty"))); +} + /* * PerformCursorOpen @@ -53,14 +66,7 @@ PerformCursorOpen(ParseState *pstate, DeclareCursorStmt *cstmt, ParamListInfo pa MemoryContext oldContext; char *queryString; - /* - * Disallow empty-string cursor name (conflicts with protocol-level - * unnamed portal). - */ - if (!cstmt->portalname || cstmt->portalname[0] == '\0') - ereport(ERROR, - (errcode(ERRCODE_INVALID_CURSOR_NAME), - errmsg("invalid cursor name: must not be empty"))); + check_cursor_name(cstmt->portalname); /* * If this is a non-holdable cursor, we require that this statement has @@ -182,14 +188,7 @@ PerformPortalFetch(FetchStmt *stmt, Portal portal; uint64 nprocessed; - /* - * Disallow empty-string cursor name (conflicts with protocol-level - * unnamed portal). - */ - if (!stmt->portalname || stmt->portalname[0] == '\0') - ereport(ERROR, - (errcode(ERRCODE_INVALID_CURSOR_NAME), - errmsg("invalid cursor name: must not be empty"))); + check_cursor_name(stmt->portalname); /* get the portal from the portal name */ portal = GetPortalByName(stmt->portalname); @@ -233,14 +232,7 @@ PerformPortalClose(const char *name) return; } - /* - * Disallow empty-string cursor name (conflicts with protocol-level - * unnamed portal). - */ - if (name[0] == '\0') - ereport(ERROR, - (errcode(ERRCODE_INVALID_CURSOR_NAME), - errmsg("invalid cursor name: must not be empty"))); + check_cursor_name(name); /* * get the portal from the portal name -- 2.43.0
