Skip to content

Commit 73b7485

Browse files
committed
GH-12940 ext/pdo_pgsql: using PQclosePrepared to free statement resources.
PQclosePrepared allows the statement's name to be reused thus allowing cache solutions to work properly ; whereas, for now, the `DEALLOCATE <statement>` query is used frees entirely the statement's resources.
1 parent 7ed21e6 commit 73b7485

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

ext/pdo_pgsql/config.m4

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,8 @@ if test "$PHP_PDO_PGSQL" != "no"; then
6868

6969
AC_CHECK_LIB(pq, PQlibVersion,, AC_MSG_ERROR([Unable to build the PDO PostgreSQL driver: at least libpq 9.1 is required]))
7070

71+
PHP_CHECK_FUNC(PQclosePrepared, pq)
72+
7173
LIBS=$old_LIBS
7274
LDFLAGS=$old_LDFLAGS
7375

ext/pdo_pgsql/pgsql_statement.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,12 +74,17 @@ static int pgsql_stmt_dtor(pdo_stmt_t *stmt)
7474
if (S->stmt_name) {
7575
if (S->is_prepared && server_obj_usable) {
7676
pdo_pgsql_db_handle *H = S->H;
77-
char *q = NULL;
7877
PGresult *res;
79-
78+
#ifndef HAVE_PQCLOSEPREPARED
79+
// TODO (??) libpq does not support close statement protocol < postgres 17
80+
// check if we can circumvent this.
81+
char *q = NULL;
8082
spprintf(&q, 0, "DEALLOCATE %s", S->stmt_name);
8183
res = PQexec(H->server, q);
8284
efree(q);
85+
#else
86+
res = PQclosePrepared(H->server, S->stmt_name);
87+
#endif
8388
if (res) {
8489
PQclear(res);
8590
}

0 commit comments

Comments
 (0)