Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ext/pgsql: adding pg_close_stmt. #14584

Closed
wants to merge 2 commits into from
Closed

Conversation

devnexen
Copy link
Member

up to postgresql 17, when done with a prepared statement, we could release it with DEALLOCATE sql command which is fine ; until we want to implement a cache solution based on statement ids.

Since PostgreSQL 17, PQclosePrepared uses internally the close protocol allowing to reuse the statement name while still freeing it. Since the close protocol implementation had been added on libpq within this release, no way to reimplement it.

@@ -71,6 +71,7 @@ if test "$PHP_PGSQL" != "no"; then
AC_CHECK_LIB(pq, PQchangePassword, AC_DEFINE(HAVE_PG_CHANGE_PASSWORD,1,[PostgreSQL 17 or later]))
AC_CHECK_LIB(pq, PQsocketPoll, AC_DEFINE(HAVE_PG_SOCKET_POLL,1,[PostgreSQL 17 or later]))
AC_CHECK_LIB(pq, PQsetChunkedRowsMode, AC_DEFINE(HAVE_PG_SET_CHUNKED_ROWS_SIZE,1,[PostgreSQL 17 or later]))
AC_CHECK_LIB(pq, PQclosePrepared, AC_DEFINE(HAVE_PG_CLOSE_STMT,1,[PostgreSQL 17 or later]))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here, now you just need to do rebase against the master branch and check it like this:

 PHP_CHECK_LIBRARY([pq], [PQclosePrepared],
   [AC_DEFINE([HAVE_PG_CLOSE_STMT], [1], [PostgreSQL 17 or later])],,
   [$PGSQL_LIBS])

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

cool. I ll even wait your libpq bump merged.

@@ -974,6 +974,9 @@ function pg_socket_poll($socket, int $read, int $write, int $timeout = -1): int
#ifdef HAVE_PG_SET_CHUNKED_ROWS_SIZE
function pg_set_chunked_rows_size(Pgsql\Connection $connection, int $size): bool {}
#endif
#ifdef HAVE_PG_CLOSE_STMT
function pg_close_stmt(Pgsql\Connection $connection, string $stmt_name): Pgsql\Result|false {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$statement_name is the consistent param name with the existing params.

Suggested change
function pg_close_stmt(Pgsql\Connection $connection, string $stmt_name): Pgsql\Result|false {}
function pg_close_stmt(Pgsql\Connection $connection, string $statement_name): Pgsql\Result|false {}

Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 comments but seems reasonable otherwise

Comment on lines 6283 to 6285
if (!pgsql_result) {
RETURN_FALSE;
} else {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possibly?

Suggested change
if (!pgsql_result) {
RETURN_FALSE;
} else {
if (pgsql_result != PGRES_COMMAND_OK) {
RETURN_FALSE;
} else {

if (!pgsql_result) {
RETURN_FALSE;
} else {
pgsql_result_handle *pg_result;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable shadowing

up to postgresql 17, when done with a prepared statement, we could
release it with DEALLOCATE sql command which is fine ; until we want
to implement a cache solution based on statement ids.

Since PostgreSQL 17, PQclosePrepared uses internally the `close` protocol
allowing to reuse the statement name while still freeing it.
Since the close protocol implementation had been added on libpq within
this release, no way to reimplement it.
Copy link
Member

@Girgias Girgias left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't forget the UPGRADING entry :)

@devnexen devnexen closed this in 1da352c Sep 29, 2024
jorgsowa pushed a commit to jorgsowa/php-src that referenced this pull request Oct 1, 2024
up to postgresql 17, when done with a prepared statement, we could
release it with DEALLOCATE sql command which is fine ; until we want
to implement a cache solution based on statement ids.

Since PostgreSQL 17, PQclosePrepared uses internally the `close` protocol
allowing to reuse the statement name while still freeing it.
Since the close protocol implementation had been added on libpq within
this release, no way to reimplement it.

close phpGH-14584
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants