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.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 $
1212 * Copyright (c) 2001-2006, PostgreSQL Global Development Group
1313 * ALL RIGHTS RESERVED;
1414 *
@@ -362,11 +362,11 @@ dblink_open(PG_FUNCTION_ARGS)
362362 DBLINK_RES_INTERNALERROR ("begin error" );
363363 PQclear (res );
364364 rconn -> newXactForCursor = TRUE;
365+
365366 /*
366367 * 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.
370370 */
371371 rconn -> openCursorCount = 0 ;
372372 }
@@ -621,8 +621,8 @@ dblink_fetch(PG_FUNCTION_ARGS)
621621 if (PQnfields (res ) != tupdesc -> natts )
622622 ereport (ERROR ,
623623 (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" )));
626626
627627 /* fast track when no results */
628628 if (funcctx -> max_calls < 1 )
@@ -827,7 +827,7 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
827827
828828 if (!res ||
829829 (PQresultStatus (res ) != PGRES_COMMAND_OK &&
830- PQresultStatus (res ) != PGRES_TUPLES_OK ))
830+ PQresultStatus (res ) != PGRES_TUPLES_OK ))
831831 {
832832 if (fail )
833833 DBLINK_RES_ERROR ("sql error" );
@@ -839,33 +839,33 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
839839 SRF_RETURN_DONE (funcctx );
840840 }
841841 }
842-
842+
843843 if (PQresultStatus (res ) == PGRES_COMMAND_OK )
844844 {
845845 is_sql_cmd = true;
846-
846+
847847 /* need a tuple descriptor representing one TEXT column */
848848 tupdesc = CreateTemplateTupleDesc (1 , false);
849849 TupleDescInitEntry (tupdesc , (AttrNumber ) 1 , "status" ,
850- TEXTOID , -1 , 0 );
851-
850+ TEXTOID , -1 , 0 );
851+
852852 /*
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+ */
856856 sql_cmd_status = PQcmdStatus (res );
857857 funcctx -> max_calls = 1 ;
858858 }
859859 else
860860 funcctx -> max_calls = PQntuples (res );
861-
861+
862862 /* got results, keep track of them */
863863 funcctx -> user_fctx = res ;
864-
864+
865865 /* if needed, close the connection to the database and cleanup */
866866 if (freeconn )
867867 PQfinish (conn );
868-
868+
869869 if (!is_sql_cmd )
870870 {
871871 /* get a tuple descriptor for our result type */
@@ -878,38 +878,41 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async, bool do_get)
878878 /* failed to determine actual type of RECORD */
879879 ereport (ERROR ,
880880 (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" )));
883883 break ;
884884 default :
885885 /* result type isn't composite */
886886 elog (ERROR , "return type must be a row type" );
887887 break ;
888888 }
889-
889+
890890 /* make sure we have a persistent copy of the tupdesc */
891891 tupdesc = CreateTupleDescCopy (tupdesc );
892892 }
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+ */
895898 if (PQnfields (res ) != tupdesc -> natts )
896899 ereport (ERROR ,
897900 (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+
901904 /* fast track when no results */
902905 if (funcctx -> max_calls < 1 )
903906 {
904907 if (res )
905908 PQclear (res );
906909 SRF_RETURN_DONE (funcctx );
907910 }
908-
911+
909912 /* store needed metadata for subsequent calls */
910913 attinmeta = TupleDescGetAttInMetadata (tupdesc );
911914 funcctx -> attinmeta = attinmeta ;
912-
915+
913916 MemoryContextSwitchTo (oldcontext );
914917 }
915918 else
@@ -991,9 +994,9 @@ PG_FUNCTION_INFO_V1(dblink_get_connections);
991994Datum
992995dblink_get_connections (PG_FUNCTION_ARGS )
993996{
994- HASH_SEQ_STATUS status ;
995- remoteConnHashEnt * hentry ;
996- ArrayBuildState * astate = NULL ;
997+ HASH_SEQ_STATUS status ;
998+ remoteConnHashEnt * hentry ;
999+ ArrayBuildState * astate = NULL ;
9971000
9981001 if (remoteConnHash )
9991002 {
@@ -1019,19 +1022,19 @@ dblink_get_connections(PG_FUNCTION_ARGS)
10191022 *
10201023 * Returns 1 if the connection is busy, 0 otherwise
10211024 * Params:
1022- * text connection_name - name of the connection to check
1023- *
1025+ * text connection_name - name of the connection to check
1026+ *
10241027 */
10251028PG_FUNCTION_INFO_V1 (dblink_is_busy );
10261029Datum
10271030dblink_is_busy (PG_FUNCTION_ARGS )
10281031{
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;
10351038
10361039 DBLINK_INIT ;
10371040 DBLINK_GET_CONN ;
@@ -1045,27 +1048,27 @@ dblink_is_busy(PG_FUNCTION_ARGS)
10451048/*
10461049 * Cancels a running request on a connection
10471050 *
1048- * Returns text:
1051+ * Returns text:
10491052 * "OK" if the cancel request has been sent correctly,
1050- * an error message otherwise
1051- *
1053+ * an error message otherwise
1054+ *
10521055 * Params:
1053- * text connection_name - name of the connection to check
1054- *
1056+ * text connection_name - name of the connection to check
1057+ *
10551058 */
10561059PG_FUNCTION_INFO_V1 (dblink_cancel_query );
10571060Datum
10581061dblink_cancel_query (PG_FUNCTION_ARGS )
10591062{
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 ];
10691072
10701073 DBLINK_INIT ;
10711074 DBLINK_GET_CONN ;
@@ -1077,7 +1080,7 @@ dblink_cancel_query(PG_FUNCTION_ARGS)
10771080 PQfreeCancel (cancel );
10781081
10791082 if (res == 0 )
1080- PG_RETURN_TEXT_P (GET_TEXT ("OK" ));
1083+ PG_RETURN_TEXT_P (GET_TEXT ("OK" ));
10811084 else
10821085 PG_RETURN_TEXT_P (GET_TEXT (errbuf ));
10831086}
@@ -1086,23 +1089,23 @@ dblink_cancel_query(PG_FUNCTION_ARGS)
10861089/*
10871090 * Get error message from a connection
10881091 *
1089- * Returns text:
1092+ * Returns text:
10901093 * "OK" if no error, an error message otherwise
1091- *
1094+ *
10921095 * Params:
1093- * text connection_name - name of the connection to check
1094- *
1096+ * text connection_name - name of the connection to check
1097+ *
10951098 */
10961099PG_FUNCTION_INFO_V1 (dblink_error_message );
10971100Datum
10981101dblink_error_message (PG_FUNCTION_ARGS )
10991102{
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;
11061109
11071110 DBLINK_INIT ;
11081111 DBLINK_GET_CONN ;
@@ -1859,7 +1862,7 @@ get_sql_delete(Oid relid, int2vector *pkattnums, int16 pknumatts, char **tgt_pka
18591862 char * relname ;
18601863 TupleDesc tupdesc ;
18611864 int natts ;
1862- StringInfoData buf ;
1865+ StringInfoData buf ;
18631866 int i ;
18641867
18651868 initStringInfo (& buf );
0 commit comments