Skip to content

Commit 8516364

Browse files
committed
dblink: Fix error reporting
The conname variable was not initialized in some code paths, resulting in error reports referring to the "unnamed" connection rather than the correct connection name. Author: Rushabh Lathia <rushabh.lathia@gmail.com>
1 parent ff539da commit 8516364

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

contrib/dblink/dblink.c

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -687,23 +687,25 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
687687
if (PG_NARGS() == 3)
688688
{
689689
/* text,text,bool */
690-
dblink_get_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)), &conn, &conname, &freeconn);
690+
conname = text_to_cstring(PG_GETARG_TEXT_PP(0));
691691
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
692692
fail = PG_GETARG_BOOL(2);
693+
dblink_get_conn(conname, &conn, &conname, &freeconn);
693694
}
694695
else if (PG_NARGS() == 2)
695696
{
696697
/* text,text or text,bool */
697698
if (get_fn_expr_argtype(fcinfo->flinfo, 1) == BOOLOID)
698699
{
699-
conn = pconn->conn;
700700
sql = text_to_cstring(PG_GETARG_TEXT_PP(0));
701701
fail = PG_GETARG_BOOL(1);
702+
conn = pconn->conn;
702703
}
703704
else
704705
{
705-
dblink_get_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)), &conn, &conname, &freeconn);
706+
conname = text_to_cstring(PG_GETARG_TEXT_PP(0));
706707
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
708+
dblink_get_conn(conname, &conn, &conname, &freeconn);
707709
}
708710
}
709711
else if (PG_NARGS() == 1)
@@ -719,16 +721,18 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
719721
else /* is_async */
720722
{
721723
/* get async result */
724+
conname = text_to_cstring(PG_GETARG_TEXT_PP(0));
725+
722726
if (PG_NARGS() == 2)
723727
{
724728
/* text,bool */
725-
conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
726729
fail = PG_GETARG_BOOL(1);
730+
conn = dblink_get_named_conn(conname);
727731
}
728732
else if (PG_NARGS() == 1)
729733
{
730734
/* text */
731-
conn = dblink_get_named_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)));
735+
conn = dblink_get_named_conn(conname);
732736
}
733737
else
734738
/* shouldn't happen */
@@ -1390,23 +1394,25 @@ dblink_exec(PG_FUNCTION_ARGS)
13901394
if (PG_NARGS() == 3)
13911395
{
13921396
/* must be text,text,bool */
1393-
dblink_get_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)), &conn, &conname, &freeconn);
1397+
conname = text_to_cstring(PG_GETARG_TEXT_PP(0));
13941398
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
13951399
fail = PG_GETARG_BOOL(2);
1400+
dblink_get_conn(conname, &conn, &conname, &freeconn);
13961401
}
13971402
else if (PG_NARGS() == 2)
13981403
{
13991404
/* might be text,text or text,bool */
14001405
if (get_fn_expr_argtype(fcinfo->flinfo, 1) == BOOLOID)
14011406
{
1402-
conn = pconn->conn;
14031407
sql = text_to_cstring(PG_GETARG_TEXT_PP(0));
14041408
fail = PG_GETARG_BOOL(1);
1409+
conn = pconn->conn;
14051410
}
14061411
else
14071412
{
1408-
dblink_get_conn(text_to_cstring(PG_GETARG_TEXT_PP(0)), &conn, &conname, &freeconn);
1413+
conname = text_to_cstring(PG_GETARG_TEXT_PP(0));
14091414
sql = text_to_cstring(PG_GETARG_TEXT_PP(1));
1415+
dblink_get_conn(conname, &conn, &conname, &freeconn);
14101416
}
14111417
}
14121418
else if (PG_NARGS() == 1)

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