8
8
* Darko Prenosil <Darko.Prenosil@finteh.hr>
9
9
* Shridhar Daithankar <shridhar_daithankar@persistent.co.in>
10
10
*
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 $
12
12
* Copyright (c) 2001-2009, PostgreSQL Global Development Group
13
13
* ALL RIGHTS RESERVED;
14
14
*
@@ -77,7 +77,7 @@ typedef struct remoteConn
77
77
/*
78
78
* Internal declarations
79
79
*/
80
- static Datum dblink_record_internal (FunctionCallInfo fcinfo , bool is_async , bool do_get );
80
+ static Datum dblink_record_internal (FunctionCallInfo fcinfo , bool is_async );
81
81
static remoteConn * getConnectionByName (const char * name );
82
82
static HTAB * createConnHash (void );
83
83
static void createNewConnection (const char * name , remoteConn * rconn );
@@ -689,25 +689,47 @@ PG_FUNCTION_INFO_V1(dblink_record);
689
689
Datum
690
690
dblink_record (PG_FUNCTION_ARGS )
691
691
{
692
- return dblink_record_internal (fcinfo , false, false );
692
+ return dblink_record_internal (fcinfo , false);
693
693
}
694
694
695
695
PG_FUNCTION_INFO_V1 (dblink_send_query );
696
696
Datum
697
697
dblink_send_query (PG_FUNCTION_ARGS )
698
698
{
699
- return dblink_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
+ bool freeconn = false;
705
+ int retval ;
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 );
700
722
}
701
723
702
724
PG_FUNCTION_INFO_V1 (dblink_get_result );
703
725
Datum
704
726
dblink_get_result (PG_FUNCTION_ARGS )
705
727
{
706
- return dblink_record_internal (fcinfo , true, true );
728
+ return dblink_record_internal (fcinfo , true);
707
729
}
708
730
709
731
static Datum
710
- dblink_record_internal (FunctionCallInfo fcinfo , bool is_async , bool do_get )
732
+ dblink_record_internal (FunctionCallInfo fcinfo , bool is_async )
711
733
{
712
734
FuncCallContext * funcctx ;
713
735
TupleDesc tupdesc = NULL ;
@@ -775,14 +797,14 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
775
797
/* shouldn't happen */
776
798
elog (ERROR , "wrong number of arguments" );
777
799
}
778
- else if ( is_async && do_get )
800
+ else /* is_async */
779
801
{
780
802
/* get async result */
781
803
if (PG_NARGS () == 2 )
782
804
{
783
805
/* text,bool */
784
806
DBLINK_GET_CONN ;
785
- fail = PG_GETARG_BOOL (2 );
807
+ fail = PG_GETARG_BOOL (1 );
786
808
}
787
809
else if (PG_NARGS () == 1 )
788
810
{
@@ -793,24 +815,10 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
793
815
/* shouldn't happen */
794
816
elog (ERROR , "wrong number of arguments" );
795
817
}
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
- }
808
818
809
819
if (!conn )
810
820
DBLINK_CONN_NOT_AVAIL ;
811
821
812
- if (!is_async || (is_async && do_get ))
813
- {
814
822
/* synchronous query, or async result retrieval */
815
823
if (!is_async )
816
824
res = PQexec (conn , sql );
@@ -911,19 +919,6 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
911
919
funcctx -> attinmeta = attinmeta ;
912
920
913
921
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" );
927
922
928
923
}
929
924
0 commit comments