@@ -3595,6 +3595,9 @@ PHP_FUNCTION(pg_send_query)
3595
3595
char * query ;
3596
3596
size_t len ;
3597
3597
PGconn * pgsql ;
3598
+ #ifdef LIBPQ_HAS_PIPELINING
3599
+ bool is_pipeline_mode ;
3600
+ #endif
3598
3601
int is_non_blocking ;
3599
3602
int ret ;
3600
3603
@@ -3606,23 +3609,40 @@ PHP_FUNCTION(pg_send_query)
3606
3609
CHECK_PGSQL_LINK (link );
3607
3610
pgsql = link -> conn ;
3608
3611
3609
- is_non_blocking = PQisnonblocking (pgsql );
3612
+ #ifdef LIBPQ_HAS_PIPELINING
3613
+ is_pipeline_mode = (PQpipelineStatus (pgsql ) == PQ_PIPELINE_ON );
3614
+ if (is_pipeline_mode ) {
3615
+ is_non_blocking = 1 ;
3616
+ } else {
3617
+ #endif
3618
+ is_non_blocking = PQisnonblocking (pgsql );
3610
3619
3611
- if (is_non_blocking == 0 && PQsetnonblocking (pgsql , 1 ) == -1 ) {
3612
- php_error_docref (NULL , E_NOTICE , "Cannot set connection to nonblocking mode" );
3613
- RETURN_FALSE ;
3614
- }
3620
+ if (is_non_blocking == 0 && PQsetnonblocking (pgsql , 1 ) == -1 ) {
3621
+ php_error_docref (NULL , E_NOTICE , "Cannot set connection to nonblocking mode" );
3622
+ RETURN_FALSE ;
3623
+ }
3615
3624
3616
- if (_php_pgsql_link_has_results (pgsql )) {
3617
- php_error_docref (NULL , E_NOTICE ,
3618
- "There are results on this connection. Call pg_get_result() until it returns FALSE" );
3625
+ if (_php_pgsql_link_has_results (pgsql )) {
3626
+ php_error_docref (NULL , E_NOTICE ,
3627
+ "There are results on this connection. Call pg_get_result() until it returns FALSE" );
3628
+ }
3629
+ #ifdef LIBPQ_HAS_PIPELINING
3619
3630
}
3631
+ #endif
3620
3632
3621
3633
if (is_non_blocking ) {
3622
3634
if (!PQsendQuery (pgsql , query )) {
3623
3635
RETURN_FALSE ;
3624
3636
}
3625
- ret = PQflush (pgsql );
3637
+ #ifdef LIBPQ_HAS_PIPELINING
3638
+ if (is_pipeline_mode ) {
3639
+ ret = 0 ;
3640
+ } else {
3641
+ #endif
3642
+ ret = PQflush (pgsql );
3643
+ #ifdef LIBPQ_HAS_PIPELINING
3644
+ }
3645
+ #endif
3626
3646
} else {
3627
3647
if (!PQsendQuery (pgsql , query )) {
3628
3648
if ((PGG (auto_reset_persistent ) & 2 ) && PQstatus (pgsql ) != CONNECTION_OK ) {
@@ -3667,6 +3687,9 @@ PHP_FUNCTION(pg_send_query_params)
3667
3687
char * query ;
3668
3688
size_t query_len ;
3669
3689
PGconn * pgsql ;
3690
+ #ifdef LIBPQ_HAS_PIPELINING
3691
+ bool is_pipeline_mode ;
3692
+ #endif
3670
3693
int is_non_blocking ;
3671
3694
int ret ;
3672
3695
@@ -3678,17 +3701,26 @@ PHP_FUNCTION(pg_send_query_params)
3678
3701
CHECK_PGSQL_LINK (link );
3679
3702
pgsql = link -> conn ;
3680
3703
3681
- is_non_blocking = PQisnonblocking (pgsql );
3704
+ #ifdef LIBPQ_HAS_PIPELINING
3705
+ is_pipeline_mode = (PQpipelineStatus (pgsql ) == PQ_PIPELINE_ON );
3706
+ if (is_pipeline_mode ) {
3707
+ is_non_blocking = 1 ;
3708
+ } else {
3709
+ #endif
3710
+ is_non_blocking = PQisnonblocking (pgsql );
3682
3711
3683
- if (is_non_blocking == 0 && PQsetnonblocking (pgsql , 1 ) == -1 ) {
3684
- php_error_docref (NULL , E_NOTICE , "Cannot set connection to nonblocking mode" );
3685
- RETURN_FALSE ;
3686
- }
3712
+ if (is_non_blocking == 0 && PQsetnonblocking (pgsql , 1 ) == -1 ) {
3713
+ php_error_docref (NULL , E_NOTICE , "Cannot set connection to nonblocking mode" );
3714
+ RETURN_FALSE ;
3715
+ }
3687
3716
3688
- if (_php_pgsql_link_has_results (pgsql )) {
3689
- php_error_docref (NULL , E_NOTICE ,
3690
- "There are results on this connection. Call pg_get_result() until it returns FALSE" );
3717
+ if (_php_pgsql_link_has_results (pgsql )) {
3718
+ php_error_docref (NULL , E_NOTICE ,
3719
+ "There are results on this connection. Call pg_get_result() until it returns FALSE" );
3720
+ }
3721
+ #ifdef LIBPQ_HAS_PIPELINING
3691
3722
}
3723
+ #endif
3692
3724
3693
3725
num_params = zend_hash_num_elements (Z_ARRVAL_P (pv_param_arr ));
3694
3726
if (num_params > 0 ) {
@@ -3727,7 +3759,15 @@ PHP_FUNCTION(pg_send_query_params)
3727
3759
}
3728
3760
3729
3761
if (is_non_blocking ) {
3730
- ret = PQflush (pgsql );
3762
+ #ifdef LIBPQ_HAS_PIPELINING
3763
+ if (is_pipeline_mode ) {
3764
+ ret = 0 ;
3765
+ } else {
3766
+ #endif
3767
+ ret = PQflush (pgsql );
3768
+ #ifdef LIBPQ_HAS_PIPELINING
3769
+ }
3770
+ #endif
3731
3771
} else {
3732
3772
/* Wait to finish sending buffer */
3733
3773
while ((ret = PQflush (pgsql ))) {
@@ -3761,6 +3801,9 @@ PHP_FUNCTION(pg_send_prepare)
3761
3801
char * query , * stmtname ;
3762
3802
size_t stmtname_len , query_len ;
3763
3803
PGconn * pgsql ;
3804
+ #ifdef LIBPQ_HAS_PIPELINING
3805
+ bool is_pipeline_mode ;
3806
+ #endif
3764
3807
int is_non_blocking ;
3765
3808
int ret ;
3766
3809
@@ -3772,17 +3815,26 @@ PHP_FUNCTION(pg_send_prepare)
3772
3815
CHECK_PGSQL_LINK (link );
3773
3816
pgsql = link -> conn ;
3774
3817
3775
- is_non_blocking = PQisnonblocking (pgsql );
3818
+ #ifdef LIBPQ_HAS_PIPELINING
3819
+ is_pipeline_mode = (PQpipelineStatus (pgsql ) == PQ_PIPELINE_ON );
3820
+ if (is_pipeline_mode ) {
3821
+ is_non_blocking = 1 ;
3822
+ } else {
3823
+ #endif
3824
+ is_non_blocking = PQisnonblocking (pgsql );
3776
3825
3777
- if (is_non_blocking == 0 && PQsetnonblocking (pgsql , 1 ) == -1 ) {
3778
- php_error_docref (NULL , E_NOTICE , "Cannot set connection to nonblocking mode" );
3779
- RETURN_FALSE ;
3780
- }
3826
+ if (is_non_blocking == 0 && PQsetnonblocking (pgsql , 1 ) == -1 ) {
3827
+ php_error_docref (NULL , E_NOTICE , "Cannot set connection to nonblocking mode" );
3828
+ RETURN_FALSE ;
3829
+ }
3781
3830
3782
- if (_php_pgsql_link_has_results (pgsql )) {
3783
- php_error_docref (NULL , E_NOTICE ,
3784
- "There are results on this connection. Call pg_get_result() until it returns FALSE" );
3831
+ if (_php_pgsql_link_has_results (pgsql )) {
3832
+ php_error_docref (NULL , E_NOTICE ,
3833
+ "There are results on this connection. Call pg_get_result() until it returns FALSE" );
3834
+ }
3835
+ #ifdef LIBPQ_HAS_PIPELINING
3785
3836
}
3837
+ #endif
3786
3838
3787
3839
if (!PQsendPrepare (pgsql , stmtname , query , 0 , NULL )) {
3788
3840
if (is_non_blocking ) {
@@ -3798,7 +3850,15 @@ PHP_FUNCTION(pg_send_prepare)
3798
3850
}
3799
3851
3800
3852
if (is_non_blocking ) {
3801
- ret = PQflush (pgsql );
3853
+ #ifdef LIBPQ_HAS_PIPELINING
3854
+ if (is_pipeline_mode ) {
3855
+ ret = 0 ;
3856
+ } else {
3857
+ #endif
3858
+ ret = PQflush (pgsql );
3859
+ #ifdef LIBPQ_HAS_PIPELINING
3860
+ }
3861
+ #endif
3802
3862
} else {
3803
3863
/* Wait to finish sending buffer */
3804
3864
while ((ret = PQflush (pgsql ))) {
@@ -3834,6 +3894,9 @@ PHP_FUNCTION(pg_send_execute)
3834
3894
char * stmtname ;
3835
3895
size_t stmtname_len ;
3836
3896
PGconn * pgsql ;
3897
+ #ifdef LIBPQ_HAS_PIPELINING
3898
+ bool is_pipeline_mode ;
3899
+ #endif
3837
3900
int is_non_blocking ;
3838
3901
int ret ;
3839
3902
@@ -3845,17 +3908,26 @@ PHP_FUNCTION(pg_send_execute)
3845
3908
CHECK_PGSQL_LINK (link );
3846
3909
pgsql = link -> conn ;
3847
3910
3848
- is_non_blocking = PQisnonblocking (pgsql );
3911
+ #ifdef LIBPQ_HAS_PIPELINING
3912
+ is_pipeline_mode = (PQpipelineStatus (pgsql ) == PQ_PIPELINE_ON );
3913
+ if (is_pipeline_mode ) {
3914
+ is_non_blocking = 1 ;
3915
+ } else {
3916
+ #endif
3917
+ is_non_blocking = PQisnonblocking (pgsql );
3849
3918
3850
- if (is_non_blocking == 0 && PQsetnonblocking (pgsql , 1 ) == -1 ) {
3851
- php_error_docref (NULL , E_NOTICE , "Cannot set connection to nonblocking mode" );
3852
- RETURN_FALSE ;
3853
- }
3919
+ if (is_non_blocking == 0 && PQsetnonblocking (pgsql , 1 ) == -1 ) {
3920
+ php_error_docref (NULL , E_NOTICE , "Cannot set connection to nonblocking mode" );
3921
+ RETURN_FALSE ;
3922
+ }
3854
3923
3855
- if (_php_pgsql_link_has_results (pgsql )) {
3856
- php_error_docref (NULL , E_NOTICE ,
3857
- "There are results on this connection. Call pg_get_result() until it returns FALSE" );
3924
+ if (_php_pgsql_link_has_results (pgsql )) {
3925
+ php_error_docref (NULL , E_NOTICE ,
3926
+ "There are results on this connection. Call pg_get_result() until it returns FALSE" );
3927
+ }
3928
+ #ifdef LIBPQ_HAS_PIPELINING
3858
3929
}
3930
+ #endif
3859
3931
3860
3932
num_params = zend_hash_num_elements (Z_ARRVAL_P (pv_param_arr ));
3861
3933
if (num_params > 0 ) {
@@ -3896,7 +3968,15 @@ PHP_FUNCTION(pg_send_execute)
3896
3968
}
3897
3969
3898
3970
if (is_non_blocking ) {
3899
- ret = PQflush (pgsql );
3971
+ #ifdef LIBPQ_HAS_PIPELINING
3972
+ if (is_pipeline_mode ) {
3973
+ ret = 0 ;
3974
+ } else {
3975
+ #endif
3976
+ ret = PQflush (pgsql );
3977
+ #ifdef LIBPQ_HAS_PIPELINING
3978
+ }
3979
+ #endif
3900
3980
} else {
3901
3981
/* Wait to finish sending buffer */
3902
3982
while ((ret = PQflush (pgsql ))) {
@@ -5891,6 +5971,8 @@ PHP_FUNCTION(pg_enter_pipeline_mode)
5891
5971
pgsql_handle = Z_PGSQL_LINK_P (pgsql_link );
5892
5972
CHECK_PGSQL_LINK (pgsql_handle );
5893
5973
5974
+ PQsetnonblocking (pgsql_handle -> conn , 1 );
5975
+
5894
5976
RETURN_BOOL (PQenterPipelineMode (pgsql_handle -> conn ));
5895
5977
}
5896
5978
@@ -5906,9 +5988,26 @@ PHP_FUNCTION(pg_exit_pipeline_mode)
5906
5988
pgsql_handle = Z_PGSQL_LINK_P (pgsql_link );
5907
5989
CHECK_PGSQL_LINK (pgsql_handle );
5908
5990
5991
+ PQsetnonblocking (pgsql_handle -> conn , 0 );
5992
+
5909
5993
RETURN_BOOL (PQexitPipelineMode (pgsql_handle -> conn ));
5910
5994
}
5911
5995
5996
+ PHP_FUNCTION (pg_send_flush_request )
5997
+ {
5998
+ zval * pgsql_link ;
5999
+ pgsql_link_handle * pgsql_handle ;
6000
+
6001
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "O" , & pgsql_link , pgsql_link_ce ) == FAILURE ) {
6002
+ RETURN_THROWS ();
6003
+ }
6004
+
6005
+ pgsql_handle = Z_PGSQL_LINK_P (pgsql_link );
6006
+ CHECK_PGSQL_LINK (pgsql_handle );
6007
+
6008
+ RETURN_BOOL (PQsendFlushRequest (pgsql_handle -> conn ));
6009
+ }
6010
+
5912
6011
PHP_FUNCTION (pg_pipeline_sync )
5913
6012
{
5914
6013
zval * pgsql_link ;
0 commit comments