mirror of
https://github.com/postgres/postgres.git
synced 2025-04-29 13:56:47 +03:00
dblink: Replace some macros by static functions
Also remove some unused code and the no longer useful dblink.h file. Reviewed-by: Tsunakawa, Takayuki <tsunakawa.takay@jp.fujitsu.com>
This commit is contained in:
parent
d1ca82d0a2
commit
acaf7ccb94
@ -61,8 +61,6 @@
|
|||||||
#include "utils/tqual.h"
|
#include "utils/tqual.h"
|
||||||
#include "utils/varlena.h"
|
#include "utils/varlena.h"
|
||||||
|
|
||||||
#include "dblink.h"
|
|
||||||
|
|
||||||
PG_MODULE_MAGIC;
|
PG_MODULE_MAGIC;
|
||||||
|
|
||||||
typedef struct remoteConn
|
typedef struct remoteConn
|
||||||
@ -146,98 +144,102 @@ typedef struct remoteConnHashEnt
|
|||||||
/* initial number of connection hashes */
|
/* initial number of connection hashes */
|
||||||
#define NUMCONN 16
|
#define NUMCONN 16
|
||||||
|
|
||||||
/* general utility */
|
static char *
|
||||||
#define xpfree(var_) \
|
xpstrdup(const char *in)
|
||||||
do { \
|
{
|
||||||
if (var_ != NULL) \
|
if (in == NULL)
|
||||||
{ \
|
return NULL;
|
||||||
pfree(var_); \
|
return pstrdup(in);
|
||||||
var_ = NULL; \
|
}
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define xpstrdup(var_c, var_) \
|
static void pg_attribute_noreturn()
|
||||||
do { \
|
dblink_res_internalerror(PGconn *conn, PGresult *res, const char *p2)
|
||||||
if (var_ != NULL) \
|
{
|
||||||
var_c = pstrdup(var_); \
|
char *msg = pchomp(PQerrorMessage(conn));
|
||||||
else \
|
if (res)
|
||||||
var_c = NULL; \
|
PQclear(res);
|
||||||
} while (0)
|
elog(ERROR, "%s: %s", p2, msg);
|
||||||
|
}
|
||||||
|
|
||||||
#define DBLINK_RES_INTERNALERROR(p2) \
|
static void pg_attribute_noreturn()
|
||||||
do { \
|
dblink_conn_not_avail(const char *conname)
|
||||||
msg = pchomp(PQerrorMessage(conn)); \
|
{
|
||||||
if (res) \
|
if (conname)
|
||||||
PQclear(res); \
|
ereport(ERROR,
|
||||||
elog(ERROR, "%s: %s", p2, msg); \
|
(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
|
||||||
} while (0)
|
errmsg("connection \"%s\" not available", conname)));
|
||||||
|
else
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST),
|
||||||
|
errmsg("connection not available")));
|
||||||
|
}
|
||||||
|
|
||||||
#define DBLINK_CONN_NOT_AVAIL \
|
static void
|
||||||
do { \
|
dblink_get_conn(char *conname_or_str,
|
||||||
if(conname) \
|
PGconn * volatile *conn_p, char **conname_p, volatile bool *freeconn_p)
|
||||||
ereport(ERROR, \
|
{
|
||||||
(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST), \
|
remoteConn *rconn = getConnectionByName(conname_or_str);
|
||||||
errmsg("connection \"%s\" not available", conname))); \
|
PGconn *conn;
|
||||||
else \
|
char *conname;
|
||||||
ereport(ERROR, \
|
bool freeconn;
|
||||||
(errcode(ERRCODE_CONNECTION_DOES_NOT_EXIST), \
|
|
||||||
errmsg("connection not available"))); \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define DBLINK_GET_CONN \
|
if (rconn)
|
||||||
do { \
|
{
|
||||||
char *conname_or_str = text_to_cstring(PG_GETARG_TEXT_PP(0)); \
|
conn = rconn->conn;
|
||||||
rconn = getConnectionByName(conname_or_str); \
|
conname = conname_or_str;
|
||||||
if (rconn) \
|
freeconn = false;
|
||||||
{ \
|
}
|
||||||
conn = rconn->conn; \
|
else
|
||||||
conname = conname_or_str; \
|
{
|
||||||
} \
|
const char *connstr;
|
||||||
else \
|
|
||||||
{ \
|
|
||||||
connstr = get_connect_string(conname_or_str); \
|
|
||||||
if (connstr == NULL) \
|
|
||||||
{ \
|
|
||||||
connstr = conname_or_str; \
|
|
||||||
} \
|
|
||||||
dblink_connstr_check(connstr); \
|
|
||||||
conn = PQconnectdb(connstr); \
|
|
||||||
if (PQstatus(conn) == CONNECTION_BAD) \
|
|
||||||
{ \
|
|
||||||
msg = pchomp(PQerrorMessage(conn)); \
|
|
||||||
PQfinish(conn); \
|
|
||||||
ereport(ERROR, \
|
|
||||||
(errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION), \
|
|
||||||
errmsg("could not establish connection"), \
|
|
||||||
errdetail_internal("%s", msg))); \
|
|
||||||
} \
|
|
||||||
dblink_security_check(conn, rconn); \
|
|
||||||
if (PQclientEncoding(conn) != GetDatabaseEncoding()) \
|
|
||||||
PQsetClientEncoding(conn, GetDatabaseEncodingName()); \
|
|
||||||
freeconn = true; \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define DBLINK_GET_NAMED_CONN \
|
connstr = get_connect_string(conname_or_str);
|
||||||
do { \
|
if (connstr == NULL)
|
||||||
conname = text_to_cstring(PG_GETARG_TEXT_PP(0)); \
|
connstr = conname_or_str;
|
||||||
rconn = getConnectionByName(conname); \
|
dblink_connstr_check(connstr);
|
||||||
if (rconn) \
|
conn = PQconnectdb(connstr);
|
||||||
conn = rconn->conn; \
|
if (PQstatus(conn) == CONNECTION_BAD)
|
||||||
else \
|
{
|
||||||
DBLINK_CONN_NOT_AVAIL; \
|
char *msg = pchomp(PQerrorMessage(conn));
|
||||||
} while (0)
|
PQfinish(conn);
|
||||||
|
ereport(ERROR,
|
||||||
|
(errcode(ERRCODE_SQLCLIENT_UNABLE_TO_ESTABLISH_SQLCONNECTION),
|
||||||
|
errmsg("could not establish connection"),
|
||||||
|
errdetail_internal("%s", msg)));
|
||||||
|
}
|
||||||
|
dblink_security_check(conn, rconn);
|
||||||
|
if (PQclientEncoding(conn) != GetDatabaseEncoding())
|
||||||
|
PQsetClientEncoding(conn, GetDatabaseEncodingName());
|
||||||
|
freeconn = true;
|
||||||
|
conname = NULL;
|
||||||
|
}
|
||||||
|
|
||||||
#define DBLINK_INIT \
|
*conn_p = conn;
|
||||||
do { \
|
*conname_p = conname;
|
||||||
if (!pconn) \
|
*freeconn_p = freeconn;
|
||||||
{ \
|
}
|
||||||
pconn = (remoteConn *) MemoryContextAlloc(TopMemoryContext, sizeof(remoteConn)); \
|
|
||||||
pconn->conn = NULL; \
|
static PGconn *
|
||||||
pconn->openCursorCount = 0; \
|
dblink_get_named_conn(const char *conname)
|
||||||
pconn->newXactForCursor = FALSE; \
|
{
|
||||||
} \
|
remoteConn *rconn = getConnectionByName(conname);
|
||||||
} while (0)
|
if (rconn)
|
||||||
|
return rconn->conn;
|
||||||
|
else
|
||||||
|
dblink_conn_not_avail(conname);
|
||||||
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
dblink_init(void)
|
||||||
|
{
|
||||||
|
if (!pconn)
|
||||||
|
{
|
||||||
|
pconn = (remoteConn *) MemoryContextAlloc(TopMemoryContext, sizeof(remoteConn));
|
||||||
|
pconn->conn = NULL;
|
||||||
|
pconn->openCursorCount = 0;
|
||||||
|
pconn->newXactForCursor = FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Create a persistent connection to another database
|
* Create a persistent connection to another database
|
||||||
@ -253,7 +255,7 @@ dblink_connect(PG_FUNCTION_ARGS)
|
|||||||
PGconn *conn = NULL;
|
PGconn *conn = NULL;
|
||||||
remoteConn *rconn = NULL;
|
remoteConn *rconn = NULL;
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
|
|
||||||
if (PG_NARGS() == 2)
|
if (PG_NARGS() == 2)
|
||||||
{
|
{
|
||||||
@ -318,7 +320,7 @@ dblink_disconnect(PG_FUNCTION_ARGS)
|
|||||||
remoteConn *rconn = NULL;
|
remoteConn *rconn = NULL;
|
||||||
PGconn *conn = NULL;
|
PGconn *conn = NULL;
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
|
|
||||||
if (PG_NARGS() == 1)
|
if (PG_NARGS() == 1)
|
||||||
{
|
{
|
||||||
@ -331,7 +333,7 @@ dblink_disconnect(PG_FUNCTION_ARGS)
|
|||||||
conn = pconn->conn;
|
conn = pconn->conn;
|
||||||
|
|
||||||
if (!conn)
|
if (!conn)
|
||||||
DBLINK_CONN_NOT_AVAIL;
|
dblink_conn_not_avail(conname);
|
||||||
|
|
||||||
PQfinish(conn);
|
PQfinish(conn);
|
||||||
if (rconn)
|
if (rconn)
|
||||||
@ -352,7 +354,6 @@ PG_FUNCTION_INFO_V1(dblink_open);
|
|||||||
Datum
|
Datum
|
||||||
dblink_open(PG_FUNCTION_ARGS)
|
dblink_open(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
char *msg;
|
|
||||||
PGresult *res = NULL;
|
PGresult *res = NULL;
|
||||||
PGconn *conn = NULL;
|
PGconn *conn = NULL;
|
||||||
char *curname = NULL;
|
char *curname = NULL;
|
||||||
@ -362,7 +363,7 @@ dblink_open(PG_FUNCTION_ARGS)
|
|||||||
remoteConn *rconn = NULL;
|
remoteConn *rconn = NULL;
|
||||||
bool fail = true; /* default to backward compatible behavior */
|
bool fail = true; /* default to backward compatible behavior */
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
initStringInfo(&buf);
|
initStringInfo(&buf);
|
||||||
|
|
||||||
if (PG_NARGS() == 2)
|
if (PG_NARGS() == 2)
|
||||||
@ -401,7 +402,7 @@ dblink_open(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!rconn || !rconn->conn)
|
if (!rconn || !rconn->conn)
|
||||||
DBLINK_CONN_NOT_AVAIL;
|
dblink_conn_not_avail(conname);
|
||||||
else
|
else
|
||||||
conn = rconn->conn;
|
conn = rconn->conn;
|
||||||
|
|
||||||
@ -410,7 +411,7 @@ dblink_open(PG_FUNCTION_ARGS)
|
|||||||
{
|
{
|
||||||
res = PQexec(conn, "BEGIN");
|
res = PQexec(conn, "BEGIN");
|
||||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
DBLINK_RES_INTERNALERROR("begin error");
|
dblink_res_internalerror(conn, res, "begin error");
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
rconn->newXactForCursor = TRUE;
|
rconn->newXactForCursor = TRUE;
|
||||||
|
|
||||||
@ -450,11 +451,10 @@ dblink_close(PG_FUNCTION_ARGS)
|
|||||||
char *curname = NULL;
|
char *curname = NULL;
|
||||||
char *conname = NULL;
|
char *conname = NULL;
|
||||||
StringInfoData buf;
|
StringInfoData buf;
|
||||||
char *msg;
|
|
||||||
remoteConn *rconn = NULL;
|
remoteConn *rconn = NULL;
|
||||||
bool fail = true; /* default to backward compatible behavior */
|
bool fail = true; /* default to backward compatible behavior */
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
initStringInfo(&buf);
|
initStringInfo(&buf);
|
||||||
|
|
||||||
if (PG_NARGS() == 1)
|
if (PG_NARGS() == 1)
|
||||||
@ -489,7 +489,7 @@ dblink_close(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!rconn || !rconn->conn)
|
if (!rconn || !rconn->conn)
|
||||||
DBLINK_CONN_NOT_AVAIL;
|
dblink_conn_not_avail(conname);
|
||||||
else
|
else
|
||||||
conn = rconn->conn;
|
conn = rconn->conn;
|
||||||
|
|
||||||
@ -517,7 +517,7 @@ dblink_close(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
res = PQexec(conn, "COMMIT");
|
res = PQexec(conn, "COMMIT");
|
||||||
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
if (PQresultStatus(res) != PGRES_COMMAND_OK)
|
||||||
DBLINK_RES_INTERNALERROR("commit error");
|
dblink_res_internalerror(conn, res, "commit error");
|
||||||
PQclear(res);
|
PQclear(res);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -543,7 +543,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
prepTuplestoreResult(fcinfo);
|
prepTuplestoreResult(fcinfo);
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
|
|
||||||
if (PG_NARGS() == 4)
|
if (PG_NARGS() == 4)
|
||||||
{
|
{
|
||||||
@ -587,7 +587,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!conn)
|
if (!conn)
|
||||||
DBLINK_CONN_NOT_AVAIL;
|
dblink_conn_not_avail(conname);
|
||||||
|
|
||||||
initStringInfo(&buf);
|
initStringInfo(&buf);
|
||||||
appendStringInfo(&buf, "FETCH %d FROM %s", howmany, curname);
|
appendStringInfo(&buf, "FETCH %d FROM %s", howmany, curname);
|
||||||
@ -633,15 +633,13 @@ PG_FUNCTION_INFO_V1(dblink_send_query);
|
|||||||
Datum
|
Datum
|
||||||
dblink_send_query(PG_FUNCTION_ARGS)
|
dblink_send_query(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
char *conname = NULL;
|
PGconn *conn;
|
||||||
PGconn *conn = NULL;
|
char *sql;
|
||||||
char *sql = NULL;
|
|
||||||
remoteConn *rconn = NULL;
|
|
||||||
int retval;
|
int retval;
|
||||||
|
|
||||||
if (PG_NARGS() == 2)
|
if (PG_NARGS() == 2)
|
||||||
{
|
{
|
||||||
DBLINK_GET_NAMED_CONN;
|
conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
|
||||||
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -671,15 +669,12 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
|
|||||||
|
|
||||||
prepTuplestoreResult(fcinfo);
|
prepTuplestoreResult(fcinfo);
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
|
|
||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
char *msg;
|
|
||||||
char *connstr = NULL;
|
|
||||||
char *sql = NULL;
|
char *sql = NULL;
|
||||||
char *conname = NULL;
|
char *conname = NULL;
|
||||||
remoteConn *rconn = NULL;
|
|
||||||
bool fail = true; /* default to backward compatible */
|
bool fail = true; /* default to backward compatible */
|
||||||
|
|
||||||
if (!is_async)
|
if (!is_async)
|
||||||
@ -687,7 +682,7 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
|
|||||||
if (PG_NARGS() == 3)
|
if (PG_NARGS() == 3)
|
||||||
{
|
{
|
||||||
/* text,text,bool */
|
/* text,text,bool */
|
||||||
DBLINK_GET_CONN;
|
dblink_get_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)), &conn, &conname, &freeconn);
|
||||||
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
||||||
fail = PG_GETARG_BOOL(2);
|
fail = PG_GETARG_BOOL(2);
|
||||||
}
|
}
|
||||||
@ -702,7 +697,7 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DBLINK_GET_CONN;
|
dblink_get_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)), &conn, &conname, &freeconn);
|
||||||
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -722,13 +717,13 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
|
|||||||
if (PG_NARGS() == 2)
|
if (PG_NARGS() == 2)
|
||||||
{
|
{
|
||||||
/* text,bool */
|
/* text,bool */
|
||||||
DBLINK_GET_NAMED_CONN;
|
conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
|
||||||
fail = PG_GETARG_BOOL(1);
|
fail = PG_GETARG_BOOL(1);
|
||||||
}
|
}
|
||||||
else if (PG_NARGS() == 1)
|
else if (PG_NARGS() == 1)
|
||||||
{
|
{
|
||||||
/* text */
|
/* text */
|
||||||
DBLINK_GET_NAMED_CONN;
|
conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
/* shouldn't happen */
|
/* shouldn't happen */
|
||||||
@ -736,7 +731,7 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!conn)
|
if (!conn)
|
||||||
DBLINK_CONN_NOT_AVAIL;
|
dblink_conn_not_avail(conname);
|
||||||
|
|
||||||
if (!is_async)
|
if (!is_async)
|
||||||
{
|
{
|
||||||
@ -1297,12 +1292,10 @@ PG_FUNCTION_INFO_V1(dblink_is_busy);
|
|||||||
Datum
|
Datum
|
||||||
dblink_is_busy(PG_FUNCTION_ARGS)
|
dblink_is_busy(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
char *conname = NULL;
|
PGconn *conn;
|
||||||
PGconn *conn = NULL;
|
|
||||||
remoteConn *rconn = NULL;
|
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
DBLINK_GET_NAMED_CONN;
|
conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
|
||||||
|
|
||||||
PQconsumeInput(conn);
|
PQconsumeInput(conn);
|
||||||
PG_RETURN_INT32(PQisBusy(conn));
|
PG_RETURN_INT32(PQisBusy(conn));
|
||||||
@ -1323,15 +1316,13 @@ PG_FUNCTION_INFO_V1(dblink_cancel_query);
|
|||||||
Datum
|
Datum
|
||||||
dblink_cancel_query(PG_FUNCTION_ARGS)
|
dblink_cancel_query(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
int res = 0;
|
int res;
|
||||||
char *conname = NULL;
|
PGconn *conn;
|
||||||
PGconn *conn = NULL;
|
|
||||||
remoteConn *rconn = NULL;
|
|
||||||
PGcancel *cancel;
|
PGcancel *cancel;
|
||||||
char errbuf[256];
|
char errbuf[256];
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
DBLINK_GET_NAMED_CONN;
|
conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
|
||||||
cancel = PQgetCancel(conn);
|
cancel = PQgetCancel(conn);
|
||||||
|
|
||||||
res = PQcancel(cancel, errbuf, 256);
|
res = PQcancel(cancel, errbuf, 256);
|
||||||
@ -1359,12 +1350,10 @@ Datum
|
|||||||
dblink_error_message(PG_FUNCTION_ARGS)
|
dblink_error_message(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
char *msg;
|
char *msg;
|
||||||
char *conname = NULL;
|
PGconn *conn;
|
||||||
PGconn *conn = NULL;
|
|
||||||
remoteConn *rconn = NULL;
|
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
DBLINK_GET_NAMED_CONN;
|
conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
|
||||||
|
|
||||||
msg = PQerrorMessage(conn);
|
msg = PQerrorMessage(conn);
|
||||||
if (msg == NULL || msg[0] == '\0')
|
if (msg == NULL || msg[0] == '\0')
|
||||||
@ -1384,22 +1373,19 @@ dblink_exec(PG_FUNCTION_ARGS)
|
|||||||
PGconn *volatile conn = NULL;
|
PGconn *volatile conn = NULL;
|
||||||
volatile bool freeconn = false;
|
volatile bool freeconn = false;
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
|
|
||||||
PG_TRY();
|
PG_TRY();
|
||||||
{
|
{
|
||||||
char *msg;
|
|
||||||
PGresult *res = NULL;
|
PGresult *res = NULL;
|
||||||
char *connstr = NULL;
|
|
||||||
char *sql = NULL;
|
char *sql = NULL;
|
||||||
char *conname = NULL;
|
char *conname = NULL;
|
||||||
remoteConn *rconn = NULL;
|
|
||||||
bool fail = true; /* default to backward compatible behavior */
|
bool fail = true; /* default to backward compatible behavior */
|
||||||
|
|
||||||
if (PG_NARGS() == 3)
|
if (PG_NARGS() == 3)
|
||||||
{
|
{
|
||||||
/* must be text,text,bool */
|
/* must be text,text,bool */
|
||||||
DBLINK_GET_CONN;
|
dblink_get_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)), &conn, &conname, &freeconn);
|
||||||
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
||||||
fail = PG_GETARG_BOOL(2);
|
fail = PG_GETARG_BOOL(2);
|
||||||
}
|
}
|
||||||
@ -1414,7 +1400,7 @@ dblink_exec(PG_FUNCTION_ARGS)
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
DBLINK_GET_CONN;
|
dblink_get_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)), &conn, &conname, &freeconn);
|
||||||
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -1429,7 +1415,7 @@ dblink_exec(PG_FUNCTION_ARGS)
|
|||||||
elog(ERROR, "wrong number of arguments");
|
elog(ERROR, "wrong number of arguments");
|
||||||
|
|
||||||
if (!conn)
|
if (!conn)
|
||||||
DBLINK_CONN_NOT_AVAIL;
|
dblink_conn_not_avail(conname);
|
||||||
|
|
||||||
res = PQexec(conn, sql);
|
res = PQexec(conn, sql);
|
||||||
if (!res ||
|
if (!res ||
|
||||||
@ -1880,9 +1866,7 @@ PG_FUNCTION_INFO_V1(dblink_get_notify);
|
|||||||
Datum
|
Datum
|
||||||
dblink_get_notify(PG_FUNCTION_ARGS)
|
dblink_get_notify(PG_FUNCTION_ARGS)
|
||||||
{
|
{
|
||||||
char *conname = NULL;
|
PGconn *conn;
|
||||||
PGconn *conn = NULL;
|
|
||||||
remoteConn *rconn = NULL;
|
|
||||||
PGnotify *notify;
|
PGnotify *notify;
|
||||||
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
|
ReturnSetInfo *rsinfo = (ReturnSetInfo *) fcinfo->resultinfo;
|
||||||
TupleDesc tupdesc;
|
TupleDesc tupdesc;
|
||||||
@ -1892,9 +1876,9 @@ dblink_get_notify(PG_FUNCTION_ARGS)
|
|||||||
|
|
||||||
prepTuplestoreResult(fcinfo);
|
prepTuplestoreResult(fcinfo);
|
||||||
|
|
||||||
DBLINK_INIT;
|
dblink_init();
|
||||||
if (PG_NARGS() == 1)
|
if (PG_NARGS() == 1)
|
||||||
DBLINK_GET_NAMED_CONN;
|
conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
|
||||||
else
|
else
|
||||||
conn = pconn->conn;
|
conn = pconn->conn;
|
||||||
|
|
||||||
@ -2698,10 +2682,10 @@ dblink_res_error(PGconn *conn, const char *conname, PGresult *res,
|
|||||||
else
|
else
|
||||||
sqlstate = ERRCODE_CONNECTION_FAILURE;
|
sqlstate = ERRCODE_CONNECTION_FAILURE;
|
||||||
|
|
||||||
xpstrdup(message_primary, pg_diag_message_primary);
|
message_primary = xpstrdup(pg_diag_message_primary);
|
||||||
xpstrdup(message_detail, pg_diag_message_detail);
|
message_detail = xpstrdup(pg_diag_message_detail);
|
||||||
xpstrdup(message_hint, pg_diag_message_hint);
|
message_hint = xpstrdup(pg_diag_message_hint);
|
||||||
xpstrdup(message_context, pg_diag_context);
|
message_context = xpstrdup(pg_diag_context);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* If we don't get a message from the PGresult, try the PGconn. This
|
* If we don't get a message from the PGresult, try the PGconn. This
|
||||||
|
@ -1,39 +0,0 @@
|
|||||||
/*
|
|
||||||
* dblink.h
|
|
||||||
*
|
|
||||||
* Functions returning results from a remote database
|
|
||||||
*
|
|
||||||
* Joe Conway <mail@joeconway.com>
|
|
||||||
* And contributors:
|
|
||||||
* Darko Prenosil <Darko.Prenosil@finteh.hr>
|
|
||||||
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
|
|
||||||
*
|
|
||||||
* contrib/dblink/dblink.h
|
|
||||||
* Copyright (c) 2001-2017, PostgreSQL Global Development Group
|
|
||||||
* ALL RIGHTS RESERVED;
|
|
||||||
*
|
|
||||||
* Permission to use, copy, modify, and distribute this software and its
|
|
||||||
* documentation for any purpose, without fee, and without a written agreement
|
|
||||||
* is hereby granted, provided that the above copyright notice and this
|
|
||||||
* paragraph and the following two paragraphs appear in all copies.
|
|
||||||
*
|
|
||||||
* IN NO EVENT SHALL THE AUTHOR OR DISTRIBUTORS BE LIABLE TO ANY PARTY FOR
|
|
||||||
* DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING
|
|
||||||
* LOST PROFITS, ARISING OUT OF THE USE OF THIS SOFTWARE AND ITS
|
|
||||||
* DOCUMENTATION, EVEN IF THE AUTHOR OR DISTRIBUTORS HAVE BEEN ADVISED OF THE
|
|
||||||
* POSSIBILITY OF SUCH DAMAGE.
|
|
||||||
*
|
|
||||||
* THE AUTHOR AND DISTRIBUTORS SPECIFICALLY DISCLAIMS ANY WARRANTIES,
|
|
||||||
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
||||||
* AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE PROVIDED HEREUNDER IS
|
|
||||||
* ON AN "AS IS" BASIS, AND THE AUTHOR AND DISTRIBUTORS HAS NO OBLIGATIONS TO
|
|
||||||
* PROVIDE MAINTENANCE, SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
#ifndef DBLINK_H
|
|
||||||
#define DBLINK_H
|
|
||||||
|
|
||||||
#include "fmgr.h"
|
|
||||||
|
|
||||||
#endif /* DBLINK_H */
|
|
Loading…
x
Reference in New Issue
Block a user