Skip to content

Commit f3576c3

Browse files
committed
Cosmetic changes to dblink.
1 parent 7d937cd commit f3576c3

File tree

1 file changed

+46
-45
lines changed

1 file changed

+46
-45
lines changed

contrib/dblink/dblink.c

Lines changed: 46 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,18 @@
6060

6161
typedef 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
*/
7172
static remoteConn *getConnectionByName(const char *name);
7273
static HTAB *createConnHash(void);
73-
static void createNewConnection(const char *name, remoteConn * con);
74+
static void createNewConnection(const char *name, remoteConn *rconn);
7475
static void deleteConnection(const char *name);
7576
static char **get_pkey_attnames(Oid relid, int16 *numatts);
7677
static 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.
99100
typedef struct remoteConnHashEnt
100101
{
101102
char 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 \
163164
do { \
164165
char *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
} \
170171
else \
171172
{ \
@@ -197,7 +198,7 @@ dblink_connect(PG_FUNCTION_ARGS)
197198
char *msg;
198199
MemoryContext oldcontext;
199200
PGconn *conn = NULL;
200-
remoteConn *rcon = NULL;
201+
remoteConn *rconn = NULL;
201202

202203
if (PG_NARGS() == 2)
203204
{
@@ -210,7 +211,7 @@ dblink_connect(PG_FUNCTION_ARGS)
210211
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
211212

212213
if (connname)
213-
rcon = (remoteConn *) palloc(sizeof(remoteConn));
214+
rconn = (remoteConn *) palloc(sizeof(remoteConn));
214215
conn = PQconnectdb(connstr);
215216

216217
MemoryContextSwitchTo(oldcontext);
@@ -219,8 +220,8 @@ dblink_connect(PG_FUNCTION_ARGS)
219220
{
220221
msg = pstrdup(PQerrorMessage(conn));
221222
PQfinish(conn);
222-
if (rcon)
223-
pfree(rcon);
223+
if (rconn)
224+
pfree(rconn);
224225

225226
ereport(ERROR,
226227
(errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
@@ -230,8 +231,8 @@ dblink_connect(PG_FUNCTION_ARGS)
230231

231232
if (connname)
232233
{
233-
rcon->con = conn;
234-
createNewConnection(connname, rcon);
234+
rconn->conn = conn;
235+
createNewConnection(connname, rconn);
235236
}
236237
else
237238
persistent_conn = conn;
@@ -247,15 +248,15 @@ Datum
247248
dblink_disconnect(PG_FUNCTION_ARGS)
248249
{
249250
char *conname = NULL;
250-
remoteConn *rcon = NULL;
251+
remoteConn *rconn = NULL;
251252
PGconn *conn = NULL;
252253

253254
if (PG_NARGS() == 1)
254255
{
255256
conname = 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
}
260261
else
261262
conn = persistent_conn;
@@ -264,10 +265,10 @@ dblink_disconnect(PG_FUNCTION_ARGS)
264265
DBLINK_CONN_NOT_AVAIL;
265266

266267
PQfinish(conn);
267-
if (rcon)
268+
if (rconn)
268269
{
269270
deleteConnection(conname);
270-
pfree(rcon);
271+
pfree(rconn);
271272
}
272273
else
273274
persistent_conn = NULL;
@@ -289,7 +290,7 @@ dblink_open(PG_FUNCTION_ARGS)
289290
char *sql = NULL;
290291
char *conname = NULL;
291292
StringInfo str = makeStringInfo();
292-
remoteConn *rcon = NULL;
293+
remoteConn *rconn = NULL;
293294
bool fail = true; /* default to backward compatible behavior */
294295

295296
if (PG_NARGS() == 2)
@@ -314,9 +315,9 @@ dblink_open(PG_FUNCTION_ARGS)
314315
conname = GET_STR(PG_GETARG_TEXT_P(0));
315316
curname = GET_STR(PG_GETARG_TEXT_P(1));
316317
sql = 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
}
322323
else if (PG_NARGS() == 4)
@@ -326,9 +327,9 @@ dblink_open(PG_FUNCTION_ARGS)
326327
curname = GET_STR(PG_GETARG_TEXT_P(1));
327328
sql = GET_STR(PG_GETARG_TEXT_P(2));
328329
fail = 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

334335
if (!conn)
@@ -370,7 +371,7 @@ dblink_close(PG_FUNCTION_ARGS)
370371
char *conname = NULL;
371372
StringInfo str = makeStringInfo();
372373
char *msg;
373-
remoteConn *rcon = NULL;
374+
remoteConn *rconn = NULL;
374375
bool fail = true; /* default to backward compatible behavior */
375376

376377
if (PG_NARGS() == 1)
@@ -392,9 +393,9 @@ dblink_close(PG_FUNCTION_ARGS)
392393
{
393394
conname = GET_STR(PG_GETARG_TEXT_P(0));
394395
curname = 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
}
400401
if (PG_NARGS() == 3)
@@ -403,9 +404,9 @@ dblink_close(PG_FUNCTION_ARGS)
403404
conname = GET_STR(PG_GETARG_TEXT_P(0));
404405
curname = GET_STR(PG_GETARG_TEXT_P(1));
405406
fail = 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

411412
if (!conn)
@@ -454,7 +455,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
454455
PGresult *res = NULL;
455456
MemoryContext oldcontext;
456457
char *conname = NULL;
457-
remoteConn *rcon = NULL;
458+
remoteConn *rconn = NULL;
458459

459460
/* stuff done only on the first call of the function */
460461
if (SRF_IS_FIRSTCALL())
@@ -473,9 +474,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
473474
howmany = PG_GETARG_INT32(2);
474475
fail = 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
}
480481
else if (PG_NARGS() == 3)
481482
{
@@ -493,9 +494,9 @@ dblink_fetch(PG_FUNCTION_ARGS)
493494
curname = GET_STR(PG_GETARG_TEXT_P(1));
494495
howmany = 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
}
501502
else if (PG_NARGS() == 2)
@@ -656,7 +657,7 @@ dblink_record(PG_FUNCTION_ARGS)
656657
char *connstr = NULL;
657658
char *sql = NULL;
658659
char *conname = NULL;
659-
remoteConn *rcon = NULL;
660+
remoteConn *rconn = NULL;
660661
bool 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)
855856
char *connstr = NULL;
856857
char *sql = NULL;
857858
char *conname = NULL;
858-
remoteConn *rcon = NULL;
859+
remoteConn *rconn = NULL;
859860
bool freeconn = false;
860861
bool fail = true; /* default to backward compatible behavior */
861862

@@ -2027,7 +2028,7 @@ getConnectionByName(const char *name)
20272028
key, HASH_FIND, NULL);
20282029

20292030
if (hentry)
2030-
return (hentry->rcon);
2031+
return (hentry->rconn);
20312032

20322033
return (NULL);
20332034
}
@@ -2063,7 +2064,7 @@ createNewConnection(const char *name, remoteConn *rconn)
20632064
(errcode(ERRCODE_DUPLICATE_OBJECT),
20642065
errmsg("duplicate connection name")));
20652066

2066-
hentry->rcon = rconn;
2067+
hentry->rconn = rconn;
20672068
strncpy(hentry->name, name, NAMEDATALEN - 1);
20682069
}
20692070

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy