From 472f2dc87e3e332bbdfb1d987af98c362fa870ee Mon Sep 17 00:00:00 2001 From: Itagaki Takahiro Date: Thu, 3 Jun 2010 09:43:04 +0000 Subject: [PATCH] Fix dblink to treat connection names longer than NAMEDATALEN-2 (62 bytes). Now long names are adjusted with truncate_identifier() and NOTICE messages are raised if names are actually truncated. Backported to release 8.0. --- contrib/dblink/dblink.c | 22 +++++++++++----------- 1 file changed, 11 insertions(+), 11 deletions(-) diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c index d46c2c51746..bbe40060a2f 100644 --- a/contrib/dblink/dblink.c +++ b/contrib/dblink/dblink.c @@ -8,7 +8,7 @@ * Darko Prenosil * Shridhar Daithankar * - * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.60.2.5 2010/02/03 23:01:47 joe Exp $ + * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.60.2.6 2010/06/03 09:43:04 itagaki Exp $ * Copyright (c) 2001-2006, PostgreSQL Global Development Group * ALL RIGHTS RESERVED; * @@ -50,6 +50,7 @@ #include "nodes/nodes.h" #include "nodes/pg_list.h" #include "parser/parse_type.h" +#include "parser/scansup.h" #include "tcop/tcopprot.h" #include "utils/array.h" #include "utils/builtins.h" @@ -2243,13 +2244,13 @@ static remoteConn * getConnectionByName(const char *name) { remoteConnHashEnt *hentry; - char key[NAMEDATALEN]; + char *key; if (!remoteConnHash) remoteConnHash = createConnHash(); - MemSet(key, 0, NAMEDATALEN); - snprintf(key, NAMEDATALEN - 1, "%s", name); + key = pstrdup(name); + truncate_identifier(key, strlen(key), true); hentry = (remoteConnHashEnt *) hash_search(remoteConnHash, key, HASH_FIND, NULL); @@ -2275,13 +2276,13 @@ createNewConnection(const char *name, remoteConn * rconn) { remoteConnHashEnt *hentry; bool found; - char key[NAMEDATALEN]; + char *key; if (!remoteConnHash) remoteConnHash = createConnHash(); - MemSet(key, 0, NAMEDATALEN); - snprintf(key, NAMEDATALEN - 1, "%s", name); + key = pstrdup(name); + truncate_identifier(key, strlen(key), true); hentry = (remoteConnHashEnt *) hash_search(remoteConnHash, key, HASH_ENTER, &found); @@ -2299,14 +2300,13 @@ deleteConnection(const char *name) { remoteConnHashEnt *hentry; bool found; - char key[NAMEDATALEN]; + char *key; if (!remoteConnHash) remoteConnHash = createConnHash(); - MemSet(key, 0, NAMEDATALEN); - snprintf(key, NAMEDATALEN - 1, "%s", name); - + key = pstrdup(name); + truncate_identifier(key, strlen(key), true); hentry = (remoteConnHashEnt *) hash_search(remoteConnHash, key, HASH_REMOVE, &found);