88 * Darko Prenosil <Darko.Prenosil@finteh.hr>
99 * Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
1010 *
11- * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.91 2010/02/26 02:00:32 momjian Exp $
11+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.92 2010/06/03 09:38:33 itagaki Exp $
1212 * Copyright (c) 2001-2010, PostgreSQL Global Development Group
1313 * ALL RIGHTS RESERVED;
1414 *
5454#include "nodes/nodes.h"
5555#include "nodes/pg_list.h"
5656#include "parser/parse_type.h"
57+ #include "parser/scansup.h"
5758#include "utils/acl.h"
5859#include "utils/array.h"
5960#include "utils/builtins.h"
@@ -2193,13 +2194,13 @@ static remoteConn *
21932194getConnectionByName (const char * name )
21942195{
21952196remoteConnHashEnt * hentry ;
2196- char key [ NAMEDATALEN ] ;
2197+ char * key ;
21972198
21982199if (!remoteConnHash )
21992200remoteConnHash = createConnHash ();
22002201
2201- MemSet ( key , 0 , NAMEDATALEN );
2202- snprintf (key ,NAMEDATALEN - 1 , "%s" , name );
2202+ key = pstrdup ( name );
2203+ truncate_identifier (key ,strlen ( key ), true );
22032204hentry = (remoteConnHashEnt * )hash_search (remoteConnHash ,
22042205key ,HASH_FIND ,NULL );
22052206
@@ -2225,13 +2226,13 @@ createNewConnection(const char *name, remoteConn *rconn)
22252226{
22262227remoteConnHashEnt * hentry ;
22272228bool found ;
2228- char key [ NAMEDATALEN ] ;
2229+ char * key ;
22292230
22302231if (!remoteConnHash )
22312232remoteConnHash = createConnHash ();
22322233
2233- MemSet ( key , 0 , NAMEDATALEN );
2234- snprintf (key ,NAMEDATALEN - 1 , "%s" , name );
2234+ key = pstrdup ( name );
2235+ truncate_identifier (key ,strlen ( key ), true );
22352236hentry = (remoteConnHashEnt * )hash_search (remoteConnHash ,key ,
22362237HASH_ENTER ,& found );
22372238
@@ -2249,14 +2250,13 @@ deleteConnection(const char *name)
22492250{
22502251remoteConnHashEnt * hentry ;
22512252bool found ;
2252- char key [ NAMEDATALEN ] ;
2253+ char * key ;
22532254
22542255if (!remoteConnHash )
22552256remoteConnHash = createConnHash ();
22562257
2257- MemSet (key ,0 ,NAMEDATALEN );
2258- snprintf (key ,NAMEDATALEN - 1 ,"%s" ,name );
2259-
2258+ key = pstrdup (name );
2259+ truncate_identifier (key ,strlen (key ), true);
22602260hentry = (remoteConnHashEnt * )hash_search (remoteConnHash ,
22612261key ,HASH_REMOVE ,& found );
22622262
@@ -2390,10 +2390,12 @@ get_connect_string(const char *servername)
23902390StringInfo buf = makeStringInfo ();
23912391ForeignDataWrapper * fdw ;
23922392AclResult aclresult ;
2393+ char * srvname ;
23932394
23942395/* first gather the server connstr options */
2395- if (strlen (servername )< NAMEDATALEN )
2396- foreign_server = GetForeignServerByName (servername , true);
2396+ srvname = pstrdup (servername );
2397+ truncate_identifier (srvname ,strlen (srvname ), true);
2398+ foreign_server = GetForeignServerByName (srvname , true);
23972399
23982400if (foreign_server )
23992401{