mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
ext/pgsql: adding pg_close_stmt.
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 GH-14584
This commit is contained in:
parent
291eef285c
commit
1da352c367
7 changed files with 98 additions and 1 deletions
|
@ -6256,3 +6256,39 @@ PHP_FUNCTION(pg_set_chunked_rows_size)
|
|||
RETURN_BOOL(PQsetChunkedRowsMode(link->conn, (int)size) == 1);
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(HAVE_PG_CLOSE_STMT)
|
||||
PHP_FUNCTION(pg_close_stmt)
|
||||
{
|
||||
zval *pgsql_link;
|
||||
pgsql_link_handle *link;
|
||||
PGresult *pgsql_result;
|
||||
zend_string *stmt;
|
||||
|
||||
ZEND_PARSE_PARAMETERS_START(2, 2)
|
||||
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
|
||||
Z_PARAM_STR(stmt)
|
||||
ZEND_PARSE_PARAMETERS_END();
|
||||
|
||||
if (ZSTR_LEN(stmt) == 0) {
|
||||
zend_argument_value_error(2, "cannot be empty");
|
||||
RETURN_THROWS();
|
||||
}
|
||||
|
||||
link = Z_PGSQL_LINK_P(pgsql_link);
|
||||
CHECK_PGSQL_LINK(link);
|
||||
|
||||
pgsql_result = PQclosePrepared(link->conn, ZSTR_VAL(stmt));
|
||||
|
||||
if (PQresultStatus(pgsql_result) != PGRES_COMMAND_OK) {
|
||||
RETURN_FALSE;
|
||||
} else {
|
||||
pgsql_result_handle *pg_handle;
|
||||
object_init_ex(return_value, pgsql_result_ce);
|
||||
pg_handle = Z_PGSQL_RESULT_P(return_value);
|
||||
pg_handle->conn = link->conn;
|
||||
pg_handle->result = pgsql_result;
|
||||
pg_handle->row = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue