@@ -5777,29 +5777,34 @@ PHP_PGSQL_API zend_result php_pgsql_select(PGconn *pg_link, const zend_string *t
5777
5777
5778
5778
ZEND_ASSERT (pg_link != NULL );
5779
5779
ZEND_ASSERT (table != NULL );
5780
- ZEND_ASSERT (Z_TYPE_P (ids_array ) == IS_ARRAY );
5780
+ if (ids_array ) {
5781
+ ZEND_ASSERT (Z_TYPE_P (ids_array ) == IS_ARRAY );
5782
+ }
5781
5783
ZEND_ASSERT (Z_TYPE_P (ret_array ) == IS_ARRAY );
5782
5784
ZEND_ASSERT (!(opt & ~(PGSQL_CONV_OPTS |PGSQL_DML_NO_CONV |PGSQL_DML_EXEC |PGSQL_DML_ASYNC |PGSQL_DML_STRING |PGSQL_DML_ESCAPE )));
5783
5785
5784
- if (zend_hash_num_elements (Z_ARRVAL_P (ids_array )) == 0 ) {
5785
- return FAILURE ;
5786
- }
5786
+ zend_bool is_valid_ids_array = ids_array && zend_hash_num_elements (Z_ARRVAL_P (ids_array )) != 0 ;
5787
5787
5788
- ZVAL_UNDEF (& ids_converted );
5789
- if (!(opt & (PGSQL_DML_NO_CONV |PGSQL_DML_ESCAPE ))) {
5790
- array_init (& ids_converted );
5791
- if (php_pgsql_convert (pg_link , table , ids_array , & ids_converted , (opt & PGSQL_CONV_OPTS )) == FAILURE ) {
5792
- goto cleanup ;
5788
+ if (is_valid_ids_array ) {
5789
+ ZVAL_UNDEF (& ids_converted );
5790
+ if (!(opt & (PGSQL_DML_NO_CONV |PGSQL_DML_ESCAPE ))) {
5791
+ array_init (& ids_converted );
5792
+ if (php_pgsql_convert (pg_link , table , ids_array , & ids_converted , (opt & PGSQL_CONV_OPTS )) == FAILURE ) {
5793
+ goto cleanup ;
5794
+ }
5795
+ ids_array = & ids_converted ;
5793
5796
}
5794
- ids_array = & ids_converted ;
5795
5797
}
5796
5798
5797
5799
smart_str_appends (& querystr , "SELECT * FROM " );
5798
5800
build_tablename (& querystr , pg_link , table );
5799
- smart_str_appends (& querystr , " WHERE " );
5800
5801
5801
- if (build_assignment_string (pg_link , & querystr , Z_ARRVAL_P (ids_array ), 1 , " AND " , sizeof (" AND " )- 1 , opt ))
5802
- goto cleanup ;
5802
+ if (is_valid_ids_array ) {
5803
+ smart_str_appends (& querystr , " WHERE " );
5804
+ if (build_assignment_string (pg_link , & querystr , Z_ARRVAL_P (ids_array ), 1 , " AND " , sizeof (" AND " )- 1 , opt )) {
5805
+ goto cleanup ;
5806
+ }
5807
+ }
5803
5808
5804
5809
smart_str_appendc (& querystr , ';' );
5805
5810
smart_str_0 (& querystr );
@@ -5814,7 +5819,9 @@ PHP_PGSQL_API zend_result php_pgsql_select(PGconn *pg_link, const zend_string *t
5814
5819
PQclear (pg_result );
5815
5820
5816
5821
cleanup :
5817
- zval_ptr_dtor (& ids_converted );
5822
+ if (is_valid_ids_array ) {
5823
+ zval_ptr_dtor (& ids_converted );
5824
+ }
5818
5825
if (ret == SUCCESS && (opt & PGSQL_DML_STRING )) {
5819
5826
* sql = querystr .s ;
5820
5827
}
@@ -5828,7 +5835,8 @@ PHP_PGSQL_API zend_result php_pgsql_select(PGconn *pg_link, const zend_string *t
5828
5835
/* {{{ Select records that has ids (id=>value) */
5829
5836
PHP_FUNCTION (pg_select )
5830
5837
{
5831
- zval * pgsql_link , * ids ;
5838
+ zval * pgsql_link ;
5839
+ zval * ids = NULL ;
5832
5840
pgsql_link_handle * link ;
5833
5841
zend_string * table ;
5834
5842
zend_ulong option = PGSQL_DML_EXEC ;
@@ -5837,7 +5845,7 @@ PHP_FUNCTION(pg_select)
5837
5845
zend_string * sql = NULL ;
5838
5846
5839
5847
/* TODO Document result_type param on php.net (apparently it was added in PHP 7.1) */
5840
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "OPa|ll " ,
5848
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "OP|all " ,
5841
5849
& pgsql_link , pgsql_link_ce , & table , & ids , & option , & result_type
5842
5850
) == FAILURE ) {
5843
5851
RETURN_THROWS ();
0 commit comments