From 81624db39aa7501690aab71a68af689df78b71e8 Mon Sep 17 00:00:00 2001
From: Michael Meskes <meskes@postgresql.org>
Date: Fri, 10 Sep 2010 10:13:20 +0000
Subject: [PATCH] Cursor names in the backend are not case-sensitve. This
 change makes sure that ecpg also does not regard cursor names as
 case-sensitive.

Thanks to Zoltan Boszormenyi for the patch.
---
 src/interfaces/ecpg/preproc/ecpg.addons  | 5 +++--
 src/interfaces/ecpg/preproc/ecpg.header  | 5 +++--
 src/interfaces/ecpg/preproc/ecpg.trailer | 5 +++--
 3 files changed, 9 insertions(+), 6 deletions(-)

diff --git a/src/interfaces/ecpg/preproc/ecpg.addons b/src/interfaces/ecpg/preproc/ecpg.addons
index a6760d4b913..af708ab019a 100644
--- a/src/interfaces/ecpg/preproc/ecpg.addons
+++ b/src/interfaces/ecpg/preproc/ecpg.addons
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.19 2010/03/31 08:45:18 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.addons,v 1.20 2010/09/10 10:13:20 meskes Exp $ */
 ECPG: stmtClosePortalStmt block
 	{
 		if (INFORMIX_MODE)
@@ -302,10 +302,11 @@ ECPG: DeclareCursorStmtDECLAREcursor_namecursor_optionsCURSORopt_holdFORSelectSt
 		struct cursor *ptr, *this;
 		char *cursor_marker = $2[0] == ':' ? make_str("$0") : mm_strdup($2);
 		char *comment, *c1, *c2;
+		int (* strcmp_fn)(const char *, const char *) = ($2[0] == ':' ? strcmp : pg_strcasecmp);
 
 		for (ptr = cur; ptr != NULL; ptr = ptr->next)
 		{
-			if (strcmp($2, ptr->name) == 0)
+			if (strcmp_fn($2, ptr->name) == 0)
 			{
 				if ($2[0] == ':')
                                         mmerror(PARSE_ERROR, ET_ERROR, "using variable \"%s\" in different declare statements is not supported", $2+1);
diff --git a/src/interfaces/ecpg/preproc/ecpg.header b/src/interfaces/ecpg/preproc/ecpg.header
index 3398f004cf4..3e8219efaf0 100644
--- a/src/interfaces/ecpg/preproc/ecpg.header
+++ b/src/interfaces/ecpg/preproc/ecpg.header
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.header,v 1.16 2010/05/25 14:32:55 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.header,v 1.17 2010/09/10 10:13:20 meskes Exp $ */
 
 /* Copyright comment */
 %{
@@ -386,10 +386,11 @@ add_additional_variables(char *name, bool insert)
 {
 	struct cursor *ptr;
 	struct arguments *p;
+	int (* strcmp_fn)(const char *, const char *) = (name[0] == ':' ? strcmp : pg_strcasecmp);
 
 	for (ptr = cur; ptr != NULL; ptr=ptr->next)
 	{
-		if (strcmp(ptr->name, name) == 0)
+		if (strcmp_fn(ptr->name, name) == 0)
 			break;
 	}
 
diff --git a/src/interfaces/ecpg/preproc/ecpg.trailer b/src/interfaces/ecpg/preproc/ecpg.trailer
index 59fc26c0ddc..2b99b4e4cf9 100644
--- a/src/interfaces/ecpg/preproc/ecpg.trailer
+++ b/src/interfaces/ecpg/preproc/ecpg.trailer
@@ -1,4 +1,4 @@
-/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.26 2010/05/25 17:28:20 meskes Exp $ */
+/* $PostgreSQL: pgsql/src/interfaces/ecpg/preproc/ecpg.trailer,v 1.27 2010/09/10 10:13:20 meskes Exp $ */
 
 statements: /*EMPTY*/
                 | statements statement
@@ -289,13 +289,14 @@ ECPGCursorStmt:  DECLARE cursor_name cursor_options CURSOR opt_hold FOR prepared
 		{
 			struct cursor *ptr, *this;
 			char *cursor_marker = $2[0] == ':' ? make_str("$0") : mm_strdup($2);
+			int (* strcmp_fn)(const char *, const char *) = ($2[0] == ':' ? strcmp : pg_strcasecmp);
 			struct variable *thisquery = (struct variable *)mm_alloc(sizeof(struct variable));
 			const char *con = connection ? connection : "NULL";
 			char *comment;
 
 			for (ptr = cur; ptr != NULL; ptr = ptr->next)
 			{
-				if (strcmp($2, ptr->name) == 0)
+				if (strcmp_fn($2, ptr->name) == 0)
 				{
 					/* re-definition is a bug */
 					if ($2[0] == ':')
-- 
GitLab