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

Commitdb02073

Browse files
committed
Fix dblink_get_result() as reported by Oleksiy Shchukin. Refactor a bit
while we're at it per request by Tom Lane. Specifically, don't try toperform dblink_send_query() via dblink_record_internal() -- it wasinappropriate and ugly.
1 parentbac2ad3 commitdb02073

File tree

1 file changed

+30
-35
lines changed

1 file changed

+30
-35
lines changed

‎contrib/dblink/dblink.c

Lines changed: 30 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* Darko Prenosil <Darko.Prenosil@finteh.hr>
99
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
1010
*
11-
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.77 2009/01/01 17:23:31 momjian Exp $
11+
* $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.78 2009/06/02 03:21:56 joe Exp $
1212
* Copyright (c) 2001-2009, PostgreSQL Global Development Group
1313
* ALL RIGHTS RESERVED;
1414
*
@@ -77,7 +77,7 @@ typedef struct remoteConn
7777
/*
7878
* Internal declarations
7979
*/
80-
staticDatumdblink_record_internal(FunctionCallInfofcinfo,boolis_async,booldo_get);
80+
staticDatumdblink_record_internal(FunctionCallInfofcinfo,boolis_async);
8181
staticremoteConn*getConnectionByName(constchar*name);
8282
staticHTAB*createConnHash(void);
8383
staticvoidcreateNewConnection(constchar*name,remoteConn*rconn);
@@ -689,25 +689,47 @@ PG_FUNCTION_INFO_V1(dblink_record);
689689
Datum
690690
dblink_record(PG_FUNCTION_ARGS)
691691
{
692-
returndblink_record_internal(fcinfo, false, false);
692+
returndblink_record_internal(fcinfo, false);
693693
}
694694

695695
PG_FUNCTION_INFO_V1(dblink_send_query);
696696
Datum
697697
dblink_send_query(PG_FUNCTION_ARGS)
698698
{
699-
returndblink_record_internal(fcinfo, true, false);
699+
PGconn*conn=NULL;
700+
char*connstr=NULL;
701+
char*sql=NULL;
702+
remoteConn*rconn=NULL;
703+
char*msg;
704+
boolfreeconn= false;
705+
intretval;
706+
707+
if (PG_NARGS()==2)
708+
{
709+
DBLINK_GET_CONN;
710+
sql=text_to_cstring(PG_GETARG_TEXT_PP(1));
711+
}
712+
else
713+
/* shouldn't happen */
714+
elog(ERROR,"wrong number of arguments");
715+
716+
/* async query send */
717+
retval=PQsendQuery(conn,sql);
718+
if (retval!=1)
719+
elog(NOTICE,"%s",PQerrorMessage(conn));
720+
721+
PG_RETURN_INT32(retval);
700722
}
701723

702724
PG_FUNCTION_INFO_V1(dblink_get_result);
703725
Datum
704726
dblink_get_result(PG_FUNCTION_ARGS)
705727
{
706-
returndblink_record_internal(fcinfo, true, true);
728+
returndblink_record_internal(fcinfo, true);
707729
}
708730

709731
staticDatum
710-
dblink_record_internal(FunctionCallInfofcinfo,boolis_async,booldo_get)
732+
dblink_record_internal(FunctionCallInfofcinfo,boolis_async)
711733
{
712734
FuncCallContext*funcctx;
713735
TupleDesctupdesc=NULL;
@@ -775,14 +797,14 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
775797
/* shouldn't happen */
776798
elog(ERROR,"wrong number of arguments");
777799
}
778-
elseif (is_async&&do_get)
800+
else/*is_async*/
779801
{
780802
/* get async result */
781803
if (PG_NARGS()==2)
782804
{
783805
/* text,bool */
784806
DBLINK_GET_CONN;
785-
fail=PG_GETARG_BOOL(2);
807+
fail=PG_GETARG_BOOL(1);
786808
}
787809
elseif (PG_NARGS()==1)
788810
{
@@ -793,24 +815,10 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
793815
/* shouldn't happen */
794816
elog(ERROR,"wrong number of arguments");
795817
}
796-
else
797-
{
798-
/* send async query */
799-
if (PG_NARGS()==2)
800-
{
801-
DBLINK_GET_CONN;
802-
sql=text_to_cstring(PG_GETARG_TEXT_PP(1));
803-
}
804-
else
805-
/* shouldn't happen */
806-
elog(ERROR,"wrong number of arguments");
807-
}
808818

809819
if (!conn)
810820
DBLINK_CONN_NOT_AVAIL;
811821

812-
if (!is_async|| (is_async&&do_get))
813-
{
814822
/* synchronous query, or async result retrieval */
815823
if (!is_async)
816824
res=PQexec(conn,sql);
@@ -911,19 +919,6 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
911919
funcctx->attinmeta=attinmeta;
912920

913921
MemoryContextSwitchTo(oldcontext);
914-
}
915-
else
916-
{
917-
/* async query send */
918-
MemoryContextSwitchTo(oldcontext);
919-
PG_RETURN_INT32(PQsendQuery(conn,sql));
920-
}
921-
}
922-
923-
if (is_async&& !do_get)
924-
{
925-
/* async query send -- should not happen */
926-
elog(ERROR,"async query send called more than once");
927922

928923
}
929924

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp