Skip to content

ext/pgsql: adding postgresql 17 new libpq wrapper call. #14571

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

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ext/pgsql/config.m4
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ if test "$PHP_PGSQL" != "no"; then
AC_CHECK_LIB(pq, PQresultMemorySize, AC_DEFINE(HAVE_PG_RESULT_MEMORY_SIZE,1,[PostgreSQL 12 or later]))
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]))

dnl Available since PostgreSQL 12.
AC_CACHE_CHECK([if PGVerbosity enum has PQERRORS_SQLSTATE],
Expand Down
38 changes: 31 additions & 7 deletions ext/pgsql/pgsql.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@
#include "php_globals.h"
#include "zend_exceptions.h"
#include "zend_attributes.h"
#if !defined(HAVE_PG_SOCKET_POLL)
#include "php_network.h"
#endif

#ifdef HAVE_PGSQL

Expand Down Expand Up @@ -935,16 +933,16 @@ static void php_pgsql_get_link_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type
array_init(return_value);
res = PQexec(pgsql, "SHOW jit_provider");
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
add_assoc_null(return_value, "jit_provider");
add_assoc_null(return_value, "jit_provider");
} else {
add_assoc_string(return_value, "jit_provider", PQgetvalue(res, 0, 0));
add_assoc_string(return_value, "jit_provider", PQgetvalue(res, 0, 0));
}
PQclear(res);
res = PQexec(pgsql, "SHOW jit");
if (PQresultStatus(res) != PGRES_TUPLES_OK) {
add_assoc_null(return_value, "jit");
add_assoc_null(return_value, "jit");
} else {
add_assoc_string(return_value, "jit", PQgetvalue(res, 0, 0));
add_assoc_string(return_value, "jit", PQgetvalue(res, 0, 0));
}
PQclear(res);
return;
Expand Down Expand Up @@ -4346,7 +4344,7 @@ static int php_pgsql_fd_cast(php_stream *stream, int cast_as, void **ret) /* {{{
}

if (ret) {
*(php_socket_t *)ret = fd_number;
*(php_socket_t *)ret = fd_number;
}
}
return SUCCESS;
Expand Down Expand Up @@ -6248,3 +6246,29 @@ PHP_FUNCTION(pg_socket_poll)

RETURN_LONG((zend_long)PQsocketPoll(socket, (int)read, (int)write, (int)ts));
}

#if defined(HAVE_PG_SET_CHUNKED_ROWS_SIZE)
PHP_FUNCTION(pg_set_chunked_rows_size)
{
zval *pgsql_link;
pgsql_link_handle *link;
zend_long size;

ZEND_PARSE_PARAMETERS_START(2, 2)
Z_PARAM_OBJECT_OF_CLASS(pgsql_link, pgsql_link_ce)
Z_PARAM_LONG(size)
ZEND_PARSE_PARAMETERS_END();

if (size < 1 || size > INT_MAX) {
zend_argument_value_error(2, "must be between 1 and %d", INT_MAX);
RETURN_THROWS();
}

link = Z_PGSQL_LINK_P(pgsql_link);
CHECK_PGSQL_LINK(link);

/** can still fail if it is not allowed e.g. already fetched results **/

RETURN_BOOL(PQsetChunkedRowsMode(link->conn, (int)size) == 1);
}
#endif
11 changes: 11 additions & 0 deletions ext/pgsql/pgsql.stub.php
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,13 @@
* @cvalue PGRES_TUPLES_OK
*/
const PGSQL_TUPLES_OK = UNKNOWN;
#ifdef HAVE_PG_SET_CHUNKED_ROWS_SIZE
/**
* @var int
* @cvalue PGRES_TUPLES_CHUNK
*/
const PGSQL_TUPLES_CHUNK = UNKNOWN;
#endif
/**
* @var int
* @cvalue PGRES_COPY_OUT
Expand Down Expand Up @@ -963,6 +970,10 @@ function pg_put_copy_end(PgSql\Connection $connection, ?string $error = null): i
* @param resource $socket
*/
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
}

namespace PgSql {
Expand Down
18 changes: 17 additions & 1 deletion ext/pgsql/pgsql_arginfo.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

49 changes: 49 additions & 0 deletions ext/pgsql/tests/pg_set_chunked_rows_size.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
--TEST--
PostgreSQL pg_set_chunked_rows_size
--EXTENSIONS--
pgsql
--SKIPIF--
<?php
include("inc/skipif.inc");
if (!function_exists("pg_set_chunked_rows_size")) die("skip pg_set_chunked_rows_size unsupported");
?>
--FILE--
<?php

include('inc/config.inc');
$table_name = "test_chunked_rows_size";

$conn = pg_connect($conn_str);
pg_query($conn, "CREATE TABLE {$table_name} (num int, str text)");

for ($i = 0; $i < 10; $i ++)
pg_query($conn, "INSERT INTO {$table_name} DEFAULT VALUES");

var_dump(pg_send_query($conn, "SELECT * FROM ".$table_name.";"));
try {
pg_set_chunked_rows_size($conn, -1);
} catch (\ValueError $e) {
echo $e->getMessage() . PHP_EOL;
}

var_dump(pg_set_chunked_rows_size($conn, 1));
$result = pg_get_result($conn);
var_dump(pg_result_status($result) === PGSQL_TUPLES_CHUNK);
var_dump(pg_num_rows($result));
var_dump(pg_set_chunked_rows_size($conn, 10));
?>
--CLEAN--
<?php
include('inc/config.inc');
$table_name = "test_chunked_rows_size";

$conn = pg_connect($conn_str);
pg_query($conn, "DROP TABLE IF EXISTS {$table_name}");
?>
--EXPECTF--
bool(true)
pg_set_chunked_rows_size(): Argument #2 ($size) must be between 1 and %d
bool(true)
bool(true)
int(1)
bool(false)
Loading