6060
6161typedef struct remoteConn
6262{
63- PGconn * con ;/* Hold the remote connection */
64- bool remoteTrFlag ;/* Indicates whether or not a transaction
65- * on remote database is in progress */
63+ PGconn * conn ;/* Hold the remote connection */
64+ int autoXactCursors ;/* Indicates the number of open cursors,
65+ * non-zero means we opened the xact
66+ * ourselves */
6667}remoteConn ;
6768
6869/*
6970 * Internal declarations
7071 */
7172static remoteConn * getConnectionByName (const char * name );
7273static HTAB * createConnHash (void );
73- static void createNewConnection (const char * name ,remoteConn * con );
74+ static void createNewConnection (const char * name ,remoteConn * rconn );
7475static void deleteConnection (const char * name );
7576static char * * get_pkey_attnames (Oid relid ,int16 * numatts );
7677static char * get_sql_insert (Oid relid ,int2vector * pkattnums ,int16 pknumatts ,char * * src_pkattvals ,char * * tgt_pkattvals );
@@ -99,7 +100,7 @@ much like ecpg e.g. a mapping between a name and a PGconn object.
99100typedef struct remoteConnHashEnt
100101{
101102char name [NAMEDATALEN ];
102- remoteConn * rcon ;
103+ remoteConn * rconn ;
103104}remoteConnHashEnt ;
104105
105106/* initial number of connection hashes */
@@ -162,10 +163,10 @@ typedef struct remoteConnHashEnt
162163#define DBLINK_GET_CONN \
163164do { \
164165char *conname_or_str = GET_STR(PG_GETARG_TEXT_P(0)); \
165- rcon = getConnectionByName(conname_or_str); \
166- if(rcon ) \
166+ rconn = getConnectionByName(conname_or_str); \
167+ if(rconn ) \
167168{ \
168- conn =rcon->con ; \
169+ conn =rconn->conn ; \
169170} \
170171else \
171172{ \
@@ -197,7 +198,7 @@ dblink_connect(PG_FUNCTION_ARGS)
197198char * msg ;
198199MemoryContext oldcontext ;
199200PGconn * conn = NULL ;
200- remoteConn * rcon = NULL ;
201+ remoteConn * rconn = NULL ;
201202
202203if (PG_NARGS ()== 2 )
203204{
@@ -210,7 +211,7 @@ dblink_connect(PG_FUNCTION_ARGS)
210211oldcontext = MemoryContextSwitchTo (TopMemoryContext );
211212
212213if (connname )
213- rcon = (remoteConn * )palloc (sizeof (remoteConn ));
214+ rconn = (remoteConn * )palloc (sizeof (remoteConn ));
214215conn = PQconnectdb (connstr );
215216
216217MemoryContextSwitchTo (oldcontext );
@@ -219,8 +220,8 @@ dblink_connect(PG_FUNCTION_ARGS)
219220{
220221msg = pstrdup (PQerrorMessage (conn ));
221222PQfinish (conn );
222- if (rcon )
223- pfree (rcon );
223+ if (rconn )
224+ pfree (rconn );
224225
225226ereport (ERROR ,
226227 (errcode (ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION ),
@@ -230,8 +231,8 @@ dblink_connect(PG_FUNCTION_ARGS)
230231
231232if (connname )
232233{
233- rcon -> con = conn ;
234- createNewConnection (connname ,rcon );
234+ rconn -> conn = conn ;
235+ createNewConnection (connname ,rconn );
235236}
236237else
237238persistent_conn = conn ;
@@ -247,15 +248,15 @@ Datum
247248dblink_disconnect (PG_FUNCTION_ARGS )
248249{
249250char * conname = NULL ;
250- remoteConn * rcon = NULL ;
251+ remoteConn * rconn = NULL ;
251252PGconn * conn = NULL ;
252253
253254if (PG_NARGS ()== 1 )
254255{
255256conname = GET_STR (PG_GETARG_TEXT_P (0 ));
256- rcon = getConnectionByName (conname );
257- if (rcon )
258- conn = rcon -> con ;
257+ rconn = getConnectionByName (conname );
258+ if (rconn )
259+ conn = rconn -> conn ;
259260}
260261else
261262conn = persistent_conn ;
@@ -264,10 +265,10 @@ dblink_disconnect(PG_FUNCTION_ARGS)
264265DBLINK_CONN_NOT_AVAIL ;
265266
266267PQfinish (conn );
267- if (rcon )
268+ if (rconn )
268269{
269270deleteConnection (conname );
270- pfree (rcon );
271+ pfree (rconn );
271272}
272273else
273274persistent_conn = NULL ;
@@ -289,7 +290,7 @@ dblink_open(PG_FUNCTION_ARGS)
289290char * sql = NULL ;
290291char * conname = NULL ;
291292StringInfo str = makeStringInfo ();
292- remoteConn * rcon = NULL ;
293+ remoteConn * rconn = NULL ;
293294bool fail = true;/* default to backward compatible behavior */
294295
295296if (PG_NARGS ()== 2 )
@@ -314,9 +315,9 @@ dblink_open(PG_FUNCTION_ARGS)
314315conname = GET_STR (PG_GETARG_TEXT_P (0 ));
315316curname = GET_STR (PG_GETARG_TEXT_P (1 ));
316317sql = GET_STR (PG_GETARG_TEXT_P (2 ));
317- rcon = getConnectionByName (conname );
318- if (rcon )
319- conn = rcon -> con ;
318+ rconn = getConnectionByName (conname );
319+ if (rconn )
320+ conn = rconn -> conn ;
320321}
321322}
322323else if (PG_NARGS ()== 4 )
@@ -326,9 +327,9 @@ dblink_open(PG_FUNCTION_ARGS)
326327curname = GET_STR (PG_GETARG_TEXT_P (1 ));
327328sql = GET_STR (PG_GETARG_TEXT_P (2 ));
328329fail = PG_GETARG_BOOL (3 );
329- rcon = getConnectionByName (conname );
330- if (rcon )
331- conn = rcon -> con ;
330+ rconn = getConnectionByName (conname );
331+ if (rconn )
332+ conn = rconn -> conn ;
332333}
333334
334335if (!conn )
@@ -370,7 +371,7 @@ dblink_close(PG_FUNCTION_ARGS)
370371char * conname = NULL ;
371372StringInfo str = makeStringInfo ();
372373char * msg ;
373- remoteConn * rcon = NULL ;
374+ remoteConn * rconn = NULL ;
374375bool fail = true;/* default to backward compatible behavior */
375376
376377if (PG_NARGS ()== 1 )
@@ -392,9 +393,9 @@ dblink_close(PG_FUNCTION_ARGS)
392393{
393394conname = GET_STR (PG_GETARG_TEXT_P (0 ));
394395curname = GET_STR (PG_GETARG_TEXT_P (1 ));
395- rcon = getConnectionByName (conname );
396- if (rcon )
397- conn = rcon -> con ;
396+ rconn = getConnectionByName (conname );
397+ if (rconn )
398+ conn = rconn -> conn ;
398399}
399400}
400401if (PG_NARGS ()== 3 )
@@ -403,9 +404,9 @@ dblink_close(PG_FUNCTION_ARGS)
403404conname = GET_STR (PG_GETARG_TEXT_P (0 ));
404405curname = GET_STR (PG_GETARG_TEXT_P (1 ));
405406fail = PG_GETARG_BOOL (2 );
406- rcon = getConnectionByName (conname );
407- if (rcon )
408- conn = rcon -> con ;
407+ rconn = getConnectionByName (conname );
408+ if (rconn )
409+ conn = rconn -> conn ;
409410}
410411
411412if (!conn )
@@ -454,7 +455,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
454455PGresult * res = NULL ;
455456MemoryContext oldcontext ;
456457char * conname = NULL ;
457- remoteConn * rcon = NULL ;
458+ remoteConn * rconn = NULL ;
458459
459460/* stuff done only on the first call of the function */
460461if (SRF_IS_FIRSTCALL ())
@@ -473,9 +474,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
473474howmany = PG_GETARG_INT32 (2 );
474475fail = PG_GETARG_BOOL (3 );
475476
476- rcon = getConnectionByName (conname );
477- if (rcon )
478- conn = rcon -> con ;
477+ rconn = getConnectionByName (conname );
478+ if (rconn )
479+ conn = rconn -> conn ;
479480}
480481else if (PG_NARGS ()== 3 )
481482{
@@ -493,9 +494,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
493494curname = GET_STR (PG_GETARG_TEXT_P (1 ));
494495howmany = PG_GETARG_INT32 (2 );
495496
496- rcon = getConnectionByName (conname );
497- if (rcon )
498- conn = rcon -> con ;
497+ rconn = getConnectionByName (conname );
498+ if (rconn )
499+ conn = rconn -> conn ;
499500}
500501}
501502else if (PG_NARGS ()== 2 )
@@ -656,7 +657,7 @@ dblink_record(PG_FUNCTION_ARGS)
656657char * connstr = NULL ;
657658char * sql = NULL ;
658659char * conname = NULL ;
659- remoteConn * rcon = NULL ;
660+ remoteConn * rconn = NULL ;
660661bool fail = true;/* default to backward compatible */
661662
662663/* create a function context for cross-call persistence */
@@ -855,7 +856,7 @@ dblink_exec(PG_FUNCTION_ARGS)
855856char * connstr = NULL ;
856857char * sql = NULL ;
857858char * conname = NULL ;
858- remoteConn * rcon = NULL ;
859+ remoteConn * rconn = NULL ;
859860bool freeconn = false;
860861bool fail = true;/* default to backward compatible behavior */
861862
@@ -2027,7 +2028,7 @@ getConnectionByName(const char *name)
20272028key ,HASH_FIND ,NULL );
20282029
20292030if (hentry )
2030- return (hentry -> rcon );
2031+ return (hentry -> rconn );
20312032
20322033return (NULL );
20332034}
@@ -2063,7 +2064,7 @@ createNewConnection(const char *name, remoteConn *rconn)
20632064(errcode (ERRCODE_DUPLICATE_OBJECT ),
20642065errmsg ("duplicate connection name" )));
20652066
2066- hentry -> rcon = rconn ;
2067+ hentry -> rconn = rconn ;
20672068strncpy (hentry -> name ,name ,NAMEDATALEN - 1 );
20682069}
20692070