1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

Merge branch 'PHP-8.3'

This commit is contained in:
David Carlier
2023-11-10 16:08:08 +00:00
4 changed files with 191 additions and 50 deletions

View File

@@ -3593,6 +3593,9 @@ PHP_FUNCTION(pg_send_query)
char *query;
size_t len;
PGconn *pgsql;
#ifdef LIBPQ_HAS_PIPELINING
bool is_pipeline_mode;
#endif
int is_non_blocking;
int ret;
@@ -3604,23 +3607,40 @@ PHP_FUNCTION(pg_send_query)
CHECK_PGSQL_LINK(link);
pgsql = link->conn;
is_non_blocking = PQisnonblocking(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
is_pipeline_mode = (PQpipelineStatus(pgsql) == PQ_PIPELINE_ON);
if (is_pipeline_mode) {
is_non_blocking = 1;
} else {
#endif
is_non_blocking = PQisnonblocking(pgsql);
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
if (_php_pgsql_link_has_results(pgsql)) {
php_error_docref(NULL, E_NOTICE,
"There are results on this connection. Call pg_get_result() until it returns FALSE");
if (_php_pgsql_link_has_results(pgsql)) {
php_error_docref(NULL, E_NOTICE,
"There are results on this connection. Call pg_get_result() until it returns FALSE");
}
#ifdef LIBPQ_HAS_PIPELINING
}
#endif
if (is_non_blocking) {
if (!PQsendQuery(pgsql, query)) {
RETURN_FALSE;
}
ret = PQflush(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
if (is_pipeline_mode) {
ret = 0;
} else {
#endif
ret = PQflush(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
}
#endif
} else {
if (!PQsendQuery(pgsql, query)) {
if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) {
@@ -3665,6 +3685,9 @@ PHP_FUNCTION(pg_send_query_params)
char *query;
size_t query_len;
PGconn *pgsql;
#ifdef LIBPQ_HAS_PIPELINING
bool is_pipeline_mode;
#endif
int is_non_blocking;
int ret;
@@ -3676,17 +3699,26 @@ PHP_FUNCTION(pg_send_query_params)
CHECK_PGSQL_LINK(link);
pgsql = link->conn;
is_non_blocking = PQisnonblocking(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
is_pipeline_mode = (PQpipelineStatus(pgsql) == PQ_PIPELINE_ON);
if (is_pipeline_mode) {
is_non_blocking = 1;
} else {
#endif
is_non_blocking = PQisnonblocking(pgsql);
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
if (_php_pgsql_link_has_results(pgsql)) {
php_error_docref(NULL, E_NOTICE,
"There are results on this connection. Call pg_get_result() until it returns FALSE");
if (_php_pgsql_link_has_results(pgsql)) {
php_error_docref(NULL, E_NOTICE,
"There are results on this connection. Call pg_get_result() until it returns FALSE");
}
#ifdef LIBPQ_HAS_PIPELINING
}
#endif
num_params = zend_hash_num_elements(Z_ARRVAL_P(pv_param_arr));
if (num_params > 0) {
@@ -3725,7 +3757,15 @@ PHP_FUNCTION(pg_send_query_params)
}
if (is_non_blocking) {
ret = PQflush(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
if (is_pipeline_mode) {
ret = 0;
} else {
#endif
ret = PQflush(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
}
#endif
} else {
/* Wait to finish sending buffer */
while ((ret = PQflush(pgsql))) {
@@ -3759,6 +3799,9 @@ PHP_FUNCTION(pg_send_prepare)
char *query, *stmtname;
size_t stmtname_len, query_len;
PGconn *pgsql;
#ifdef LIBPQ_HAS_PIPELINING
bool is_pipeline_mode;
#endif
int is_non_blocking;
int ret;
@@ -3770,17 +3813,26 @@ PHP_FUNCTION(pg_send_prepare)
CHECK_PGSQL_LINK(link);
pgsql = link->conn;
is_non_blocking = PQisnonblocking(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
is_pipeline_mode = (PQpipelineStatus(pgsql) == PQ_PIPELINE_ON);
if (is_pipeline_mode) {
is_non_blocking = 1;
} else {
#endif
is_non_blocking = PQisnonblocking(pgsql);
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
if (_php_pgsql_link_has_results(pgsql)) {
php_error_docref(NULL, E_NOTICE,
"There are results on this connection. Call pg_get_result() until it returns FALSE");
if (_php_pgsql_link_has_results(pgsql)) {
php_error_docref(NULL, E_NOTICE,
"There are results on this connection. Call pg_get_result() until it returns FALSE");
}
#ifdef LIBPQ_HAS_PIPELINING
}
#endif
if (!PQsendPrepare(pgsql, stmtname, query, 0, NULL)) {
if (is_non_blocking) {
@@ -3796,7 +3848,15 @@ PHP_FUNCTION(pg_send_prepare)
}
if (is_non_blocking) {
ret = PQflush(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
if (is_pipeline_mode) {
ret = 0;
} else {
#endif
ret = PQflush(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
}
#endif
} else {
/* Wait to finish sending buffer */
while ((ret = PQflush(pgsql))) {
@@ -3832,6 +3892,9 @@ PHP_FUNCTION(pg_send_execute)
char *stmtname;
size_t stmtname_len;
PGconn *pgsql;
#ifdef LIBPQ_HAS_PIPELINING
bool is_pipeline_mode;
#endif
int is_non_blocking;
int ret;
@@ -3843,17 +3906,26 @@ PHP_FUNCTION(pg_send_execute)
CHECK_PGSQL_LINK(link);
pgsql = link->conn;
is_non_blocking = PQisnonblocking(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
is_pipeline_mode = (PQpipelineStatus(pgsql) == PQ_PIPELINE_ON);
if (is_pipeline_mode) {
is_non_blocking = 1;
} else {
#endif
is_non_blocking = PQisnonblocking(pgsql);
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
RETURN_FALSE;
}
if (_php_pgsql_link_has_results(pgsql)) {
php_error_docref(NULL, E_NOTICE,
"There are results on this connection. Call pg_get_result() until it returns FALSE");
if (_php_pgsql_link_has_results(pgsql)) {
php_error_docref(NULL, E_NOTICE,
"There are results on this connection. Call pg_get_result() until it returns FALSE");
}
#ifdef LIBPQ_HAS_PIPELINING
}
#endif
num_params = zend_hash_num_elements(Z_ARRVAL_P(pv_param_arr));
if (num_params > 0) {
@@ -3894,7 +3966,15 @@ PHP_FUNCTION(pg_send_execute)
}
if (is_non_blocking) {
ret = PQflush(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
if (is_pipeline_mode) {
ret = 0;
} else {
#endif
ret = PQflush(pgsql);
#ifdef LIBPQ_HAS_PIPELINING
}
#endif
} else {
/* Wait to finish sending buffer */
while ((ret = PQflush(pgsql))) {
@@ -5897,6 +5977,8 @@ PHP_FUNCTION(pg_enter_pipeline_mode)
pgsql_handle = Z_PGSQL_LINK_P(pgsql_link);
CHECK_PGSQL_LINK(pgsql_handle);
PQsetnonblocking(pgsql_handle->conn, 1);
RETURN_BOOL(PQenterPipelineMode(pgsql_handle->conn));
}
@@ -5912,9 +5994,26 @@ PHP_FUNCTION(pg_exit_pipeline_mode)
pgsql_handle = Z_PGSQL_LINK_P(pgsql_link);
CHECK_PGSQL_LINK(pgsql_handle);
PQsetnonblocking(pgsql_handle->conn, 0);
RETURN_BOOL(PQexitPipelineMode(pgsql_handle->conn));
}
PHP_FUNCTION(pg_send_flush_request)
{
zval *pgsql_link;
pgsql_link_handle *pgsql_handle;
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &pgsql_link, pgsql_link_ce) == FAILURE) {
RETURN_THROWS();
}
pgsql_handle = Z_PGSQL_LINK_P(pgsql_link);
CHECK_PGSQL_LINK(pgsql_handle);
RETURN_BOOL(PQsendFlushRequest(pgsql_handle->conn));
}
PHP_FUNCTION(pg_pipeline_sync)
{
zval *pgsql_link;

View File

@@ -966,6 +966,7 @@ namespace {
#ifdef LIBPQ_HAS_PIPELINING
function pg_enter_pipeline_mode(PgSql\Connection $connection): bool {}
function pg_exit_pipeline_mode(PgSql\Connection $connection): bool {}
function pg_send_flush_request(PgSql\Connection $connection): bool {}
function pg_pipeline_sync(PgSql\Connection $connection): bool {}
function pg_pipeline_status(PgSql\Connection $connection): int {}
#endif

View File

@@ -1,5 +1,5 @@
/* This is a generated file, edit the .stub.php file instead.
* Stub hash: 29e402e7c708a25c99a4b2df0e858ea65a221e9b */
* Stub hash: b52f6b94faabab12457bf0d8ec035295aaacbfba */
ZEND_BEGIN_ARG_WITH_RETURN_OBJ_TYPE_MASK_EX(arginfo_pg_connect, 0, 1, PgSql\\Connection, MAY_BE_FALSE)
ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0)
@@ -462,6 +462,10 @@ ZEND_END_ARG_INFO()
#define arginfo_pg_exit_pipeline_mode arginfo_pg_enter_pipeline_mode
#endif
#if defined(LIBPQ_HAS_PIPELINING)
#define arginfo_pg_send_flush_request arginfo_pg_enter_pipeline_mode
#endif
#if defined(LIBPQ_HAS_PIPELINING)
#define arginfo_pg_pipeline_sync arginfo_pg_enter_pipeline_mode
#endif
@@ -578,6 +582,9 @@ ZEND_FUNCTION(pg_enter_pipeline_mode);
ZEND_FUNCTION(pg_exit_pipeline_mode);
#endif
#if defined(LIBPQ_HAS_PIPELINING)
ZEND_FUNCTION(pg_send_flush_request);
#endif
#if defined(LIBPQ_HAS_PIPELINING)
ZEND_FUNCTION(pg_pipeline_sync);
#endif
#if defined(LIBPQ_HAS_PIPELINING)
@@ -709,6 +716,9 @@ static const zend_function_entry ext_functions[] = {
#if defined(LIBPQ_HAS_PIPELINING)
ZEND_FE(pg_exit_pipeline_mode, arginfo_pg_exit_pipeline_mode)
#endif
#if defined(LIBPQ_HAS_PIPELINING)
ZEND_FE(pg_send_flush_request, arginfo_pg_send_flush_request)
#endif
#if defined(LIBPQ_HAS_PIPELINING)
ZEND_FE(pg_pipeline_sync, arginfo_pg_pipeline_sync)
#endif

View File

@@ -50,6 +50,26 @@ if (!pg_send_query_params($db, "SELECT $1 as index, now() + ($1||' day')::interv
die('pg_send_query_params failed');
}
if (!pg_flush($db)) {
die('pg_flush failed');
}
for ($i = 2; $i < 50; ++$i) {
if (!pg_send_query_params($db, "select $1 as index, now() + ($1||' day')::interval as time", array($i))) {
die('pg_send_query_params failed');
}
}
if (!pg_send_flush_request($db)) {
die('pg_send_flush_request failed');
}
for ($i = 50; $i < 99; ++$i) {
if (!pg_send_query_params($db, "select $1 as index, now() + ($1||' day')::interval as time", array($i))) {
die('pg_send_query_params failed');
}
}
if (!pg_pipeline_sync($db)) {
die('pg_pipeline_sync failed');
}
@@ -58,26 +78,37 @@ if (pg_pipeline_status($db) !== PGSQL_PIPELINE_ON) {
die('pg_pipeline_status failed');
}
if (!($result = pg_get_result($db))) {
die('pg_get_result');
if (!($stream = pg_socket($db))) {
die('pg_socket');
}
if (pg_result_status($result) !== PGSQL_TUPLES_OK) {
die('pg_result_status failed');
if (pg_connection_busy($db)) {
$read = [$stream]; $write = $ex = [];
while (!stream_select($read, $write, $ex, null, null)) { }
}
if (pg_num_rows($result) == -1) {
die('pg_num_rows failed');
}
for ($i = 1; $i < 99; ++$i) {
if (!($result = pg_get_result($db))) {
die('pg_get_result');
}
if (!pg_fetch_row($result, null)) {
die('pg_fetch_row failed');
}
if (pg_result_status($result) !== PGSQL_TUPLES_OK) {
die('pg_result_status failed');
}
pg_free_result($result);
if (pg_num_rows($result) == -1) {
die('pg_num_rows failed');
}
if (pg_get_result($db) !== false) {
die('pg_get_result failed');
if (!($row = pg_fetch_row($result, null))) {
die('pg_fetch_row failed');
}
pg_free_result($result);
if (pg_get_result($db) !== false) {
die('pg_get_result failed');
}
}
if (($result = pg_get_result($db)) !== false) {