Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitdde1813

Browse files
committed
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 thesurrounding function's conname variable, causing errors to be incorrectlyreported 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 proposedpatch.Back-patch to 8.4; 8.3 does not have the same type of error reportingso the patch is not relevant.
1 parent20d98ab commitdde1813

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

‎contrib/dblink/dblink.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,10 @@ typedef struct remoteConnHashEnt
167167
do { \
168168
char *conname_or_str = text_to_cstring(PG_GETARG_TEXT_PP(0)); \
169169
rconn = getConnectionByName(conname_or_str); \
170-
if(rconn) \
170+
if(rconn) \
171171
{ \
172172
conn = rconn->conn; \
173+
conname = conname_or_str; \
173174
} \
174175
else \
175176
{ \
@@ -197,9 +198,9 @@ typedef struct remoteConnHashEnt
197198

198199
#defineDBLINK_GET_NAMED_CONN \
199200
do { \
200-
char *conname = text_to_cstring(PG_GETARG_TEXT_PP(0)); \
201+
conname = text_to_cstring(PG_GETARG_TEXT_PP(0)); \
201202
rconn = getConnectionByName(conname); \
202-
if(rconn) \
203+
if(rconn) \
203204
conn = rconn->conn; \
204205
else \
205206
DBLINK_CONN_NOT_AVAIL; \
@@ -612,6 +613,7 @@ PG_FUNCTION_INFO_V1(dblink_send_query);
612613
Datum
613614
dblink_send_query(PG_FUNCTION_ARGS)
614615
{
616+
char*conname=NULL;
615617
PGconn*conn=NULL;
616618
char*sql=NULL;
617619
remoteConn*rconn=NULL;
@@ -933,6 +935,7 @@ PG_FUNCTION_INFO_V1(dblink_is_busy);
933935
Datum
934936
dblink_is_busy(PG_FUNCTION_ARGS)
935937
{
938+
char*conname=NULL;
936939
PGconn*conn=NULL;
937940
remoteConn*rconn=NULL;
938941

@@ -959,6 +962,7 @@ Datum
959962
dblink_cancel_query(PG_FUNCTION_ARGS)
960963
{
961964
intres=0;
965+
char*conname=NULL;
962966
PGconn*conn=NULL;
963967
remoteConn*rconn=NULL;
964968
PGcancel*cancel;
@@ -993,6 +997,7 @@ Datum
993997
dblink_error_message(PG_FUNCTION_ARGS)
994998
{
995999
char*msg;
1000+
char*conname=NULL;
9961001
PGconn*conn=NULL;
9971002
remoteConn*rconn=NULL;
9981003

@@ -1502,6 +1507,7 @@ PG_FUNCTION_INFO_V1(dblink_get_notify);
15021507
Datum
15031508
dblink_get_notify(PG_FUNCTION_ARGS)
15041509
{
1510+
char*conname=NULL;
15051511
PGconn*conn=NULL;
15061512
remoteConn*rconn=NULL;
15071513
PGnotify*notify;

‎contrib/dblink/expected/dblink.out

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ SELECT *
371371
FROM dblink('myconn','SELECT * FROM foobar',false) AS t(a int, b text, c text[])
372372
WHERE t.a > 7;
373373
NOTICE: relation "foobar" does not exist
374-
CONTEXT: Error occurred on dblink connection named "unnamed": could not execute query.
374+
CONTEXT: Error occurred on dblink connection named "myconn": could not execute query.
375375
a | b | c
376376
---+---+---
377377
(0 rows)
@@ -494,7 +494,7 @@ SELECT dblink_close('myconn','rmt_foo_cursor');
494494
-- this should fail because there is no open transaction
495495
SELECT dblink_exec('myconn','DECLARE xact_test CURSOR FOR SELECT * FROM foo');
496496
ERROR: DECLARE CURSOR can only be used in transaction blocks
497-
CONTEXT: Error occurred on dblink connection named "unnamed": could not execute command.
497+
CONTEXT: Error occurred on dblink connection named "myconn": could not execute command.
498498
-- reset remote transaction state
499499
SELECT dblink_exec('myconn','ABORT');
500500
dblink_exec

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp