@@ -1421,7 +1421,7 @@ postgresReScanForeignScan(ForeignScanState *node)
14211421 * We don't use a PG_TRY block here, so be careful not to throw error
14221422 * without releasing the PGresult.
14231423 */
1424- res = PQexec (fsstate -> conn ,sql );
1424+ res = pgfdw_exec_query (fsstate -> conn ,sql );
14251425if (PQresultStatus (res )!= PGRES_COMMAND_OK )
14261426pgfdw_report_error (ERROR ,res ,fsstate -> conn , true,sql );
14271427PQclear (res );
@@ -1749,18 +1749,24 @@ postgresExecForeignInsert(EState *estate,
17491749p_values = convert_prep_stmt_params (fmstate ,NULL ,slot );
17501750
17511751/*
1752- * Execute the prepared statement, and check for success.
1752+ * Execute the prepared statement.
1753+ */
1754+ if (!PQsendQueryPrepared (fmstate -> conn ,
1755+ fmstate -> p_name ,
1756+ fmstate -> p_nums ,
1757+ p_values ,
1758+ NULL ,
1759+ NULL ,
1760+ 0 ))
1761+ pgfdw_report_error (ERROR ,NULL ,fmstate -> conn , false,fmstate -> query );
1762+
1763+ /*
1764+ * Get the result, and check for success.
17531765 *
17541766 * We don't use a PG_TRY block here, so be careful not to throw error
17551767 * without releasing the PGresult.
17561768 */
1757- res = PQexecPrepared (fmstate -> conn ,
1758- fmstate -> p_name ,
1759- fmstate -> p_nums ,
1760- p_values ,
1761- NULL ,
1762- NULL ,
1763- 0 );
1769+ res = pgfdw_get_result (fmstate -> conn ,fmstate -> query );
17641770if (PQresultStatus (res )!=
17651771(fmstate -> has_returning ?PGRES_TUPLES_OK :PGRES_COMMAND_OK ))
17661772pgfdw_report_error (ERROR ,res ,fmstate -> conn , true,fmstate -> query );
@@ -1819,18 +1825,24 @@ postgresExecForeignUpdate(EState *estate,
18191825slot );
18201826
18211827/*
1822- * Execute the prepared statement, and check for success.
1828+ * Execute the prepared statement.
1829+ */
1830+ if (!PQsendQueryPrepared (fmstate -> conn ,
1831+ fmstate -> p_name ,
1832+ fmstate -> p_nums ,
1833+ p_values ,
1834+ NULL ,
1835+ NULL ,
1836+ 0 ))
1837+ pgfdw_report_error (ERROR ,NULL ,fmstate -> conn , false,fmstate -> query );
1838+
1839+ /*
1840+ * Get the result, and check for success.
18231841 *
18241842 * We don't use a PG_TRY block here, so be careful not to throw error
18251843 * without releasing the PGresult.
18261844 */
1827- res = PQexecPrepared (fmstate -> conn ,
1828- fmstate -> p_name ,
1829- fmstate -> p_nums ,
1830- p_values ,
1831- NULL ,
1832- NULL ,
1833- 0 );
1845+ res = pgfdw_get_result (fmstate -> conn ,fmstate -> query );
18341846if (PQresultStatus (res )!=
18351847(fmstate -> has_returning ?PGRES_TUPLES_OK :PGRES_COMMAND_OK ))
18361848pgfdw_report_error (ERROR ,res ,fmstate -> conn , true,fmstate -> query );
@@ -1889,18 +1901,24 @@ postgresExecForeignDelete(EState *estate,
18891901NULL );
18901902
18911903/*
1892- * Execute the prepared statement, and check for success.
1904+ * Execute the prepared statement.
1905+ */
1906+ if (!PQsendQueryPrepared (fmstate -> conn ,
1907+ fmstate -> p_name ,
1908+ fmstate -> p_nums ,
1909+ p_values ,
1910+ NULL ,
1911+ NULL ,
1912+ 0 ))
1913+ pgfdw_report_error (ERROR ,NULL ,fmstate -> conn , false,fmstate -> query );
1914+
1915+ /*
1916+ * Get the result, and check for success.
18931917 *
18941918 * We don't use a PG_TRY block here, so be careful not to throw error
18951919 * without releasing the PGresult.
18961920 */
1897- res = PQexecPrepared (fmstate -> conn ,
1898- fmstate -> p_name ,
1899- fmstate -> p_nums ,
1900- p_values ,
1901- NULL ,
1902- NULL ,
1903- 0 );
1921+ res = pgfdw_get_result (fmstate -> conn ,fmstate -> query );
19041922if (PQresultStatus (res )!=
19051923(fmstate -> has_returning ?PGRES_TUPLES_OK :PGRES_COMMAND_OK ))
19061924pgfdw_report_error (ERROR ,res ,fmstate -> conn , true,fmstate -> query );
@@ -1950,7 +1968,7 @@ postgresEndForeignModify(EState *estate,
19501968 * We don't use a PG_TRY block here, so be careful not to throw error
19511969 * without releasing the PGresult.
19521970 */
1953- res = PQexec (fmstate -> conn ,sql );
1971+ res = pgfdw_exec_query (fmstate -> conn ,sql );
19541972if (PQresultStatus (res )!= PGRES_COMMAND_OK )
19551973pgfdw_report_error (ERROR ,res ,fmstate -> conn , true,sql );
19561974PQclear (res );
@@ -2712,7 +2730,7 @@ get_remote_estimate(const char *sql, PGconn *conn,
27122730/*
27132731 * Execute EXPLAIN remotely.
27142732 */
2715- res = PQexec (conn ,sql );
2733+ res = pgfdw_exec_query (conn ,sql );
27162734if (PQresultStatus (res )!= PGRES_TUPLES_OK )
27172735pgfdw_report_error (ERROR ,res ,conn , false,sql );
27182736
@@ -2817,12 +2835,18 @@ create_cursor(ForeignScanState *node)
28172835 * parameter (see deparse.c), the "inference" is trivial and will produce
28182836 * the desired result. This allows us to avoid assuming that the remote
28192837 * server has the same OIDs we do for the parameters' types.
2838+ */
2839+ if (!PQsendQueryParams (conn ,buf .data ,numParams ,
2840+ NULL ,values ,NULL ,NULL ,0 ))
2841+ pgfdw_report_error (ERROR ,NULL ,conn , false,buf .data );
2842+
2843+ /*
2844+ * Get the result, and check for success.
28202845 *
28212846 * We don't use a PG_TRY block here, so be careful not to throw error
28222847 * without releasing the PGresult.
28232848 */
2824- res = PQexecParams (conn ,buf .data ,numParams ,NULL ,values ,
2825- NULL ,NULL ,0 );
2849+ res = pgfdw_get_result (conn ,buf .data );
28262850if (PQresultStatus (res )!= PGRES_COMMAND_OK )
28272851pgfdw_report_error (ERROR ,res ,conn , true,fsstate -> query );
28282852PQclear (res );
@@ -2868,7 +2892,7 @@ fetch_more_data(ForeignScanState *node)
28682892snprintf (sql ,sizeof (sql ),"FETCH %d FROM c%u" ,
28692893fsstate -> fetch_size ,fsstate -> cursor_number );
28702894
2871- res = PQexec (conn ,sql );
2895+ res = pgfdw_exec_query (conn ,sql );
28722896/* On error, report the original query, not the FETCH. */
28732897if (PQresultStatus (res )!= PGRES_TUPLES_OK )
28742898pgfdw_report_error (ERROR ,res ,conn , false,fsstate -> query );
@@ -2978,7 +3002,7 @@ close_cursor(PGconn *conn, unsigned int cursor_number)
29783002 * We don't use a PG_TRY block here, so be careful not to throw error
29793003 * without releasing the PGresult.
29803004 */
2981- res = PQexec (conn ,sql );
3005+ res = pgfdw_exec_query (conn ,sql );
29823006if (PQresultStatus (res )!= PGRES_COMMAND_OK )
29833007pgfdw_report_error (ERROR ,res ,conn , true,sql );
29843008PQclear (res );
@@ -3006,16 +3030,21 @@ prepare_foreign_modify(PgFdwModifyState *fmstate)
30063030 * with the remote server using different type OIDs than we do. All of
30073031 * the prepared statements we use in this module are simple enough that
30083032 * the remote server will make the right choices.
3033+ */
3034+ if (!PQsendPrepare (fmstate -> conn ,
3035+ p_name ,
3036+ fmstate -> query ,
3037+ 0 ,
3038+ NULL ))
3039+ pgfdw_report_error (ERROR ,NULL ,fmstate -> conn , false,fmstate -> query );
3040+
3041+ /*
3042+ * Get the result, and check for success.
30093043 *
30103044 * We don't use a PG_TRY block here, so be careful not to throw error
30113045 * without releasing the PGresult.
30123046 */
3013- res = PQprepare (fmstate -> conn ,
3014- p_name ,
3015- fmstate -> query ,
3016- 0 ,
3017- NULL );
3018-
3047+ res = pgfdw_get_result (fmstate -> conn ,fmstate -> query );
30193048if (PQresultStatus (res )!= PGRES_COMMAND_OK )
30203049pgfdw_report_error (ERROR ,res ,fmstate -> conn , true,fmstate -> query );
30213050PQclear (res );
@@ -3147,12 +3176,18 @@ execute_dml_stmt(ForeignScanState *node)
31473176 * parameter (see deparse.c), the "inference" is trivial and will produce
31483177 * the desired result. This allows us to avoid assuming that the remote
31493178 * server has the same OIDs we do for the parameters' types.
3179+ */
3180+ if (!PQsendQueryParams (dmstate -> conn ,dmstate -> query ,numParams ,
3181+ NULL ,values ,NULL ,NULL ,0 ))
3182+ pgfdw_report_error (ERROR ,NULL ,dmstate -> conn , false,dmstate -> query );
3183+
3184+ /*
3185+ * Get the result, and check for success.
31503186 *
31513187 * We don't use a PG_TRY block here, so be careful not to throw error
31523188 * without releasing the PGresult.
31533189 */
3154- dmstate -> result = PQexecParams (dmstate -> conn ,dmstate -> query ,
3155- numParams ,NULL ,values ,NULL ,NULL ,0 );
3190+ dmstate -> result = pgfdw_get_result (dmstate -> conn ,dmstate -> query );
31563191if (PQresultStatus (dmstate -> result )!=
31573192(dmstate -> has_returning ?PGRES_TUPLES_OK :PGRES_COMMAND_OK ))
31583193pgfdw_report_error (ERROR ,dmstate -> result ,dmstate -> conn , true,
@@ -3355,7 +3390,7 @@ postgresAnalyzeForeignTable(Relation relation,
33553390/* In what follows, do not risk leaking any PGresults. */
33563391PG_TRY ();
33573392{
3358- res = PQexec (conn ,sql .data );
3393+ res = pgfdw_exec_query (conn ,sql .data );
33593394if (PQresultStatus (res )!= PGRES_TUPLES_OK )
33603395pgfdw_report_error (ERROR ,res ,conn , false,sql .data );
33613396
@@ -3449,7 +3484,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
34493484/* In what follows, do not risk leaking any PGresults. */
34503485PG_TRY ();
34513486{
3452- res = PQexec (conn ,sql .data );
3487+ res = pgfdw_exec_query (conn ,sql .data );
34533488if (PQresultStatus (res )!= PGRES_COMMAND_OK )
34543489pgfdw_report_error (ERROR ,res ,conn , false,sql .data );
34553490PQclear (res );
@@ -3500,7 +3535,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
35003535snprintf (fetch_sql ,sizeof (fetch_sql ),"FETCH %d FROM c%u" ,
35013536fetch_size ,cursor_number );
35023537
3503- res = PQexec (conn ,fetch_sql );
3538+ res = pgfdw_exec_query (conn ,fetch_sql );
35043539/* On error, report the original query, not the FETCH. */
35053540if (PQresultStatus (res )!= PGRES_TUPLES_OK )
35063541pgfdw_report_error (ERROR ,res ,conn , false,sql .data );
@@ -3675,7 +3710,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
36753710appendStringInfoString (& buf ,"SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = " );
36763711deparseStringLiteral (& buf ,stmt -> remote_schema );
36773712
3678- res = PQexec (conn ,buf .data );
3713+ res = pgfdw_exec_query (conn ,buf .data );
36793714if (PQresultStatus (res )!= PGRES_TUPLES_OK )
36803715pgfdw_report_error (ERROR ,res ,conn , false,buf .data );
36813716
@@ -3774,7 +3809,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
37743809appendStringInfoString (& buf ," ORDER BY c.relname, a.attnum" );
37753810
37763811/* Fetch the data */
3777- res = PQexec (conn ,buf .data );
3812+ res = pgfdw_exec_query (conn ,buf .data );
37783813if (PQresultStatus (res )!= PGRES_TUPLES_OK )
37793814pgfdw_report_error (ERROR ,res ,conn , false,buf .data );
37803815