@@ -1066,7 +1066,7 @@ postgresReScanForeignScan(ForeignScanState *node)
1066
1066
* We don't use a PG_TRY block here, so be careful not to throw error
1067
1067
* without releasing the PGresult.
1068
1068
*/
1069
- res = PQexec (fsstate -> conn , sql );
1069
+ res = pgfdw_exec_query (fsstate -> conn , sql );
1070
1070
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
1071
1071
pgfdw_report_error (ERROR , res , fsstate -> conn , true, sql );
1072
1072
PQclear (res );
@@ -1388,18 +1388,24 @@ postgresExecForeignInsert(EState *estate,
1388
1388
p_values = convert_prep_stmt_params (fmstate , NULL , slot );
1389
1389
1390
1390
/*
1391
- * Execute the prepared statement, and check for success.
1391
+ * Execute the prepared statement.
1392
+ */
1393
+ if (!PQsendQueryPrepared (fmstate -> conn ,
1394
+ fmstate -> p_name ,
1395
+ fmstate -> p_nums ,
1396
+ p_values ,
1397
+ NULL ,
1398
+ NULL ,
1399
+ 0 ))
1400
+ pgfdw_report_error (ERROR , NULL , fmstate -> conn , false, fmstate -> query );
1401
+
1402
+ /*
1403
+ * Get the result, and check for success.
1392
1404
*
1393
1405
* We don't use a PG_TRY block here, so be careful not to throw error
1394
1406
* without releasing the PGresult.
1395
1407
*/
1396
- res = PQexecPrepared (fmstate -> conn ,
1397
- fmstate -> p_name ,
1398
- fmstate -> p_nums ,
1399
- p_values ,
1400
- NULL ,
1401
- NULL ,
1402
- 0 );
1408
+ res = pgfdw_get_result (fmstate -> conn , fmstate -> query );
1403
1409
if (PQresultStatus (res ) !=
1404
1410
(fmstate -> has_returning ? PGRES_TUPLES_OK : PGRES_COMMAND_OK ))
1405
1411
pgfdw_report_error (ERROR , res , fmstate -> conn , true, fmstate -> query );
@@ -1458,18 +1464,24 @@ postgresExecForeignUpdate(EState *estate,
1458
1464
slot );
1459
1465
1460
1466
/*
1461
- * Execute the prepared statement, and check for success.
1467
+ * Execute the prepared statement.
1468
+ */
1469
+ if (!PQsendQueryPrepared (fmstate -> conn ,
1470
+ fmstate -> p_name ,
1471
+ fmstate -> p_nums ,
1472
+ p_values ,
1473
+ NULL ,
1474
+ NULL ,
1475
+ 0 ))
1476
+ pgfdw_report_error (ERROR , NULL , fmstate -> conn , false, fmstate -> query );
1477
+
1478
+ /*
1479
+ * Get the result, and check for success.
1462
1480
*
1463
1481
* We don't use a PG_TRY block here, so be careful not to throw error
1464
1482
* without releasing the PGresult.
1465
1483
*/
1466
- res = PQexecPrepared (fmstate -> conn ,
1467
- fmstate -> p_name ,
1468
- fmstate -> p_nums ,
1469
- p_values ,
1470
- NULL ,
1471
- NULL ,
1472
- 0 );
1484
+ res = pgfdw_get_result (fmstate -> conn , fmstate -> query );
1473
1485
if (PQresultStatus (res ) !=
1474
1486
(fmstate -> has_returning ? PGRES_TUPLES_OK : PGRES_COMMAND_OK ))
1475
1487
pgfdw_report_error (ERROR , res , fmstate -> conn , true, fmstate -> query );
@@ -1528,18 +1540,24 @@ postgresExecForeignDelete(EState *estate,
1528
1540
NULL );
1529
1541
1530
1542
/*
1531
- * Execute the prepared statement, and check for success.
1543
+ * Execute the prepared statement.
1544
+ */
1545
+ if (!PQsendQueryPrepared (fmstate -> conn ,
1546
+ fmstate -> p_name ,
1547
+ fmstate -> p_nums ,
1548
+ p_values ,
1549
+ NULL ,
1550
+ NULL ,
1551
+ 0 ))
1552
+ pgfdw_report_error (ERROR , NULL , fmstate -> conn , false, fmstate -> query );
1553
+
1554
+ /*
1555
+ * Get the result, and check for success.
1532
1556
*
1533
1557
* We don't use a PG_TRY block here, so be careful not to throw error
1534
1558
* without releasing the PGresult.
1535
1559
*/
1536
- res = PQexecPrepared (fmstate -> conn ,
1537
- fmstate -> p_name ,
1538
- fmstate -> p_nums ,
1539
- p_values ,
1540
- NULL ,
1541
- NULL ,
1542
- 0 );
1560
+ res = pgfdw_get_result (fmstate -> conn , fmstate -> query );
1543
1561
if (PQresultStatus (res ) !=
1544
1562
(fmstate -> has_returning ? PGRES_TUPLES_OK : PGRES_COMMAND_OK ))
1545
1563
pgfdw_report_error (ERROR , res , fmstate -> conn , true, fmstate -> query );
@@ -1589,7 +1607,7 @@ postgresEndForeignModify(EState *estate,
1589
1607
* We don't use a PG_TRY block here, so be careful not to throw error
1590
1608
* without releasing the PGresult.
1591
1609
*/
1592
- res = PQexec (fmstate -> conn , sql );
1610
+ res = pgfdw_exec_query (fmstate -> conn , sql );
1593
1611
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
1594
1612
pgfdw_report_error (ERROR , res , fmstate -> conn , true, sql );
1595
1613
PQclear (res );
@@ -1847,7 +1865,7 @@ get_remote_estimate(const char *sql, PGconn *conn,
1847
1865
/*
1848
1866
* Execute EXPLAIN remotely.
1849
1867
*/
1850
- res = PQexec (conn , sql );
1868
+ res = pgfdw_exec_query (conn , sql );
1851
1869
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
1852
1870
pgfdw_report_error (ERROR , res , conn , false, sql );
1853
1871
@@ -1976,12 +1994,18 @@ create_cursor(ForeignScanState *node)
1976
1994
* parameter (see deparse.c), the "inference" is trivial and will produce
1977
1995
* the desired result. This allows us to avoid assuming that the remote
1978
1996
* server has the same OIDs we do for the parameters' types.
1997
+ */
1998
+ if (!PQsendQueryParams (conn , buf .data , numParams ,
1999
+ NULL , values , NULL , NULL , 0 ))
2000
+ pgfdw_report_error (ERROR , NULL , conn , false, buf .data );
2001
+
2002
+ /*
2003
+ * Get the result, and check for success.
1979
2004
*
1980
2005
* We don't use a PG_TRY block here, so be careful not to throw error
1981
2006
* without releasing the PGresult.
1982
2007
*/
1983
- res = PQexecParams (conn , buf .data , numParams , NULL , values ,
1984
- NULL , NULL , 0 );
2008
+ res = pgfdw_get_result (conn , buf .data );
1985
2009
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
1986
2010
pgfdw_report_error (ERROR , res , conn , true, fsstate -> query );
1987
2011
PQclear (res );
@@ -2031,7 +2055,7 @@ fetch_more_data(ForeignScanState *node)
2031
2055
snprintf (sql , sizeof (sql ), "FETCH %d FROM c%u" ,
2032
2056
fetch_size , fsstate -> cursor_number );
2033
2057
2034
- res = PQexec (conn , sql );
2058
+ res = pgfdw_exec_query (conn , sql );
2035
2059
/* On error, report the original query, not the FETCH. */
2036
2060
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
2037
2061
pgfdw_report_error (ERROR , res , conn , false, fsstate -> query );
@@ -2138,7 +2162,7 @@ close_cursor(PGconn *conn, unsigned int cursor_number)
2138
2162
* We don't use a PG_TRY block here, so be careful not to throw error
2139
2163
* without releasing the PGresult.
2140
2164
*/
2141
- res = PQexec (conn , sql );
2165
+ res = pgfdw_exec_query (conn , sql );
2142
2166
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
2143
2167
pgfdw_report_error (ERROR , res , conn , true, sql );
2144
2168
PQclear (res );
@@ -2166,16 +2190,21 @@ prepare_foreign_modify(PgFdwModifyState *fmstate)
2166
2190
* with the remote server using different type OIDs than we do. All of
2167
2191
* the prepared statements we use in this module are simple enough that
2168
2192
* the remote server will make the right choices.
2193
+ */
2194
+ if (!PQsendPrepare (fmstate -> conn ,
2195
+ p_name ,
2196
+ fmstate -> query ,
2197
+ 0 ,
2198
+ NULL ))
2199
+ pgfdw_report_error (ERROR , NULL , fmstate -> conn , false, fmstate -> query );
2200
+
2201
+ /*
2202
+ * Get the result, and check for success.
2169
2203
*
2170
2204
* We don't use a PG_TRY block here, so be careful not to throw error
2171
2205
* without releasing the PGresult.
2172
2206
*/
2173
- res = PQprepare (fmstate -> conn ,
2174
- p_name ,
2175
- fmstate -> query ,
2176
- 0 ,
2177
- NULL );
2178
-
2207
+ res = pgfdw_get_result (fmstate -> conn , fmstate -> query );
2179
2208
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
2180
2209
pgfdw_report_error (ERROR , res , fmstate -> conn , true, fmstate -> query );
2181
2210
PQclear (res );
@@ -2325,7 +2354,7 @@ postgresAnalyzeForeignTable(Relation relation,
2325
2354
/* In what follows, do not risk leaking any PGresults. */
2326
2355
PG_TRY ();
2327
2356
{
2328
- res = PQexec (conn , sql .data );
2357
+ res = pgfdw_exec_query (conn , sql .data );
2329
2358
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
2330
2359
pgfdw_report_error (ERROR , res , conn , false, sql .data );
2331
2360
@@ -2419,7 +2448,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
2419
2448
/* In what follows, do not risk leaking any PGresults. */
2420
2449
PG_TRY ();
2421
2450
{
2422
- res = PQexec (conn , sql .data );
2451
+ res = pgfdw_exec_query (conn , sql .data );
2423
2452
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
2424
2453
pgfdw_report_error (ERROR , res , conn , false, sql .data );
2425
2454
PQclear (res );
@@ -2449,7 +2478,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
2449
2478
snprintf (fetch_sql , sizeof (fetch_sql ), "FETCH %d FROM c%u" ,
2450
2479
fetch_size , cursor_number );
2451
2480
2452
- res = PQexec (conn , fetch_sql );
2481
+ res = pgfdw_exec_query (conn , fetch_sql );
2453
2482
/* On error, report the original query, not the FETCH. */
2454
2483
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
2455
2484
pgfdw_report_error (ERROR , res , conn , false, sql .data );
0 commit comments