Skip to content

Commit 72ec12b

Browse files
committed
ext/pgsql: adding postgresql 17 new libpq wrapper call.
pg_set_chunked_rows_mode to allow to fetch results in chunk of max N rows.
1 parent 2bb8fbd commit 72ec12b

File tree

4 files changed

+50
-8
lines changed

4 files changed

+50
-8
lines changed

ext/pgsql/config.m4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ if test "$PHP_PGSQL" != "no"; then
7070
AC_CHECK_LIB(pq, PQresultMemorySize, AC_DEFINE(HAVE_PG_RESULT_MEMORY_SIZE,1,[PostgreSQL 12 or later]))
7171
AC_CHECK_LIB(pq, PQchangePassword, AC_DEFINE(HAVE_PG_CHANGE_PASSWORD,1,[PostgreSQL 17 or later]))
7272
AC_CHECK_LIB(pq, PQsocketPoll, AC_DEFINE(HAVE_PG_SOCKET_POLL,1,[PostgreSQL 17 or later]))
73+
AC_CHECK_LIB(pq, PQsetChunkedRowsMode, AC_DEFINE(HAVE_PG_SET_CHUNKED_ROWS_MODE,1,[PostgreSQL 17 or later]))
7374

7475
dnl Available since PostgreSQL 12.
7576
AC_CACHE_CHECK([if PGVerbosity enum has PQERRORS_SQLSTATE],

ext/pgsql/pgsql.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,7 @@
4040
#include "php_globals.h"
4141
#include "zend_exceptions.h"
4242
#include "zend_attributes.h"
43-
#if !defined(HAVE_PG_SOCKET_POLL)
4443
#include "php_network.h"
45-
#endif
4644

4745
#ifdef HAVE_PGSQL
4846

@@ -935,16 +933,16 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
935933
array_init(return_value);
936934
res = PQexec(pgsql, "SHOW jit_provider");
937935
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
938-
add_assoc_null(return_value, "jit_provider");
936+
add_assoc_null(return_value, "jit_provider");
939937
} else {
940-
add_assoc_string(return_value, "jit_provider", PQgetvalue(res, 0, 0));
938+
add_assoc_string(return_value, "jit_provider", PQgetvalue(res, 0, 0));
941939
}
942940
PQclear(res);
943941
res = PQexec(pgsql, "SHOW jit");
944942
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
945-
add_assoc_null(return_value, "jit");
943+
add_assoc_null(return_value, "jit");
946944
} else {
947-
add_assoc_string(return_value, "jit", PQgetvalue(res, 0, 0));
945+
add_assoc_string(return_value, "jit", PQgetvalue(res, 0, 0));
948946
}
949947
PQclear(res);
950948
return;
@@ -4346,7 +4344,7 @@ static int php_pgsql_fd_cast(php_stream *stream, int cast_as, void **ret) /* {{{
43464344
}
43474345

43484346
if (ret) {
4349-
*(php_socket_t *)ret = fd_number;
4347+
*(php_socket_t *)ret = fd_number;
43504348
}
43514349
}
43524350
return SUCCESS;
@@ -6248,3 +6246,29 @@ PHP_FUNCTION(pg_socket_poll)
62486246

62496247
RETURN_LONG((zend_long)PQsocketPoll(socket, (int)read, (int)write, (int)ts));
62506248
}
6249+
6250+
#if defined(HAVE_PG_SET_CHUNKED_ROWS_MODE)
6251+
PHP_FUNCTION(pg_set_chunked_rows_mode)
6252+
{
6253+
zval *pgsql_link;
6254+
pgsql_link_handle *link;
6255+
zend_long size;
6256+
6257+
ZEND_PARSE_PARAMETERS_START(2, 2)
6258+
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
6259+
Z_PARAM_LONG(size)
6260+
ZEND_PARSE_PARAMETERS_END();
6261+
6262+
if (size < 1 || size > INT_MAX) {
6263+
zend_argument_value_error(2, "must be between 1 and %d", INT_MAX);
6264+
RETURN_THROWS();
6265+
}
6266+
6267+
link = Z_PGSQL_LINK_P(pgsql_link);
6268+
CHECK_PGSQL_LINK(link);
6269+
6270+
/** can still fail if it is not allowed e.g. already fetched results **/
6271+
6272+
RETURN_LONG((zend_long)PQsetChunkedRowsMode(link->conn, (int)size));
6273+
}
6274+
#endif

ext/pgsql/pgsql.stub.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,10 @@ function pg_put_copy_end(PgSql\Connection $connection, ?string $error = null): i
963963
* @param resource $socket
964964
*/
965965
function pg_socket_poll($socket, int $read, int $write, int $timeout = -1): int {}
966+
967+
#ifdef HAVE_PG_SET_CHUNKED_ROWS_MODE
968+
function pg_set_chunked_rows_mode(Pgsql\Connection $connection, int $size): int {}
969+
#endif
966970
}
967971

968972
namespace PgSql {

ext/pgsql/pgsql_arginfo.h

Lines changed: 14 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)