summaryrefslogtreecommitdiff
path: root/contrib/dblink/dblink.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-03-29 17:52:43 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-03-29 17:52:43 -0400
commit19ab40fd468b78ef8e6e4e9db6e515d2232faefc (patch)
treebf877be3f4835c7e042c36cf14af38565eddb68d /contrib/dblink/dblink.c
parent0e74f1f6e0313e768d62d5f252a7d167ebd46a86 (diff)
Fix dblink's failure to report correct connection name in error messages.
The DBLINK_GET_CONN and DBLINK_GET_NAMED_CONN macros did not set the surrounding function's conname variable, causing errors to be incorrectly reported as having occurred on the "unnamed" connection in some cases. This bug was actually visible in two cases in the regression tests, but apparently whoever added those cases wasn't paying attention. Noted by Kyotaro Horiguchi, though this is different from his proposed patch. Back-patch to 8.4; 8.3 does not have the same type of error reporting so the patch is not relevant.
Diffstat (limited to 'contrib/dblink/dblink.c')
-rw-r--r--contrib/dblink/dblink.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/contrib/dblink/dblink.c b/contrib/dblink/dblink.c
index d68b12aeddc..c8f91a72fb3 100644
--- a/contrib/dblink/dblink.c
+++ b/contrib/dblink/dblink.c
@@ -167,9 +167,10 @@ typedef struct remoteConnHashEnt
do { \
char *conname_or_str = text_to_cstring(PG_GETARG_TEXT_PP(0)); \
rconn = getConnectionByName(conname_or_str); \
- if(rconn) \
+ if (rconn) \
{ \
conn = rconn->conn; \
+ conname = conname_or_str; \
} \
else \
{ \
@@ -197,9 +198,9 @@ typedef struct remoteConnHashEnt
#define DBLINK_GET_NAMED_CONN \
do { \
- char *conname = text_to_cstring(PG_GETARG_TEXT_PP(0)); \
+ conname = text_to_cstring(PG_GETARG_TEXT_PP(0)); \
rconn = getConnectionByName(conname); \
- if(rconn) \
+ if (rconn) \
conn = rconn->conn; \
else \
DBLINK_CONN_NOT_AVAIL; \
@@ -718,6 +719,7 @@ PG_FUNCTION_INFO_V1(dblink_send_query);
Datum
dblink_send_query(PG_FUNCTION_ARGS)
{
+ char *conname = NULL;
PGconn *conn = NULL;
char *connstr = NULL;
char *sql = NULL;
@@ -1042,6 +1044,7 @@ PG_FUNCTION_INFO_V1(dblink_is_busy);
Datum
dblink_is_busy(PG_FUNCTION_ARGS)
{
+ char *conname = NULL;
PGconn *conn = NULL;
remoteConn *rconn = NULL;
@@ -1068,6 +1071,7 @@ Datum
dblink_cancel_query(PG_FUNCTION_ARGS)
{
int res = 0;
+ char *conname = NULL;
PGconn *conn = NULL;
remoteConn *rconn = NULL;
PGcancel *cancel;
@@ -1102,6 +1106,7 @@ Datum
dblink_error_message(PG_FUNCTION_ARGS)
{
char *msg;
+ char *conname = NULL;
PGconn *conn = NULL;
remoteConn *rconn = NULL;