Skip to content

Commit 994d19d

Browse files
committed
Merge branch 'PHP-8.3'
2 parents 60ca5a0 + 6389800 commit 994d19d

File tree

4 files changed

+191
-50
lines changed

4 files changed

+191
-50
lines changed

ext/pgsql/pgsql.c

Lines changed: 135 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -3593,6 +3593,9 @@ PHP_FUNCTION(pg_send_query)
35933593
char *query;
35943594
size_t len;
35953595
PGconn *pgsql;
3596+
#ifdef LIBPQ_HAS_PIPELINING
3597+
bool is_pipeline_mode;
3598+
#endif
35963599
int is_non_blocking;
35973600
int ret;
35983601

@@ -3604,23 +3607,40 @@ PHP_FUNCTION(pg_send_query)
36043607
CHECK_PGSQL_LINK(link);
36053608
pgsql = link->conn;
36063609

3607-
is_non_blocking = PQisnonblocking(pgsql);
3610+
#ifdef LIBPQ_HAS_PIPELINING
3611+
is_pipeline_mode = (PQpipelineStatus(pgsql) == PQ_PIPELINE_ON);
3612+
if (is_pipeline_mode) {
3613+
is_non_blocking = 1;
3614+
} else {
3615+
#endif
3616+
is_non_blocking = PQisnonblocking(pgsql);
36083617

3609-
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
3610-
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
3611-
RETURN_FALSE;
3612-
}
3618+
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
3619+
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
3620+
RETURN_FALSE;
3621+
}
36133622

3614-
if (_php_pgsql_link_has_results(pgsql)) {
3615-
php_error_docref(NULL, E_NOTICE,
3616-
"There are results on this connection. Call pg_get_result() until it returns FALSE");
3623+
if (_php_pgsql_link_has_results(pgsql)) {
3624+
php_error_docref(NULL, E_NOTICE,
3625+
"There are results on this connection. Call pg_get_result() until it returns FALSE");
3626+
}
3627+
#ifdef LIBPQ_HAS_PIPELINING
36173628
}
3629+
#endif
36183630

36193631
if (is_non_blocking) {
36203632
if (!PQsendQuery(pgsql, query)) {
36213633
RETURN_FALSE;
36223634
}
3623-
ret = PQflush(pgsql);
3635+
#ifdef LIBPQ_HAS_PIPELINING
3636+
if (is_pipeline_mode) {
3637+
ret = 0;
3638+
} else {
3639+
#endif
3640+
ret = PQflush(pgsql);
3641+
#ifdef LIBPQ_HAS_PIPELINING
3642+
}
3643+
#endif
36243644
} else {
36253645
if (!PQsendQuery(pgsql, query)) {
36263646
if ((PGG(auto_reset_persistent) & 2) && PQstatus(pgsql) != CONNECTION_OK) {
@@ -3665,6 +3685,9 @@ PHP_FUNCTION(pg_send_query_params)
36653685
char *query;
36663686
size_t query_len;
36673687
PGconn *pgsql;
3688+
#ifdef LIBPQ_HAS_PIPELINING
3689+
bool is_pipeline_mode;
3690+
#endif
36683691
int is_non_blocking;
36693692
int ret;
36703693

@@ -3676,17 +3699,26 @@ PHP_FUNCTION(pg_send_query_params)
36763699
CHECK_PGSQL_LINK(link);
36773700
pgsql = link->conn;
36783701

3679-
is_non_blocking = PQisnonblocking(pgsql);
3702+
#ifdef LIBPQ_HAS_PIPELINING
3703+
is_pipeline_mode = (PQpipelineStatus(pgsql) == PQ_PIPELINE_ON);
3704+
if (is_pipeline_mode) {
3705+
is_non_blocking = 1;
3706+
} else {
3707+
#endif
3708+
is_non_blocking = PQisnonblocking(pgsql);
36803709

3681-
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
3682-
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
3683-
RETURN_FALSE;
3684-
}
3710+
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
3711+
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
3712+
RETURN_FALSE;
3713+
}
36853714

3686-
if (_php_pgsql_link_has_results(pgsql)) {
3687-
php_error_docref(NULL, E_NOTICE,
3688-
"There are results on this connection. Call pg_get_result() until it returns FALSE");
3715+
if (_php_pgsql_link_has_results(pgsql)) {
3716+
php_error_docref(NULL, E_NOTICE,
3717+
"There are results on this connection. Call pg_get_result() until it returns FALSE");
3718+
}
3719+
#ifdef LIBPQ_HAS_PIPELINING
36893720
}
3721+
#endif
36903722

36913723
num_params = zend_hash_num_elements(Z_ARRVAL_P(pv_param_arr));
36923724
if (num_params > 0) {
@@ -3725,7 +3757,15 @@ PHP_FUNCTION(pg_send_query_params)
37253757
}
37263758

37273759
if (is_non_blocking) {
3728-
ret = PQflush(pgsql);
3760+
#ifdef LIBPQ_HAS_PIPELINING
3761+
if (is_pipeline_mode) {
3762+
ret = 0;
3763+
} else {
3764+
#endif
3765+
ret = PQflush(pgsql);
3766+
#ifdef LIBPQ_HAS_PIPELINING
3767+
}
3768+
#endif
37293769
} else {
37303770
/* Wait to finish sending buffer */
37313771
while ((ret = PQflush(pgsql))) {
@@ -3759,6 +3799,9 @@ PHP_FUNCTION(pg_send_prepare)
37593799
char *query, *stmtname;
37603800
size_t stmtname_len, query_len;
37613801
PGconn *pgsql;
3802+
#ifdef LIBPQ_HAS_PIPELINING
3803+
bool is_pipeline_mode;
3804+
#endif
37623805
int is_non_blocking;
37633806
int ret;
37643807

@@ -3770,17 +3813,26 @@ PHP_FUNCTION(pg_send_prepare)
37703813
CHECK_PGSQL_LINK(link);
37713814
pgsql = link->conn;
37723815

3773-
is_non_blocking = PQisnonblocking(pgsql);
3816+
#ifdef LIBPQ_HAS_PIPELINING
3817+
is_pipeline_mode = (PQpipelineStatus(pgsql) == PQ_PIPELINE_ON);
3818+
if (is_pipeline_mode) {
3819+
is_non_blocking = 1;
3820+
} else {
3821+
#endif
3822+
is_non_blocking = PQisnonblocking(pgsql);
37743823

3775-
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
3776-
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
3777-
RETURN_FALSE;
3778-
}
3824+
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
3825+
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
3826+
RETURN_FALSE;
3827+
}
37793828

3780-
if (_php_pgsql_link_has_results(pgsql)) {
3781-
php_error_docref(NULL, E_NOTICE,
3782-
"There are results on this connection. Call pg_get_result() until it returns FALSE");
3829+
if (_php_pgsql_link_has_results(pgsql)) {
3830+
php_error_docref(NULL, E_NOTICE,
3831+
"There are results on this connection. Call pg_get_result() until it returns FALSE");
3832+
}
3833+
#ifdef LIBPQ_HAS_PIPELINING
37833834
}
3835+
#endif
37843836

37853837
if (!PQsendPrepare(pgsql, stmtname, query, 0, NULL)) {
37863838
if (is_non_blocking) {
@@ -3796,7 +3848,15 @@ PHP_FUNCTION(pg_send_prepare)
37963848
}
37973849

37983850
if (is_non_blocking) {
3799-
ret = PQflush(pgsql);
3851+
#ifdef LIBPQ_HAS_PIPELINING
3852+
if (is_pipeline_mode) {
3853+
ret = 0;
3854+
} else {
3855+
#endif
3856+
ret = PQflush(pgsql);
3857+
#ifdef LIBPQ_HAS_PIPELINING
3858+
}
3859+
#endif
38003860
} else {
38013861
/* Wait to finish sending buffer */
38023862
while ((ret = PQflush(pgsql))) {
@@ -3832,6 +3892,9 @@ PHP_FUNCTION(pg_send_execute)
38323892
char *stmtname;
38333893
size_t stmtname_len;
38343894
PGconn *pgsql;
3895+
#ifdef LIBPQ_HAS_PIPELINING
3896+
bool is_pipeline_mode;
3897+
#endif
38353898
int is_non_blocking;
38363899
int ret;
38373900

@@ -3843,17 +3906,26 @@ PHP_FUNCTION(pg_send_execute)
38433906
CHECK_PGSQL_LINK(link);
38443907
pgsql = link->conn;
38453908

3846-
is_non_blocking = PQisnonblocking(pgsql);
3909+
#ifdef LIBPQ_HAS_PIPELINING
3910+
is_pipeline_mode = (PQpipelineStatus(pgsql) == PQ_PIPELINE_ON);
3911+
if (is_pipeline_mode) {
3912+
is_non_blocking = 1;
3913+
} else {
3914+
#endif
3915+
is_non_blocking = PQisnonblocking(pgsql);
38473916

3848-
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
3849-
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
3850-
RETURN_FALSE;
3851-
}
3917+
if (is_non_blocking == 0 && PQsetnonblocking(pgsql, 1) == -1) {
3918+
php_error_docref(NULL, E_NOTICE, "Cannot set connection to nonblocking mode");
3919+
RETURN_FALSE;
3920+
}
38523921

3853-
if (_php_pgsql_link_has_results(pgsql)) {
3854-
php_error_docref(NULL, E_NOTICE,
3855-
"There are results on this connection. Call pg_get_result() until it returns FALSE");
3922+
if (_php_pgsql_link_has_results(pgsql)) {
3923+
php_error_docref(NULL, E_NOTICE,
3924+
"There are results on this connection. Call pg_get_result() until it returns FALSE");
3925+
}
3926+
#ifdef LIBPQ_HAS_PIPELINING
38563927
}
3928+
#endif
38573929

38583930
num_params = zend_hash_num_elements(Z_ARRVAL_P(pv_param_arr));
38593931
if (num_params > 0) {
@@ -3894,7 +3966,15 @@ PHP_FUNCTION(pg_send_execute)
38943966
}
38953967

38963968
if (is_non_blocking) {
3897-
ret = PQflush(pgsql);
3969+
#ifdef LIBPQ_HAS_PIPELINING
3970+
if (is_pipeline_mode) {
3971+
ret = 0;
3972+
} else {
3973+
#endif
3974+
ret = PQflush(pgsql);
3975+
#ifdef LIBPQ_HAS_PIPELINING
3976+
}
3977+
#endif
38983978
} else {
38993979
/* Wait to finish sending buffer */
39003980
while ((ret = PQflush(pgsql))) {
@@ -5897,6 +5977,8 @@ PHP_FUNCTION(pg_enter_pipeline_mode)
58975977
pgsql_handle = Z_PGSQL_LINK_P(pgsql_link);
58985978
CHECK_PGSQL_LINK(pgsql_handle);
58995979

5980+
PQsetnonblocking(pgsql_handle->conn, 1);
5981+
59005982
RETURN_BOOL(PQenterPipelineMode(pgsql_handle->conn));
59015983
}
59025984

@@ -5912,9 +5994,26 @@ PHP_FUNCTION(pg_exit_pipeline_mode)
59125994
pgsql_handle = Z_PGSQL_LINK_P(pgsql_link);
59135995
CHECK_PGSQL_LINK(pgsql_handle);
59145996

5997+
PQsetnonblocking(pgsql_handle->conn, 0);
5998+
59155999
RETURN_BOOL(PQexitPipelineMode(pgsql_handle->conn));
59166000
}
59176001

6002+
PHP_FUNCTION(pg_send_flush_request)
6003+
{
6004+
zval *pgsql_link;
6005+
pgsql_link_handle *pgsql_handle;
6006+
6007+
if (zend_parse_parameters(ZEND_NUM_ARGS(), "O", &pgsql_link, pgsql_link_ce) == FAILURE) {
6008+
RETURN_THROWS();
6009+
}
6010+
6011+
pgsql_handle = Z_PGSQL_LINK_P(pgsql_link);
6012+
CHECK_PGSQL_LINK(pgsql_handle);
6013+
6014+
RETURN_BOOL(PQsendFlushRequest(pgsql_handle->conn));
6015+
}
6016+
59186017
PHP_FUNCTION(pg_pipeline_sync)
59196018
{
59206019
zval *pgsql_link;

ext/pgsql/pgsql.stub.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -966,6 +966,7 @@ function pg_select(PgSql\Connection $connection, string $table_name, array $cond
966966
#ifdef LIBPQ_HAS_PIPELINING
967967
function pg_enter_pipeline_mode(PgSql\Connection $connection): bool {}
968968
function pg_exit_pipeline_mode(PgSql\Connection $connection): bool {}
969+
function pg_send_flush_request(PgSql\Connection $connection): bool {}
969970
function pg_pipeline_sync(PgSql\Connection $connection): bool {}
970971
function pg_pipeline_status(PgSql\Connection $connection): int {}
971972
#endif

ext/pgsql/pgsql_arginfo.h

Lines changed: 11 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)