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.58 2006/09/02 21:11:15 joe Exp $
11
+ * $PostgreSQL: pgsql/contrib/dblink/dblink.c,v 1.59 2006/10/04 00:29:44 momjian Exp $
12
12
* Copyright (c) 2001-2006, PostgreSQL Global Development Group
13
13
* ALL RIGHTS RESERVED;
14
14
*
@@ -362,11 +362,11 @@ dblink_open(PG_FUNCTION_ARGS)
362
362
DBLINK_RES_INTERNALERROR ("begin error" );
363
363
PQclear (res );
364
364
rconn -> newXactForCursor = TRUE;
365
+
365
366
/*
366
367
* Since transaction state was IDLE, we force cursor count to
367
- * initially be 0. This is needed as a previous ABORT might
368
- * have wiped out our transaction without maintaining the
369
- * cursor count for us.
368
+ * initially be 0. This is needed as a previous ABORT might have wiped
369
+ * out our transaction without maintaining the cursor count for us.
370
370
*/
371
371
rconn -> openCursorCount = 0 ;
372
372
}
@@ -621,8 +621,8 @@ dblink_fetch(PG_FUNCTION_ARGS)
621
621
if (PQnfields (res ) != tupdesc -> natts )
622
622
ereport (ERROR ,
623
623
(errcode (ERRCODE_DATATYPE_MISMATCH ),
624
- errmsg ("remote query result rowtype does not match "
625
- "the specified FROM clause rowtype" )));
624
+ errmsg ("remote query result rowtype does not match "
625
+ "the specified FROM clause rowtype" )));
626
626
627
627
/* fast track when no results */
628
628
if (funcctx -> max_calls < 1 )
@@ -827,7 +827,7 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
827
827
828
828
if (!res ||
829
829
(PQresultStatus (res ) != PGRES_COMMAND_OK &&
830
- PQresultStatus (res ) != PGRES_TUPLES_OK ))
830
+ PQresultStatus (res ) != PGRES_TUPLES_OK ))
831
831
{
832
832
if (fail )
833
833
DBLINK_RES_ERROR ("sql error" );
@@ -839,33 +839,33 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
839
839
SRF_RETURN_DONE (funcctx );
840
840
}
841
841
}
842
-
842
+
843
843
if (PQresultStatus (res ) == PGRES_COMMAND_OK )
844
844
{
845
845
is_sql_cmd = true;
846
-
846
+
847
847
/* need a tuple descriptor representing one TEXT column */
848
848
tupdesc = CreateTemplateTupleDesc (1 , false);
849
849
TupleDescInitEntry (tupdesc , (AttrNumber ) 1 , "status" ,
850
- TEXTOID , -1 , 0 );
851
-
850
+ TEXTOID , -1 , 0 );
851
+
852
852
/*
853
- * and save a copy of the command status string to return as our
854
- * result tuple
855
- */
853
+ * and save a copy of the command status string to return as
854
+ * our result tuple
855
+ */
856
856
sql_cmd_status = PQcmdStatus (res );
857
857
funcctx -> max_calls = 1 ;
858
858
}
859
859
else
860
860
funcctx -> max_calls = PQntuples (res );
861
-
861
+
862
862
/* got results, keep track of them */
863
863
funcctx -> user_fctx = res ;
864
-
864
+
865
865
/* if needed, close the connection to the database and cleanup */
866
866
if (freeconn )
867
867
PQfinish (conn );
868
-
868
+
869
869
if (!is_sql_cmd )
870
870
{
871
871
/* get a tuple descriptor for our result type */
@@ -878,38 +878,41 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
878
878
/* failed to determine actual type of RECORD */
879
879
ereport (ERROR ,
880
880
(errcode (ERRCODE_FEATURE_NOT_SUPPORTED ),
881
- errmsg ("function returning record called in context "
882
- "that cannot accept type record" )));
881
+ errmsg ("function returning record called in context "
882
+ "that cannot accept type record" )));
883
883
break ;
884
884
default :
885
885
/* result type isn't composite */
886
886
elog (ERROR , "return type must be a row type" );
887
887
break ;
888
888
}
889
-
889
+
890
890
/* make sure we have a persistent copy of the tupdesc */
891
891
tupdesc = CreateTupleDescCopy (tupdesc );
892
892
}
893
-
894
- /* check result and tuple descriptor have the same number of columns */
893
+
894
+ /*
895
+ * check result and tuple descriptor have the same number of
896
+ * columns
897
+ */
895
898
if (PQnfields (res ) != tupdesc -> natts )
896
899
ereport (ERROR ,
897
900
(errcode (ERRCODE_DATATYPE_MISMATCH ),
898
- errmsg ("remote query result rowtype does not match "
899
- "the specified FROM clause rowtype" )));
900
-
901
+ errmsg ("remote query result rowtype does not match "
902
+ "the specified FROM clause rowtype" )));
903
+
901
904
/* fast track when no results */
902
905
if (funcctx -> max_calls < 1 )
903
906
{
904
907
if (res )
905
908
PQclear (res );
906
909
SRF_RETURN_DONE (funcctx );
907
910
}
908
-
911
+
909
912
/* store needed metadata for subsequent calls */
910
913
attinmeta = TupleDescGetAttInMetadata (tupdesc );
911
914
funcctx -> attinmeta = attinmeta ;
912
-
915
+
913
916
MemoryContextSwitchTo (oldcontext );
914
917
}
915
918
else
@@ -991,9 +994,9 @@ PG_FUNCTION_INFO_V1(dblink_get_connections);
991
994
Datum
992
995
dblink_get_connections (PG_FUNCTION_ARGS )
993
996
{
994
- HASH_SEQ_STATUS status ;
995
- remoteConnHashEnt * hentry ;
996
- ArrayBuildState * astate = NULL ;
997
+ HASH_SEQ_STATUS status ;
998
+ remoteConnHashEnt * hentry ;
999
+ ArrayBuildState * astate = NULL ;
997
1000
998
1001
if (remoteConnHash )
999
1002
{
@@ -1019,19 +1022,19 @@ dblink_get_connections(PG_FUNCTION_ARGS)
1019
1022
*
1020
1023
* Returns 1 if the connection is busy, 0 otherwise
1021
1024
* Params:
1022
- * text connection_name - name of the connection to check
1023
- *
1025
+ * text connection_name - name of the connection to check
1026
+ *
1024
1027
*/
1025
1028
PG_FUNCTION_INFO_V1 (dblink_is_busy );
1026
1029
Datum
1027
1030
dblink_is_busy (PG_FUNCTION_ARGS )
1028
1031
{
1029
- char * msg ;
1030
- PGconn * conn = NULL ;
1031
- char * conname = NULL ;
1032
- char * connstr = NULL ;
1033
- remoteConn * rconn = NULL ;
1034
- bool freeconn = false;
1032
+ char * msg ;
1033
+ PGconn * conn = NULL ;
1034
+ char * conname = NULL ;
1035
+ char * connstr = NULL ;
1036
+ remoteConn * rconn = NULL ;
1037
+ bool freeconn = false;
1035
1038
1036
1039
DBLINK_INIT ;
1037
1040
DBLINK_GET_CONN ;
@@ -1045,27 +1048,27 @@ dblink_is_busy(PG_FUNCTION_ARGS)
1045
1048
/*
1046
1049
* Cancels a running request on a connection
1047
1050
*
1048
- * Returns text:
1051
+ * Returns text:
1049
1052
* "OK" if the cancel request has been sent correctly,
1050
- * an error message otherwise
1051
- *
1053
+ * an error message otherwise
1054
+ *
1052
1055
* Params:
1053
- * text connection_name - name of the connection to check
1054
- *
1056
+ * text connection_name - name of the connection to check
1057
+ *
1055
1058
*/
1056
1059
PG_FUNCTION_INFO_V1 (dblink_cancel_query );
1057
1060
Datum
1058
1061
dblink_cancel_query (PG_FUNCTION_ARGS )
1059
1062
{
1060
- char * msg ;
1061
- int res = 0 ;
1062
- PGconn * conn = NULL ;
1063
- char * conname = NULL ;
1064
- char * connstr = NULL ;
1065
- remoteConn * rconn = NULL ;
1066
- bool freeconn = false;
1067
- PGcancel * cancel ;
1068
- char errbuf [256 ];
1063
+ char * msg ;
1064
+ int res = 0 ;
1065
+ PGconn * conn = NULL ;
1066
+ char * conname = NULL ;
1067
+ char * connstr = NULL ;
1068
+ remoteConn * rconn = NULL ;
1069
+ bool freeconn = false;
1070
+ PGcancel * cancel ;
1071
+ char errbuf [256 ];
1069
1072
1070
1073
DBLINK_INIT ;
1071
1074
DBLINK_GET_CONN ;
@@ -1077,7 +1080,7 @@ dblink_cancel_query(PG_FUNCTION_ARGS)
1077
1080
PQfreeCancel (cancel );
1078
1081
1079
1082
if (res == 0 )
1080
- PG_RETURN_TEXT_P (GET_TEXT ("OK" ));
1083
+ PG_RETURN_TEXT_P (GET_TEXT ("OK" ));
1081
1084
else
1082
1085
PG_RETURN_TEXT_P (GET_TEXT (errbuf ));
1083
1086
}
@@ -1086,23 +1089,23 @@ dblink_cancel_query(PG_FUNCTION_ARGS)
1086
1089
/*
1087
1090
* Get error message from a connection
1088
1091
*
1089
- * Returns text:
1092
+ * Returns text:
1090
1093
* "OK" if no error, an error message otherwise
1091
- *
1094
+ *
1092
1095
* Params:
1093
- * text connection_name - name of the connection to check
1094
- *
1096
+ * text connection_name - name of the connection to check
1097
+ *
1095
1098
*/
1096
1099
PG_FUNCTION_INFO_V1 (dblink_error_message );
1097
1100
Datum
1098
1101
dblink_error_message (PG_FUNCTION_ARGS )
1099
1102
{
1100
- char * msg ;
1101
- PGconn * conn = NULL ;
1102
- char * conname = NULL ;
1103
- char * connstr = NULL ;
1104
- remoteConn * rconn = NULL ;
1105
- bool freeconn = false;
1103
+ char * msg ;
1104
+ PGconn * conn = NULL ;
1105
+ char * conname = NULL ;
1106
+ char * connstr = NULL ;
1107
+ remoteConn * rconn = NULL ;
1108
+ bool freeconn = false;
1106
1109
1107
1110
DBLINK_INIT ;
1108
1111
DBLINK_GET_CONN ;
@@ -1859,7 +1862,7 @@ get_sql_delete(Oid relid, int2vector *pkattnums, int16 pknumatts, char **tgt_pka
1859
1862
char * relname ;
1860
1863
TupleDesc tupdesc ;
1861
1864
int natts ;
1862
- StringInfoData buf ;
1865
+ StringInfoData buf ;
1863
1866
int i ;
1864
1867
1865
1868
initStringInfo (& buf );
0 commit comments