public inbox for [email protected]  
help / color / mirror / Atom feed
From: Aleksander Alekseev <[email protected]>
To: PostgreSQL Hackers <[email protected]>
Subject: [PATCH] Little refactoring of portalcmds.c
Date: Wed, 8 Oct 2025 17:02:00 +0300
Message-ID: <CAJ7c6TOQq=R5MmrbkrGYdqTQEaaoEgMq-ZraXPjkdCJ60oJcaQ@mail.gmail.com> (raw)

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


Attachments:

  [text/x-patch] v1-0001-Refactor-portalcmds.c.patch (2.5K, 2-v1-0001-Refactor-portalcmds.c.patch)
  download | inline diff:
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



reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: [email protected]
  Cc: [email protected], [email protected]
  Subject: Re: [PATCH] Little refactoring of portalcmds.c
  In-Reply-To: <CAJ7c6TOQq=R5MmrbkrGYdqTQEaaoEgMq-ZraXPjkdCJ60oJcaQ@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by agora; see mirroring instructions
for how to clone and mirror all data and code used for this inbox