@ -61,6 +61,7 @@
# include "utils/memutils.h"
# include "utils/rel.h"
# include "utils/varlena.h"
# include "utils/wait_event.h"
PG_MODULE_MAGIC ;
@ -133,6 +134,7 @@ static HTAB *remoteConnHash = NULL;
/* custom wait event values, retrieved from shared memory */
static uint32 dblink_we_connect = 0 ;
static uint32 dblink_we_get_conn = 0 ;
static uint32 dblink_we_get_result = 0 ;
/*
* Following is list that holds multiple remote connections .
@ -252,6 +254,9 @@ dblink_init(void)
{
if ( ! pconn )
{
if ( dblink_we_get_result = = 0 )
dblink_we_get_result = WaitEventExtensionNew ( " DblinkGetResult " ) ;
pconn = ( remoteConn * ) MemoryContextAlloc ( TopMemoryContext , sizeof ( remoteConn ) ) ;
pconn - > conn = NULL ;
pconn - > openCursorCount = 0 ;
@ -442,7 +447,7 @@ dblink_open(PG_FUNCTION_ARGS)
/* If we are not in a transaction, start one */
if ( PQtransactionStatus ( conn ) = = PQTRANS_IDLE )
{
res = PQ exec( conn , " BEGIN " ) ;
res = libpqsrv_ exec( conn , " BEGIN " , dblink_we_get_result ) ;
if ( PQresultStatus ( res ) ! = PGRES_COMMAND_OK )
dblink_res_internalerror ( conn , res , " begin error " ) ;
PQclear ( res ) ;
@ -461,7 +466,7 @@ dblink_open(PG_FUNCTION_ARGS)
( rconn - > openCursorCount ) + + ;
appendStringInfo ( & buf , " DECLARE %s CURSOR FOR %s " , curname , sql ) ;
res = PQ exec( conn , buf . data ) ;
res = libpqsrv_ exec( conn , buf . data , dblink_we_get_result ) ;
if ( ! res | | PQresultStatus ( res ) ! = PGRES_COMMAND_OK )
{
dblink_res_error ( conn , conname , res , fail ,
@ -530,7 +535,7 @@ dblink_close(PG_FUNCTION_ARGS)
appendStringInfo ( & buf , " CLOSE %s " , curname ) ;
/* close the cursor */
res = PQ exec( conn , buf . data ) ;
res = libpqsrv_ exec( conn , buf . data , dblink_we_get_result ) ;
if ( ! res | | PQresultStatus ( res ) ! = PGRES_COMMAND_OK )
{
dblink_res_error ( conn , conname , res , fail ,
@ -550,7 +555,7 @@ dblink_close(PG_FUNCTION_ARGS)
{
rconn - > newXactForCursor = false ;
res = PQ exec( conn , " COMMIT " ) ;
res = libpqsrv_ exec( conn , " COMMIT " , dblink_we_get_result ) ;
if ( PQresultStatus ( res ) ! = PGRES_COMMAND_OK )
dblink_res_internalerror ( conn , res , " commit error " ) ;
PQclear ( res ) ;
@ -632,7 +637,7 @@ dblink_fetch(PG_FUNCTION_ARGS)
* PGresult will be long - lived even though we are still in a short - lived
* memory context .
*/
res = PQ exec( conn , buf . data ) ;
res = libpqsrv_ exec( conn , buf . data , dblink_we_get_result ) ;
if ( ! res | |
( PQresultStatus ( res ) ! = PGRES_COMMAND_OK & &
PQresultStatus ( res ) ! = PGRES_TUPLES_OK ) )
@ -780,7 +785,7 @@ dblink_record_internal(FunctionCallInfo fcinfo, bool is_async)
else
{
/* async result retrieval, do it the old way */
PGresult * res = PQgetR esult( conn ) ;
PGresult * res = libpqsrv_get_r esult( conn , dblink_we_get_result ) ;
/* NULL means we're all done with the async results */
if ( res )
@ -1088,7 +1093,8 @@ materializeQueryResult(FunctionCallInfo fcinfo,
PQclear ( sinfo . last_res ) ;
PQclear ( sinfo . cur_res ) ;
/* and clear out any pending data in libpq */
while ( ( res = PQgetResult ( conn ) ) ! = NULL )
while ( ( res = libpqsrv_get_result ( conn , dblink_we_get_result ) ) ! =
NULL )
PQclear ( res ) ;
PG_RE_THROW ( ) ;
}
@ -1115,7 +1121,7 @@ storeQueryResult(volatile storeInfo *sinfo, PGconn *conn, const char *sql)
{
CHECK_FOR_INTERRUPTS ( ) ;
sinfo - > cur_res = PQgetR esult( conn ) ;
sinfo - > cur_res = libpqsrv_get_r esult( conn , dblink_we_get_result ) ;
if ( ! sinfo - > cur_res )
break ;
@ -1443,7 +1449,7 @@ dblink_exec(PG_FUNCTION_ARGS)
if ( ! conn )
dblink_conn_not_avail ( conname ) ;
res = PQ exec( conn , sql ) ;
res = libpqsrv_ exec( conn , sql , dblink_we_get_result ) ;
if ( ! res | |
( PQresultStatus ( res ) ! = PGRES_COMMAND_OK & &
PQresultStatus ( res ) ! = PGRES_TUPLES_OK ) )
@ -2739,8 +2745,8 @@ dblink_res_error(PGconn *conn, const char *conname, PGresult *res,
/*
* If we don ' t get a message from the PGresult , try the PGconn . This is
* needed because for connection - level failures , PQexec may just return
* NULL , not a PGresult at all .
* needed because for connection - level failures , PQgetResult may just
* return NULL , not a PGresult at all .
*/
if ( message_primary = = NULL )
message_primary = pchomp ( PQerrorMessage ( conn ) ) ;