@@ -3593,6 +3593,9 @@ PHP_FUNCTION(pg_send_query)
3593
3593
char * query ;
3594
3594
size_t len ;
3595
3595
PGconn * pgsql ;
3596
+ #ifdef LIBPQ_HAS_PIPELINING
3597
+ bool is_pipeline_mode ;
3598
+ #endif
3596
3599
int is_non_blocking ;
3597
3600
int ret ;
3598
3601
@@ -3604,23 +3607,40 @@ PHP_FUNCTION(pg_send_query)
3604
3607
CHECK_PGSQL_LINK (link );
3605
3608
pgsql = link -> conn ;
3606
3609
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 );
3608
3617
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
+ }
3613
3622
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
3617
3628
}
3629
+ #endif
3618
3630
3619
3631
if (is_non_blocking ) {
3620
3632
if (!PQsendQuery (pgsql , query )) {
3621
3633
RETURN_FALSE ;
3622
3634
}
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
3624
3644
} else {
3625
3645
if (!PQsendQuery (pgsql , query )) {
3626
3646
if ((PGG (auto_reset_persistent ) & 2 ) && PQstatus (pgsql ) != CONNECTION_OK ) {
@@ -3665,6 +3685,9 @@ PHP_FUNCTION(pg_send_query_params)
3665
3685
char * query ;
3666
3686
size_t query_len ;
3667
3687
PGconn * pgsql ;
3688
+ #ifdef LIBPQ_HAS_PIPELINING
3689
+ bool is_pipeline_mode ;
3690
+ #endif
3668
3691
int is_non_blocking ;
3669
3692
int ret ;
3670
3693
@@ -3676,17 +3699,26 @@ PHP_FUNCTION(pg_send_query_params)
3676
3699
CHECK_PGSQL_LINK (link );
3677
3700
pgsql = link -> conn ;
3678
3701
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 );
3680
3709
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
+ }
3685
3714
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
3689
3720
}
3721
+ #endif
3690
3722
3691
3723
num_params = zend_hash_num_elements (Z_ARRVAL_P (pv_param_arr ));
3692
3724
if (num_params > 0 ) {
@@ -3725,7 +3757,15 @@ PHP_FUNCTION(pg_send_query_params)
3725
3757
}
3726
3758
3727
3759
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
3729
3769
} else {
3730
3770
/* Wait to finish sending buffer */
3731
3771
while ((ret = PQflush (pgsql ))) {
@@ -3759,6 +3799,9 @@ PHP_FUNCTION(pg_send_prepare)
3759
3799
char * query , * stmtname ;
3760
3800
size_t stmtname_len , query_len ;
3761
3801
PGconn * pgsql ;
3802
+ #ifdef LIBPQ_HAS_PIPELINING
3803
+ bool is_pipeline_mode ;
3804
+ #endif
3762
3805
int is_non_blocking ;
3763
3806
int ret ;
3764
3807
@@ -3770,17 +3813,26 @@ PHP_FUNCTION(pg_send_prepare)
3770
3813
CHECK_PGSQL_LINK (link );
3771
3814
pgsql = link -> conn ;
3772
3815
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 );
3774
3823
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
+ }
3779
3828
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
3783
3834
}
3835
+ #endif
3784
3836
3785
3837
if (!PQsendPrepare (pgsql , stmtname , query , 0 , NULL )) {
3786
3838
if (is_non_blocking ) {
@@ -3796,7 +3848,15 @@ PHP_FUNCTION(pg_send_prepare)
3796
3848
}
3797
3849
3798
3850
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
3800
3860
} else {
3801
3861
/* Wait to finish sending buffer */
3802
3862
while ((ret = PQflush (pgsql ))) {
@@ -3832,6 +3892,9 @@ PHP_FUNCTION(pg_send_execute)
3832
3892
char * stmtname ;
3833
3893
size_t stmtname_len ;
3834
3894
PGconn * pgsql ;
3895
+ #ifdef LIBPQ_HAS_PIPELINING
3896
+ bool is_pipeline_mode ;
3897
+ #endif
3835
3898
int is_non_blocking ;
3836
3899
int ret ;
3837
3900
@@ -3843,17 +3906,26 @@ PHP_FUNCTION(pg_send_execute)
3843
3906
CHECK_PGSQL_LINK (link );
3844
3907
pgsql = link -> conn ;
3845
3908
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 );
3847
3916
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
+ }
3852
3921
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
3856
3927
}
3928
+ #endif
3857
3929
3858
3930
num_params = zend_hash_num_elements (Z_ARRVAL_P (pv_param_arr ));
3859
3931
if (num_params > 0 ) {
@@ -3894,7 +3966,15 @@ PHP_FUNCTION(pg_send_execute)
3894
3966
}
3895
3967
3896
3968
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
3898
3978
} else {
3899
3979
/* Wait to finish sending buffer */
3900
3980
while ((ret = PQflush (pgsql ))) {
@@ -5897,6 +5977,8 @@ PHP_FUNCTION(pg_enter_pipeline_mode)
5897
5977
pgsql_handle = Z_PGSQL_LINK_P (pgsql_link );
5898
5978
CHECK_PGSQL_LINK (pgsql_handle );
5899
5979
5980
+ PQsetnonblocking (pgsql_handle -> conn , 1 );
5981
+
5900
5982
RETURN_BOOL (PQenterPipelineMode (pgsql_handle -> conn ));
5901
5983
}
5902
5984
@@ -5912,9 +5994,26 @@ PHP_FUNCTION(pg_exit_pipeline_mode)
5912
5994
pgsql_handle = Z_PGSQL_LINK_P (pgsql_link );
5913
5995
CHECK_PGSQL_LINK (pgsql_handle );
5914
5996
5997
+ PQsetnonblocking (pgsql_handle -> conn , 0 );
5998
+
5915
5999
RETURN_BOOL (PQexitPipelineMode (pgsql_handle -> conn ));
5916
6000
}
5917
6001
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
+
5918
6017
PHP_FUNCTION (pg_pipeline_sync )
5919
6018
{
5920
6019
zval * pgsql_link ;
0 commit comments