@@ -1088,7 +1088,7 @@ postgresReScanForeignScan(ForeignScanState *node)
1088
1088
* We don't use a PG_TRY block here, so be careful not to throw error
1089
1089
* without releasing the PGresult.
1090
1090
*/
1091
- res = PQexec (fsstate -> conn , sql );
1091
+ res = pgfdw_exec_query (fsstate -> conn , sql );
1092
1092
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
1093
1093
pgfdw_report_error (ERROR , res , fsstate -> conn , true, sql );
1094
1094
PQclear (res );
@@ -1425,18 +1425,24 @@ postgresExecForeignInsert(EState *estate,
1425
1425
p_values = convert_prep_stmt_params (fmstate , NULL , slot );
1426
1426
1427
1427
/*
1428
- * Execute the prepared statement, and check for success.
1428
+ * Execute the prepared statement.
1429
+ */
1430
+ if (!PQsendQueryPrepared (fmstate -> conn ,
1431
+ fmstate -> p_name ,
1432
+ fmstate -> p_nums ,
1433
+ p_values ,
1434
+ NULL ,
1435
+ NULL ,
1436
+ 0 ))
1437
+ pgfdw_report_error (ERROR , NULL , fmstate -> conn , false, fmstate -> query );
1438
+
1439
+ /*
1440
+ * Get the result, and check for success.
1429
1441
*
1430
1442
* We don't use a PG_TRY block here, so be careful not to throw error
1431
1443
* without releasing the PGresult.
1432
1444
*/
1433
- res = PQexecPrepared (fmstate -> conn ,
1434
- fmstate -> p_name ,
1435
- fmstate -> p_nums ,
1436
- p_values ,
1437
- NULL ,
1438
- NULL ,
1439
- 0 );
1445
+ res = pgfdw_get_result (fmstate -> conn , fmstate -> query );
1440
1446
if (PQresultStatus (res ) !=
1441
1447
(fmstate -> has_returning ? PGRES_TUPLES_OK : PGRES_COMMAND_OK ))
1442
1448
pgfdw_report_error (ERROR , res , fmstate -> conn , true, fmstate -> query );
@@ -1495,18 +1501,24 @@ postgresExecForeignUpdate(EState *estate,
1495
1501
slot );
1496
1502
1497
1503
/*
1498
- * Execute the prepared statement, and check for success.
1504
+ * Execute the prepared statement.
1505
+ */
1506
+ if (!PQsendQueryPrepared (fmstate -> conn ,
1507
+ fmstate -> p_name ,
1508
+ fmstate -> p_nums ,
1509
+ p_values ,
1510
+ NULL ,
1511
+ NULL ,
1512
+ 0 ))
1513
+ pgfdw_report_error (ERROR , NULL , fmstate -> conn , false, fmstate -> query );
1514
+
1515
+ /*
1516
+ * Get the result, and check for success.
1499
1517
*
1500
1518
* We don't use a PG_TRY block here, so be careful not to throw error
1501
1519
* without releasing the PGresult.
1502
1520
*/
1503
- res = PQexecPrepared (fmstate -> conn ,
1504
- fmstate -> p_name ,
1505
- fmstate -> p_nums ,
1506
- p_values ,
1507
- NULL ,
1508
- NULL ,
1509
- 0 );
1521
+ res = pgfdw_get_result (fmstate -> co
1241
nn , fmstate -> query );
1510
1522
if (PQresultStatus (res ) !=
1511
1523
(fmstate -> has_returning ? PGRES_TUPLES_OK : PGRES_COMMAND_OK ))
1512
1524
pgfdw_report_error (ERROR , res , fmstate -> conn , true, fmstate -> query );
@@ -1565,18 +1577,24 @@ postgresExecForeignDelete(EState *estate,
1565
1577
NULL );
1566
1578
1567
1579
/*
1568
- * Execute the prepared statement, and check for success.
1580
+ * Execute the prepared statement.
1581
+ */
1582
+ if (!PQsendQueryPrepared (fmstate -> conn ,
1583
+ fmstate -> p_name ,
1584
+ fmstate -> p_nums ,
1585
+ p_values ,
1586
+ NULL ,
1587
+ NULL ,
1588
+ 0 ))
1589
+ pgfdw_report_error (ERROR , NULL , fmstate -> conn , false, fmstate -> query );
1590
+
1591
+ /*
1592
+ * Get the result, and check for success.
1569
1593
*
1570
1594
* We don't use a PG_TRY block here, so be careful not to throw error
1571
1595
* without releasing the PGresult.
1572
1596
*/
1573
- res = PQexecPrepared (fmstate -> conn ,
1574
- fmstate -> p_name ,
1575
- fmstate -> p_nums ,
1576
- p_values ,
1577
- NULL ,
1578
- NULL ,
1579
- 0 );
1597
+ res = pgfdw_get_result (fmstate -> conn , fmstate -> query );
1580
1598
if (PQresultStatus (res ) !=
1581
1599
(fmstate -> has_returning ? PGRES_TUPLES_OK : PGRES_COMMAND_OK ))
1582
1600
pgfdw_report_error (ERROR , res , fmstate -> conn , true, fmstate -> query );
@@ -1626,7 +1644,7 @@ postgresEndForeignModify(EState *estate,
1626
1644
* We don't use a PG_TRY block here, so be careful not to throw error
1627
1645
* without releasing the PGresult.
1628
1646
*/
1629
- res = PQexec (fmstate -> conn , sql );
1647
+ res = pgfdw_exec_query (fmstate -> conn , sql );
1630
1648
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
1631
1649
pgfdw_report_error (ERROR , res , fmstate -> conn , true, sql );
1632
1650
PQclear (res );
@@ -1884,7 +1902,7 @@ get_remote_estimate(const char *sql, PGconn *conn,
1884
1902
/*
1885
1903
* Execute EXPLAIN remotely.
1886
1904
*/
1887
- res = PQexec (conn , sql );
1905
+ res = pgfdw_exec_query (conn , sql );
1888
1906
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
1889
1907
pgfdw_report_error (ERROR , res , conn , false, sql );
1890
1908
@@ -2013,12 +2031,18 @@ create_cursor(ForeignScanState *node)
2013
2031
* parameter (see deparse.c), the "inference" is trivial and will produce
2014
2032
* the desired result. This allows us to avoid assuming that the remote
2015
2033
* server has the same OIDs we do for the parameters' types.
2034
+ */
2035
+ if (!PQsendQueryParams (conn , buf .data , numParams ,
2036
+ NULL , values , NULL , NULL , 0 ))
2037
+ pgfdw_report_error (ERROR , NULL , conn , false, buf .data );
2038
+
2039
+ /*
2040
+ * Get the result, and check for success.
2016
2041
*
2017
2042
* We don't use a PG_TRY block here, so be careful not to throw error
2018
2043
* without releasing the PGresult.
2019
2044
*/
2020
- res = PQexecParams (conn , buf .data , numParams , NULL , values ,
2021
- NULL , NULL , 0 );
2045
+ res = pgfdw_get_result (conn , buf .data );
2022
2046
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
2023
2047
pgfdw_report_error (ERROR , res , conn , true, fsstate -> query );
2024
2048
PQclear (res );
@@ -2068,7 +2092,7 @@ fetch_more_data(ForeignScanState *node)
2068
2092
snprintf (sql , sizeof (sql ), "FETCH %d FROM c%u" ,
2069
2093
fetch_size , fsstate -> cursor_number );
2070
2094
2071
- res = PQexec (conn , sql );
2095
+ res = pgfdw_exec_query (conn , sql );
2072
2096
/* On error, report the original query, not the FETCH. */
2073
2097
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
2074
2098
pgfdw_report_error (ERROR , res , conn , false, fsstate -> query );
@@ -2175,7 +2199,7 @@ close_cursor(PGconn *conn, unsigned int cursor_number)
2175
2199
* We don't use a PG_TRY block here, so be careful not to throw error
2176
2200
* without releasing the PGresult.
2177
2201
*/
2178
- res = PQexec (conn , sql );
2202
+ res = pgfdw_exec_query (conn , sql );
2179
2203
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
2180
2204
pgfdw_report_error (ERROR , res , conn , true, sql );
2181
2205
PQclear (res );
@@ -2203,16 +2227,21 @@ prepare_foreign_modify(PgFdwModifyState *fmstate)
2203
2227
* with the remote server using different type OIDs than we do. All of
2204
2228
* the prepared statements we use in this module are simple enough that
2205
2229
* the remote server will make the right choices.
2230
+ */
2231
+ if (!PQsendPrepare (fmstate -> conn ,
2232
+ p_name ,
2233
+ fmstate -> query ,
2234
+ 0 ,
2235
+ NULL ))
2236
+ pgfdw_report_error (ERROR , NULL , fmstate -> conn , false, fmstate -> query );
2237
+
2238
+ /*
2239
+ * Get the result, and check for success.
2206
2240
*
2207
2241
* We don't use a PG_TRY block here, so be careful not to throw error
2208
2242
* without releasing the PGresult.
2209
2243
*/
2210
- res = PQprepare (fmstate -> conn ,
2211
- p_name ,
2212
- fmstate -> query ,
2213
- 0 ,
2214
- NULL );
2215
-
2244
+ res = pgfdw_get_result (fmstate -> conn , fmstate -> query );
2216
2245
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
2217
2246
pgfdw_report_error (ERROR , res , fmstate -> conn , true, fmstate -> query );
2218
2247
PQclear (res );
@@ -2361,7 +2390,7 @@ postgresAnalyzeForeignTable(Relation relation,
2361
2390
/* In what follows, do not risk leaking any PGresults. */
2362
2391
PG_TRY ();
2363
2392
{
2364
- res = PQexec (conn , sql .data );
2393
+ res = pgfdw_exec_query (conn , sql .data );
2365
2394
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
2366
2395
pgfdw_report_error (ERROR , res , conn , false, sql .data );
2367
2396
@@ -2455,7 +2484,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
2455
2484
/* In what follows, do not risk leaking any PGresults. */
2456
2485
PG_TRY ();
2457
2486
{
2458
- res = PQexec (conn , sql .data );
2487
+ res = pgfdw_exec_query (conn , sql .data );
2459
2488
if (PQresultStatus (res ) != PGRES_COMMAND_OK )
2460
2489
pgfdw_report_error (ERROR , res , conn , false, sql .data );
2461
2490
PQclear (res );
@@ -2485,7 +2514,7 @@ postgresAcquireSampleRowsFunc(Relation relation, int elevel,
2485
2514
snprintf (fetch_sql , sizeof (fetch_sql ), "FETCH %d FROM c%u" ,
2486
2515
fetch_size , cursor_number );
2487
2516
2488
- res = PQexec (conn , fetch_sql );
2517
+ res = pgfdw_exec_query (conn , fetch_sql );
2489
2518
/* On error, report the original query, not the FETCH. */
2490
2519
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
2491
2520
pgfdw_report_error (ERROR , res , conn , false, sql .data );
@@ -2659,7 +2688,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
2659
2688
appendStringInfoString (& buf , "SELECT 1 FROM pg_catalog.pg_namespace WHERE nspname = " );
2660
2689
deparseStringLiteral (& buf , stmt -> remote_schema );
2661
2690
2662
- res = PQexec (conn , buf .data );
2691
+ res = pgfdw_exec_query (conn , buf .data );
2663
2692
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
2664
2693
pgfdw_report_error (ERROR , res , conn , false, buf .data );
2665
2694
@@ -2758,7 +2787,7 @@ postgresImportForeignSchema(ImportForeignSchemaStmt *stmt, Oid serverOid)
2758
2787
appendStringInfoString (& buf , " ORDER BY c.relname, a.attnum" );
2759
2788
2760
2789
/* Fetch the data */
2761
- res = PQexec (conn , buf .data );
2790
+ res = pgfdw_exec_query (conn , buf .data );
2762
2791
if (PQresultStatus (res ) != PGRES_TUPLES_OK )
2763
2792
pgfdw_report_error (ERROR , res , conn , false, buf .data );
2764
2793
0 commit comments