@@ -1159,17 +1159,14 @@ PHP_FUNCTION(pg_query)
1159
1159
1160
1160
link = FETCH_DEFAULT_LINK ();
1161
1161
CHECK_DEFAULT_LINK (link );
1162
- } else if ( ZEND_NUM_ARGS () == 2 ) {
1162
+ } else {
1163
1163
ZEND_PARSE_PARAMETERS_START (2 , 2 )
1164
1164
Z_PARAM_OBJECT_OF_CLASS (pgsql_link , pgsql_link_ce )
1165
1165
Z_PARAM_STRING (query , query_len )
1166
1166
ZEND_PARSE_PARAMETERS_END ();
1167
1167
1168
1168
link = Z_PGSQL_LINK_P (pgsql_link );
1169
1169
CHECK_PGSQL_LINK (link );
1170
- } else {
1171
- zend_wrong_parameters_count_error (1 , 2 );
1172
- RETURN_THROWS ();
1173
1170
}
1174
1171
1175
1172
pgsql = link -> conn ;
@@ -1260,7 +1257,7 @@ PHP_FUNCTION(pg_query_params)
1260
1257
1261
1258
link = FETCH_DEFAULT_LINK ();
1262
1259
CHECK_DEFAULT_LINK (link );
1263
- } else if ( ZEND_NUM_ARGS () == 3 ) {
1260
+ } else {
1264
1261
ZEND_PARSE_PARAMETERS_START (3 , 3 )
1265
1262
Z_PARAM_OBJECT_OF_CLASS (pgsql_link , pgsql_link_ce )
1266
1263
Z_PARAM_STRING (query , query_len )
@@ -1269,9 +1266,6 @@ PHP_FUNCTION(pg_query_params)
1269
1266
1270
1267
link = Z_PGSQL_LINK_P (pgsql_link );
1271
1268
CHECK_PGSQL_LINK (link );
1272
- } else {
1273
- zend_wrong_parameters_count_error (2 , 3 );
1274
- RETURN_THROWS ();
1275
1269
}
1276
1270
1277
1271
pgsql = link -> conn ;
@@ -1373,7 +1367,7 @@ PHP_FUNCTION(pg_prepare)
1373
1367
1374
1368
link = FETCH_DEFAULT_LINK ();
1375
1369
CHECK_DEFAULT_LINK (link );
1376
- } else if ( ZEND_NUM_ARGS () == 3 ) {
1370
+ } else {
1377
1371
ZEND_PARSE_PARAMETERS_START (3 , 3 )
1378
1372
Z_PARAM_OBJECT_OF_CLASS (pgsql_link , pgsql_link_ce )
1379
1373
Z_PARAM_STRING (stmtname , stmtname_len )
@@ -1382,9 +1376,6 @@ PHP_FUNCTION(pg_prepare)
1382
1376
1383
1377
link = Z_PGSQL_LINK_P (pgsql_link );
1384
1378
CHECK_PGSQL_LINK (link );
1385
- } else {
1386
- zend_wrong_parameters_count_error (2 , 3 );
1387
- RETURN_THROWS ();
1388
1379
}
1389
1380
1390
1381
pgsql = link -> conn ;
@@ -1462,7 +1453,7 @@ PHP_FUNCTION(pg_execute)
1462
1453
1463
1454
link = FETCH_DEFAULT_LINK ();
1464
1455
CHECK_DEFAULT_LINK (link );
1465
- } else if ( ZEND_NUM_ARGS () == 3 ) {
1456
+ } else {
1466
1457
ZEND_PARSE_PARAMETERS_START (3 , 3 )
1467
1458
Z_PARAM_OBJECT_OF_CLASS (pgsql_link , pgsql_link_ce )
1468
1459
Z_PARAM_STRING (stmtname , stmtname_len )
@@ -1471,9 +1462,6 @@ PHP_FUNCTION(pg_execute)
1471
1462
1472
1463
link = Z_PGSQL_LINK_P (pgsql_link );
1473
1464
CHECK_PGSQL_LINK (link );
1474
- } else {
1475
- zend_wrong_parameters_count_error (2 , 3 );
1476
- RETURN_THROWS ();
1477
1465
}
1478
1466
1479
1467
pgsql = link -> conn ;
@@ -1928,7 +1916,7 @@ PHP_FUNCTION(pg_fetch_result)
1928
1916
Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
1929
1917
Z_PARAM_STR_OR_LONG (field_name , field_offset )
1930
1918
ZEND_PARSE_PARAMETERS_END ();
1931
- } else if ( ZEND_NUM_ARGS () == 3 ) {
1919
+ } else {
1932
1920
ZEND_PARSE_PARAMETERS_START (3 , 3 )
1933
1921
Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
1934
1922
if (zend_string_equals_literal (EG (current_execute_data )-> func -> common .function_name , "pg_result" )) {
@@ -1938,9 +1926,6 @@ PHP_FUNCTION(pg_fetch_result)
1938
1926
}
1939
1927
Z_PARAM_STR_OR_LONG (field_name , field_offset )
1940
1928
ZEND_PARSE_PARAMETERS_END ();
1941
- } else {
1942
- zend_wrong_parameters_count_error (2 , 3 );
1943
- RETURN_THROWS ();
1944
1929
}
1945
1930
1946
1931
pg_result = Z_PGSQL_RESULT_P (result );
@@ -1984,39 +1969,12 @@ PHP_FUNCTION(pg_fetch_result)
1984
1969
/* }}} */
1985
1970
1986
1971
/* {{{ void php_pgsql_fetch_hash */
1987
- static void php_pgsql_fetch_hash (INTERNAL_FUNCTION_PARAMETERS , zend_long result_type , int into_object )
1972
+ static void php_pgsql_fetch_hash (zval * return_value , const zval * result , zend_long row , bool row_is_null , zend_long result_type )
1988
1973
{
1989
- zval * result ;
1990
1974
PGresult * pgsql_result ;
1991
1975
pgsql_result_handle * pg_result ;
1992
1976
int i , num_fields , pgsql_row ;
1993
- zend_long row ;
1994
- bool row_is_null = true;
1995
1977
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
1978
2021
1979
if (!row_is_null && row < 0 ) {
2022
1980
zend_argument_value_error (2 , "must be greater than or equal to 0" );
@@ -2060,7 +2018,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
2060
2018
add_assoc_null (return_value , field_name );
2061
2019
}
2062
2020
} else {
2063
- char * element = PQgetvalue (pgsql_result , pgsql_row , i );
2021
+ const char * element = PQgetvalue (pgsql_result , pgsql_row , i );
2064
2022
if (element ) {
2065
2023
const size_t element_len = strlen (element );
2066
2024
@@ -2075,63 +2033,110 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
2075
2033
}
2076
2034
}
2077
2035
}
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
2036
}
2102
2037
/* }}} */
2103
2038
2104
2039
/* {{{ Get a row as an enumerated array */
2105
2040
PHP_FUNCTION (pg_fetch_row )
2106
2041
{
2107
- php_pgsql_fetch_hash (INTERNAL_FUNCTION_PARAM_PASSTHRU , PGSQL_NUM , 0 );
2042
+ zval * result ;
2043
+ zend_long row ;
2044
+ bool row_is_null = true;
2045
+ zend_long result_type = PGSQL_NUM ;
2046
+
2047
+ ZEND_PARSE_PARAMETERS_START (1 , 3 )
2048
+ Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2049
+ Z_PARAM_OPTIONAL
2050
+ Z_PARAM_LONG_OR_NULL (row , row_is_null )
2051
+ Z_PARAM_LONG (result_type )
2052
+ ZEND_PARSE_PARAMETERS_END ();
2053
+
2054
+ php_pgsql_fetch_hash (return_value , result , row , row_is_null , result_type );
2108
2055
}
2109
2056
/* }}} */
2110
2057
2111
2058
/* {{{ Fetch a row as an assoc array */
2112
2059
PHP_FUNCTION (pg_fetch_assoc )
2113
2060
{
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 );
2061
+ zval * result ;
2062
+ zend_long row ;
2063
+ bool row_is_null = true;
2064
+
2065
+ ZEND_PARSE_PARAMETERS_START (1 , 2 )
2066
+ Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2067
+ Z_PARAM_OPTIONAL
2068
+ Z_PARAM_LONG_OR_NULL (row , row_is_null )
2069
+ ZEND_PARSE_PARAMETERS_END ();
2070
+
2071
+ php_pgsql_fetch_hash (return_value , result , row , row_is_null , PGSQL_ASSOC );
2119
2072
}
2120
2073
/* }}} */
2121
2074
2122
2075
/* {{{ Fetch a row as an array */
2123
2076
PHP_FUNCTION (pg_fetch_array )
2124
2077
{
2125
- php_pgsql_fetch_hash (INTERNAL_FUNCTION_PARAM_PASSTHRU , PGSQL_BOTH , 0 );
2078
+ zval * result ;
2079
+ zend_long row ;
2080
+ bool row_is_null = true;
2081
+ zend_long result_type = PGSQL_BOTH ;
2082
+
2083
+ ZEND_PARSE_PARAMETERS_START (1 , 3 )
2084
+ Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2085
+ Z_PARAM_OPTIONAL
2086
+ Z_PARAM_LONG_OR_NULL (row , row_is_null )
2087
+ Z_PARAM_LONG (result_type )
2088
+ ZEND_PARSE_PARAMETERS_END ();
2089
+
2090
+ php_pgsql_fetch_hash (return_value , result , row , row_is_null , result_type );
2126
2091
}
2127
2092
/* }}} */
2128
2093
2129
2094
/* {{{ Fetch a row as an object */
2130
2095
PHP_FUNCTION (pg_fetch_object )
2131
2096
{
2097
+ zval * result ;
2098
+ zend_long row ;
2099
+ bool row_is_null = true;
2100
+ zend_class_entry * ce = NULL ;
2101
+ HashTable * ctor_params = NULL ;
2102
+
2103
+ ZEND_PARSE_PARAMETERS_START (1 , 4 )
2104
+ Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2105
+ Z_PARAM_OPTIONAL
2106
+ Z_PARAM_LONG_OR_NULL (row , row_is_null )
2107
+ Z_PARAM_CLASS (ce )
2108
+ Z_PARAM_ARRAY_HT (ctor_params )
2109
+ ZEND_PARSE_PARAMETERS_END ();
2110
+
2111
+ if (!ce ) {
2112
+ ce = zend_standard_class_def ;
2113
+ }
2114
+
2115
+ if (!ce -> constructor && ctor_params && zend_hash_num_elements (ctor_params ) > 0 ) {
2116
+ zend_argument_value_error (3 ,
2117
+ "must be empty when the specified class (%s) does not have a constructor" ,
2118
+ ZSTR_VAL (ce -> name )
2119
+ );
2120
+ RETURN_THROWS ();
2121
+ }
2122
+
2132
2123
/* pg_fetch_object() allowed result_type used to be. 3rd parameter
2133
2124
must be allowed for compatibility */
2134
- php_pgsql_fetch_hash (INTERNAL_FUNCTION_PARAM_PASSTHRU , PGSQL_ASSOC , 1 );
2125
+ zval dataset ;
2126
+ php_pgsql_fetch_hash (& dataset , result , row , row_is_null , PGSQL_ASSOC );
2127
+
2128
+ object_init_ex (return_value , ce );
2129
+ if (!ce -> default_properties_count && !ce -> __set ) {
2130
+ Z_OBJ_P (return_value )-> properties = Z_ARR (dataset );
2131
+ } else {
2132
+ zend_merge_properties (return_value , Z_ARRVAL (dataset ));
2133
+ zval_ptr_dtor (& dataset );
2134
+ }
2135
+
2136
+ if (ce -> constructor ) {
2137
+ zend_call_known_function (ce -> constructor , Z_OBJ_P (return_value ), Z_OBJCE_P (return_value ),
2138
+ /* retval */ NULL , /* argc */ 0 , /* params */ NULL , ctor_params );
2139
+ }
2135
2140
}
2136
2141
/* }}} */
2137
2142
@@ -2265,7 +2270,7 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type, bo
2265
2270
Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2266
2271
Z_PARAM_STR_OR_LONG (field_name , field_offset )
2267
2272
ZEND_PARSE_PARAMETERS_END ();
2268
- } else if ( ZEND_NUM_ARGS () == 3 ) {
2273
+ } else {
2269
2274
ZEND_PARSE_PARAMETERS_START (3 , 3 )
2270
2275
Z_PARAM_OBJECT_OF_CLASS (result , pgsql_result_ce )
2271
2276
if (nullable_row ) {
@@ -2275,9 +2280,6 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type, bo
2275
2280
}
2276
2281
Z_PARAM_STR_OR_LONG (field_name , field_offset )
2277
2282
ZEND_PARSE_PARAMETERS_END ();
2278
- } else {
2279
- zend_wrong_parameters_count_error (2 , 3 );
2280
- RETURN_THROWS ();
2281
2283
}
2282
2284
2283
2285
pg_result = Z_PGSQL_RESULT_P (result );
@@ -2865,19 +2867,19 @@ PHP_FUNCTION(pg_lo_import)
2865
2867
Oid returned_oid ;
2866
2868
pgsql_link_handle * link ;
2867
2869
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 ) {
2870
+ /* Deprecated signature with implicit connection */
2871
+ if (zend_parse_parameters_ex (ZEND_PARSE_PARAMS_QUIET , ZEND_NUM_ARGS (), "P|z" , & file_in , & oid ) == SUCCESS ) {
2875
2872
link = FETCH_DEFAULT_LINK ();
2876
2873
CHECK_DEFAULT_LINK (link );
2874
+ goto fn_body ;
2877
2875
}
2878
- else {
2879
- WRONG_PARAM_COUNT ;
2876
+ if ( zend_parse_parameters ( ZEND_NUM_ARGS (), "OP|z" , & pgsql_link , pgsql_link_ce , & file_in , & oid ) == FAILURE ) {
2877
+ RETURN_THROWS () ;
2880
2878
}
2879
+ link = Z_PGSQL_LINK_P (pgsql_link );
2880
+ CHECK_PGSQL_LINK (link );
2881
+
2882
+ fn_body :
2881
2883
2882
2884
if (php_check_open_basedir (ZSTR_VAL (file_in ))) {
2883
2885
RETURN_FALSE ;
@@ -3108,17 +3110,14 @@ PHP_FUNCTION(pg_set_error_verbosity)
3108
3110
3109
3111
link = FETCH_DEFAULT_LINK ();
3110
3112
CHECK_DEFAULT_LINK (link );
3111
- } else if ( ZEND_NUM_ARGS () == 2 ) {
3113
+ } else {
3112
3114
ZEND_PARSE_PARAMETERS_START (2 , 2 )
3113
3115
Z_PARAM_OBJECT_OF_CLASS (pgsql_link , pgsql_link_ce )
3114
3116
Z_PARAM_LONG (verbosity )
3115
3117
ZEND_PARSE_PARAMETERS_END ();
3116
3118
3117
3119
link = Z_PGSQL_LINK_P (pgsql_link );
3118
3120
CHECK_PGSQL_LINK (link );
3119
- } else {
3120
- zend_wrong_parameters_count_error (1 , 2 );
3121
- RETURN_THROWS ();
3122
3121
}
3123
3122
3124
3123
pgsql = link -> conn ;
@@ -3189,17 +3188,14 @@ PHP_FUNCTION(pg_set_client_encoding)
3189
3188
3190
3189
link = FETCH_DEFAULT_LINK ();
3191
3190
CHECK_DEFAULT_LINK (link );
3192
- } else if ( ZEND_NUM_ARGS () == 2 ) {
3191
+ } else {
3193
3192
ZEND_PARSE_PARAMETERS_START (2 , 2 )
3194
3193
Z_PARAM_OBJECT_OF_CLASS (pgsql_link , pgsql_link_ce )
3195
3194
Z_PARAM_STRING (encoding , encoding_len )
3196
3195
ZEND_PARSE_PARAMETERS_END ();
3197
3196
3198
3197
link = Z_PGSQL_LINK_P (pgsql_link );
3199
3198
CHECK_PGSQL_LINK (link );
3200
- } else {
3201
- zend_wrong_parameters_count_error (1 , 2 );
3202
- RETURN_THROWS ();
3203
3199
}
3204
3200
3205
3201
pgsql = link -> conn ;
@@ -3286,17 +3282,14 @@ PHP_FUNCTION(pg_put_line)
3286
3282
3287
3283
link = FETCH_DEFAULT_LINK ();
3288
3284
CHECK_DEFAULT_LINK (link );
3289
- } else if ( ZEND_NUM_ARGS () == 2 ) {
3285
+ } else {
3290
3286
ZEND_PARSE_PARAMETERS_START (2 , 2 )
3291
3287
Z_PARAM_OBJECT_OF_CLASS (pgsql_link , pgsql_link_ce )
3292
3288
Z_PARAM_STRING (query , query_len )
3293
3289
ZEND_PARSE_PARAMETERS_END ();
3294
3290
3295
3291
link = Z_PGSQL_LINK_P (pgsql_link );
3296
3292
CHECK_PGSQL_LINK (link );
3297
- } else {
3298
- zend_wrong_parameters_count_error (1 , 2 );
3299
- RETURN_THROWS ();
3300
3293
}
3301
3294
3302
3295
pgsql = link -> conn ;
0 commit comments