@@ -1984,39 +1984,12 @@ PHP_FUNCTION(pg_fetch_result)
1984
1984
/* }}} */
1985
1985
1986
1986
/* {{{ void php_pgsql_fetch_hash */
1987
- static void php_pgsql_fetch_hash (INTERNAL_FUNCTION_PARAMETERS , zend_long result_type , int into_object )
1987
+ static void php_pgsql_fetch_hash (zval * return_value , const zval * result , zend_long row , bool row_is_null , zend_long result_type )
1988
1988
{
1989
- zval * result ;
1990
1989
PGresult * pgsql_result ;
1991
1990
pgsql_result_handle * pg_result ;
1992
1991
int i , num_fields , pgsql_row ;
1993
- zend_long row ;
1994
- bool row_is_null = true;
1995
1992
char * field_name ;
1996
- HashTable * ctor_params = NULL ;
1997
- zend_class_entry * ce = NULL ;
1998
-
1999
- if (into_object ) {
2000
- ZEND_PARSE_PARAMETERS_START (1 , 4 )
2001
- Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2002
- Z_PARAM_OPTIONAL
2003
- Z_PARAM_LONG_OR_NULL (row , row_is_null )
2004
- Z_PARAM_CLASS (ce )
2005
- Z_PARAM_ARRAY_HT (ctor_params )
2006
- ZEND_PARSE_PARAMETERS_END ();
2007
-
2008
- if (!ce ) {
2009
- ce = zend_standard_class_def ;
2010
- }
2011
- result_type = PGSQL_ASSOC ;
2012
- } else {
2013
- ZEND_PARSE_PARAMETERS_START (1 , 3 )
2014
- Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2015
- Z_PARAM_OPTIONAL
2016
- Z_PARAM_LONG_OR_NULL (row , row_is_null )
2017
- Z_PARAM_LONG (result_type )
2018
- ZEND_PARSE_PARAMETERS_END ();
2019
- }
2020
1993
2021
1994
if (!row_is_null && row < 0 ) {
2022
1995
zend_argument_value_error (2 , "must be greater than or equal to 0" );
@@ -2060,7 +2033,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
2060
2033
add_assoc_null (return_value , field_name );
2061
2034
}
2062
2035
} else {
2063
- char * element = PQgetvalue (pgsql_result , pgsql_row , i );
2036
+ const char * element = PQgetvalue (pgsql_result , pgsql_row , i );
2064
2037
if (element ) {
2065
2038
const size_t element_len = strlen (element );
2066
2039
@@ -2075,63 +2048,110 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
2075
2048
}
2076
2049
}
2077
2050
}
2078
-
2079
- if (into_object ) {
2080
- zval dataset ;
2081
-
2082
- ZVAL_COPY_VALUE (& dataset , return_value );
2083
- object_init_ex (return_value , ce );
2084
- if (!ce -> default_properties_count && !ce -> __set ) {
2085
- Z_OBJ_P (return_value )-> properties = Z_ARR (dataset );
2086
- } else {
2087
- zend_merge_properties (return_value , Z_ARRVAL (dataset ));
2088
- zval_ptr_dtor (& dataset );
2089
- }
2090
-
2091
- if (ce -> constructor ) {
2092
- zend_call_known_function (ce -> constructor , Z_OBJ_P (return_value ), Z_OBJCE_P (return_value ),
2093
- /* retval */ NULL , /* argc */ 0 , /* params */ NULL , ctor_params );
2094
- } else if (ctor_params && zend_hash_num_elements (ctor_params ) > 0 ) {
2095
- zend_argument_value_error (3 ,
2096
- "must be empty when the specified class (%s) does not have a constructor" ,
2097
- ZSTR_VAL (ce -> name )
2098
- );
2099
- }
2100
- }
2101
2051
}
2102
2052
/* }}} */
2103
2053
2104
2054
/* {{{ Get a row as an enumerated array */
2105
2055
PHP_FUNCTION (pg_fetch_row )
2106
2056
{
2107
- php_pgsql_fetch_hash (INTERNAL_FUNCTION_PARAM_PASSTHRU , PGSQL_NUM , 0 );
2057
+ zval * result ;
2058
+ zend_long row ;
2059
+ bool row_is_null = true;
2060
+ zend_long result_type = PGSQL_NUM ;
2061
+
2062
+ ZEND_PARSE_PARAMETERS_START (1 , 3 )
2063
+ Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2064
+ Z_PARAM_OPTIONAL
2065
+ Z_PARAM_LONG_OR_NULL (row , row_is_null )
2066
+ Z_PARAM_LONG (result_type )
2067
+ ZEND_PARSE_PARAMETERS_END ();
2068
+
2069
+ php_pgsql_fetch_hash (return_value , result , row , row_is_null , result_type );
2108
2070
}
2109
2071
/* }}} */
2110
2072
2111
2073
/* {{{ Fetch a row as an assoc array */
2112
2074
PHP_FUNCTION (pg_fetch_assoc )
2113
2075
{
2114
- /* pg_fetch_assoc() is added from PHP 4.3.0. It should raise error, when
2115
- there is 3rd parameter */
2116
- if (ZEND_NUM_ARGS () > 2 )
2117
- WRONG_PARAM_COUNT ;
2118
- php_pgsql_fetch_hash (INTERNAL_FUNCTION_PARAM_PASSTHRU , PGSQL_ASSOC , 0 );
2076
+ zval * result ;
2077
+ zend_long row ;
2078
+ bool row_is_null = true;
2079
+
2080
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
2081
+ Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2082
+ Z_PARAM_OPTIONAL
2083
+ Z_PARAM_LONG_OR_NULL (row , row_is_null )
2084
+ ZEND_PARSE_PARAMETERS_END ();
2085
+
2086
+ php_pgsql_fetch_hash (return_value , result , row , row_is_null , PGSQL_ASSOC );
2119
2087
}
2120
2088
/* }}} */
2121
2089
2122
2090
/* {{{ Fetch a row as an array */
2123
2091
PHP_FUNCTION (pg_fetch_array )
2124
2092
{
2125
- php_pgsql_fetch_hash (INTERNAL_FUNCTION_PARAM_PASSTHRU , PGSQL_BOTH , 0 );
2093
+ zval * result ;
2094
+ zend_long row ;
2095
+ bool row_is_null = true;
2096
+ zend_long result_type = PGSQL_BOTH ;
2097
+
2098
+ ZEND_PARSE_PARAMETERS_START (1 , 3 )
2099
+ Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2100
+ Z_PARAM_OPTIONAL
2101
+ Z_PARAM_LONG_OR_NULL (row , row_is_null )
2102
+ Z_PARAM_LONG (result_type )
2103
+ ZEND_PARSE_PARAMETERS_END ();
2104
+
2105
+ php_pgsql_fetch_hash (return_value , result , row , row_is_null , result_type );
2126
2106
}
2127
2107
/* }}} */
2128
2108
2129
2109
/* {{{ Fetch a row as an object */
2130
2110
PHP_FUNCTION (pg_fetch_object )
2131
2111
{
2112
+ zval * result ;
2113
+ zend_long row ;
2114
+ bool row_is_null = true;
2115
+ zend_class_entry * ce = NULL ;
2116
+ HashTable * ctor_params = NULL ;
2117
+
2118
+ ZEND_PARSE_PARAMETERS_START (1 , 4 )
2119
+ Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2120
+ Z_PARAM_OPTIONAL
2121
+ Z_PARAM_LONG_OR_NULL (row , row_is_null )
2122
+ Z_PARAM_CLASS (ce )
2123
+ Z_PARAM_ARRAY_HT (ctor_params )
2124
+ ZEND_PARSE_PARAMETERS_END ();
2125
+
2126
+ if (!ce ) {
2127
+ ce = zend_standard_class_def ;
2128
+ }
2129
+
2130
+ if (!ce -> constructor && ctor_params && zend_hash_num_elements (ctor_params ) > 0 ) {
2131
+ zend_argument_value_error (3 ,
2132
+ "must be empty when the specified class (%s) does not have a constructor" ,
2133
+ ZSTR_VAL (ce -> name )
2134
+ );
2135
+ RETURN_THROWS ();
2136
+ }
2137
+
2132
2138
/* pg_fetch_object() allowed result_type used to be. 3rd parameter
2133
2139
must be allowed for compatibility */
2134
- php_pgsql_fetch_hash (INTERNAL_FUNCTION_PARAM_PASSTHRU , PGSQL_ASSOC , 1 );
2140
+ zval dataset ;
2141
+ php_pgsql_fetch_hash (& dataset , result , row , row_is_null , PGSQL_ASSOC );
2142
+
2143
+ object_init_ex (return_value , ce );
2144
+ if (!ce -> default_properties_count && !ce -> __set ) {
2145
+ Z_OBJ_P (return_value )-> properties = Z_ARR (dataset );
2146
+ } else {
2147
+ zend_merge_properties (return_value , Z_ARRVAL (dataset ));
2148
+ zval_ptr_dtor (& dataset );
2149
+ }
2150
+
2151
+ if (ce -> constructor ) {
2152
+ zend_call_known_function (ce -> constructor , Z_OBJ_P (return_value ), Z_OBJCE_P (return_value ),
2153
+ /* retval */ NULL , /* argc */ 0 , /* params */ NULL , ctor_params );
2154
+ }
2135
2155
}
2136
2156
/* }}} */
2137
2157
@@ -2865,19 +2885,19 @@ PHP_FUNCTION(pg_lo_import)
2865
2885
Oid returned_oid ;
2866
2886
pgsql_link_handle * link ;
2867
2887
2868
- if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS (),
2869
- "OP|z" , & pgsql_link , pgsql_link_ce , & file_in , & oid ) == SUCCESS ) {
2870
- link = Z_PGSQL_LINK_P (pgsql_link );
2871
- CHECK_PGSQL_LINK (link );
2872
- }
2873
- else if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS (),
2874
- "P|z" , & file_in , & oid ) == SUCCESS ) {
2888
+ /* Deprecated signature with implicit connection */
2889
+ if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS (), "P|z" , & file_in , & oid ) == SUCCESS ) {
2875
2890
link = FETCH_DEFAULT_LINK ();
2876
2891
CHECK_DEFAULT_LINK (link );
2892
+ goto fn_body ;
2877
2893
}
2878
- else {
2879
- WRONG_PARAM_COUNT ;
2894
+ if ( zend_parse_parameters ( ZEND_NUM_ARGS (), "OP|z" , & pgsql_link , pgsql_link_ce , & file_in , & oid ) == FAILURE ) {
2895
+ RETURN_THROWS () ;
2880
2896
}
2897
+ link = Z_PGSQL_LINK_P (pgsql_link );
2898
+ CHECK_PGSQL_LINK (link );
2899
+
2900
+ fn_body :
2881
2901
2882
2902
if (php_check_open_basedir (ZSTR_VAL (file_in ))) {
2883
2903
RETURN_FALSE ;
0 commit comments