typedef struct remoteConn
{
- PGconn *con; /* Hold the remote connection */
- bool remoteTrFlag; /* Indicates whether or not a transaction
- * on remote database is in progress */
+ PGconn *conn; /* Hold the remote connection */
+ int autoXactCursors; /* Indicates the number of open cursors,
+ * non-zero means we opened the xact
+ * ourselves */
} remoteConn;
/*
*/
static remoteConn *getConnectionByName(const char *name);
static HTAB *createConnHash(void);
-static void createNewConnection(const char *name, remoteConn * con);
+static void createNewConnection(const char *name, remoteConn *rconn);
static void deleteConnection(const char *name);
static char **get_pkey_attnames(Oid relid, int16 *numatts);
static char *get_sql_insert(Oid relid, int2vector *pkattnums, int16 pknumatts, char **src_pkattvals, char **tgt_pkattvals);
typedef struct remoteConnHashEnt
{
char name[NAMEDATALEN];
- remoteConn *rcon;
+ remoteConn *rconn;
} remoteConnHashEnt;
/* initial number of connection hashes */
#define DBLINK_GET_CONN \
do { \
char *conname_or_str = GET_STR(PG_GETARG_TEXT_P(0)); \
- rcon = getConnectionByName(conname_or_str); \
- if(rcon) \
+ rconn = getConnectionByName(conname_or_str); \
+ if(rconn) \
{ \
- conn = rcon->con; \
+ conn = rconn->conn; \
} \
else \
{ \
char *msg;
MemoryContext oldcontext;
PGconn *conn = NULL;
- remoteConn *rcon = NULL;
+ remoteConn *rconn = NULL;
if (PG_NARGS() == 2)
{
oldcontext = MemoryContextSwitchTo(TopMemoryContext);
if (connname)
- rcon = (remoteConn *) palloc(sizeof(remoteConn));
+ rconn = (remoteConn *) palloc(sizeof(remoteConn));
conn = PQconnectdb(connstr);
MemoryContextSwitchTo(oldcontext);
{
msg = pstrdup(PQerrorMessage(conn));
PQfinish(conn);
- if (rcon)
- pfree(rcon);
+ if (rconn)
+ pfree(rconn);
ereport(ERROR,
(errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
if (connname)
{
- rcon->con = conn;
- createNewConnection(connname, rcon);
+ rconn->conn = conn;
+ createNewConnection(connname, rconn);
}
else
persistent_conn = conn;
dblink_disconnect(PG_FUNCTION_ARGS)
{
char *conname = NULL;
- remoteConn *rcon = NULL;
+ remoteConn *rconn = NULL;
PGconn *conn = NULL;
if (PG_NARGS() == 1)
{
conname = GET_STR(PG_GETARG_TEXT_P(0));
- rcon = getConnectionByName(conname);
- if (rcon)
- conn = rcon->con;
+ rconn = getConnectionByName(conname);
+ if (rconn)
+ conn = rconn->conn;
}
else
conn = persistent_conn;
DBLINK_CONN_NOT_AVAIL;
PQfinish(conn);
- if (rcon)
+ if (rconn)
{
deleteConnection(conname);
- pfree(rcon);
+ pfree(rconn);
}
else
persistent_conn = NULL;
char *sql = NULL;
char *conname = NULL;
StringInfo str = makeStringInfo();
- remoteConn *rcon = NULL;
+ remoteConn *rconn = NULL;
bool fail = true; /* default to backward compatible behavior */
if (PG_NARGS() == 2)
conname = GET_STR(PG_GETARG_TEXT_P(0));
curname = GET_STR(PG_GETARG_TEXT_P(1));
sql = GET_STR(PG_GETARG_TEXT_P(2));
- rcon = getConnectionByName(conname);
- if (rcon)
- conn = rcon->con;
+ rconn = getConnectionByName(conname);
+ if (rconn)
+ conn = rconn->conn;
}
}
else if (PG_NARGS() == 4)
curname = GET_STR(PG_GETARG_TEXT_P(1));
sql = GET_STR(PG_GETARG_TEXT_P(2));
fail = PG_GETARG_BOOL(3);
- rcon = getConnectionByName(conname);
- if (rcon)
- conn = rcon->con;
+ rconn = getConnectionByName(conname);
+ if (rconn)
+ conn = rconn->conn;
}
if (!conn)
char *conname = NULL;
StringInfo str = makeStringInfo();
char *msg;
- remoteConn *rcon = NULL;
+ remoteConn *rconn = NULL;
bool fail = true; /* default to backward compatible behavior */
if (PG_NARGS() == 1)
{
conname = GET_STR(PG_GETARG_TEXT_P(0));
curname = GET_STR(PG_GETARG_TEXT_P(1));
- rcon = getConnectionByName(conname);
- if (rcon)
- conn = rcon->con;
+ rconn = getConnectionByName(conname);
+ if (rconn)
+ conn = rconn->conn;
}
}
if (PG_NARGS() == 3)
conname = GET_STR(PG_GETARG_TEXT_P(0));
curname = GET_STR(PG_GETARG_TEXT_P(1));
fail = PG_GETARG_BOOL(2);
- rcon = getConnectionByName(conname);
- if (rcon)
- conn = rcon->con;
+ rconn = getConnectionByName(conname);
+ if (rconn)
+ conn = rconn->conn;
}
if (!conn)
PGresult *res = NULL;
MemoryContext oldcontext;
char *conname = NULL;
- remoteConn *rcon = NULL;
+ remoteConn *rconn = NULL;
/* stuff done only on the first call of the function */
if (SRF_IS_FIRSTCALL())
howmany = PG_GETARG_INT32(2);
fail = PG_GETARG_BOOL(3);
- rcon = getConnectionByName(conname);
- if (rcon)
- conn = rcon->con;
+ rconn = getConnectionByName(conname);
+ if (rconn)
+ conn = rconn->conn;
}
else if (PG_NARGS() == 3)
{
curname = GET_STR(PG_GETARG_TEXT_P(1));
howmany = PG_GETARG_INT32(2);
- rcon = getConnectionByName(conname);
- if (rcon)
- conn = rcon->con;
+ rconn = getConnectionByName(conname);
+ if (rconn)
+ conn = rconn->conn;
}
}
else if (PG_NARGS() == 2)
char *connstr = NULL;
char *sql = NULL;
char *conname = NULL;
- remoteConn *rcon = NULL;
+ remoteConn *rconn = NULL;
bool fail = true; /* default to backward compatible */
/* create a function context for cross-call persistence */
char *connstr = NULL;
char *sql = NULL;
char *conname = NULL;
- remoteConn *rcon = NULL;
+ remoteConn *rconn = NULL;
bool freeconn = false;
bool fail = true; /* default to backward compatible behavior */
key, HASH_FIND, NULL);
if (hentry)
- return (hentry->rcon);
+ return (hentry->rconn);
return (NULL);
}
(errcode(ERRCODE_DUPLICATE_OBJECT),
errmsg("duplicate connection name")));
- hentry->rcon = rconn;
+ hentry->rconn = rconn;
strncpy(hentry->name, name, NAMEDATALEN - 1);
}