@@ -1723,20 +1723,24 @@ PHP_FUNCTION(pg_field_num)
1723
1723
/* {{{ Returns values from a result identifier */
1724
1724
PHP_FUNCTION (pg_fetch_result )
1725
1725
{
1726
- zval * result , * field = NULL ;
1727
- zend_long row ;
1726
+ zval * result ;
1727
+ zend_string * field_name ;
1728
+ zend_long row , field_offset ;
1728
1729
PGresult * pgsql_result ;
1729
1730
pgsql_result_handle * pg_result ;
1730
- int field_offset , pgsql_row , argc = ZEND_NUM_ARGS ();
1731
+ int pgsql_row , argc = ZEND_NUM_ARGS ();
1731
1732
1732
1733
if (argc == 2 ) {
1733
- if (zend_parse_parameters (argc , "rz" , & result , & field ) == FAILURE ) {
1734
- RETURN_THROWS ();
1735
- }
1734
+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
1735
+ Z_PARAM_RESOURCE (result )
1736
+ Z_PARAM_STR_OR_LONG (field_name , field_offset )
1737
+ ZEND_PARSE_PARAMETERS_END ();
1736
1738
} else {
1737
- if (zend_parse_parameters (argc , "rlz" , & result , & row , & field ) == FAILURE ) {
1738
- RETURN_THROWS ();
1739
- }
1739
+ ZEND_PARSE_PARAMETERS_START (3 , 3 )
1740
+ Z_PARAM_RESOURCE (result )
1741
+ Z_PARAM_LONG (row )
1742
+ Z_PARAM_STR_OR_LONG (field_name , field_offset )
1743
+ ZEND_PARSE_PARAMETERS_END ();
1740
1744
}
1741
1745
1742
1746
if ((pg_result = (pgsql_result_handle * )zend_fetch_resource (Z_RES_P (result ), "PostgreSQL result" , le_result )) == NULL ) {
@@ -1761,22 +1765,17 @@ PHP_FUNCTION(pg_fetch_result)
1761
1765
}
1762
1766
pgsql_row = (int )row ;
1763
1767
}
1764
- switch (Z_TYPE_P (field )) {
1765
- case IS_STRING :
1766
- field_offset = PQfnumber (pgsql_result , Z_STRVAL_P (field ));
1767
- if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
1768
- php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
1769
- RETURN_FALSE ;
1770
- }
1771
- break ;
1772
- default :
1773
- convert_to_long_ex (field );
1774
- if (Z_LVAL_P (field ) < 0 || Z_LVAL_P (field ) >= PQnfields (pgsql_result )) {
1775
- php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
1776
- RETURN_FALSE ;
1777
- }
1778
- field_offset = (int )Z_LVAL_P (field );
1779
- break ;
1768
+ if (field_name ) {
1769
+ field_offset = PQfnumber (pgsql_result , ZSTR_VAL (field_name ));
1770
+ if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
1771
+ php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
1772
+ RETURN_FALSE ;
1773
+ }
1774
+ } else {
1775
+ if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
1776
+ php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
1777
+ RETURN_FALSE ;
1778
+ }
1780
1779
}
1781
1780
1782
1781
if (PQgetisnull (pgsql_result , pgsql_row , field_offset )) {
@@ -1802,7 +1801,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
1802
1801
zend_class_entry * ce = NULL ;
1803
1802
1804
1803
if (into_object ) {
1805
- if (zend_parse_parameters (ZEND_NUM_ARGS (), "r|l!Cz " , & result , & row , & row_is_null , & ce , & ctor_params ) == FAILURE ) {
1804
+ if (zend_parse_parameters (ZEND_NUM_ARGS (), "r|l!Ca! " , & result , & row , & row_is_null , & ce , & ctor_params ) == FAILURE ) {
1806
1805
RETURN_THROWS ();
1807
1806
}
1808
1807
if (!ce ) {
@@ -1899,7 +1898,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, zend_long result_
1899
1898
fci .param_count = 0 ;
1900
1899
fci .named_params = NULL ;
1901
1900
1902
- if (ctor_params && Z_TYPE_P ( ctor_params ) != IS_NULL ) {
1901
+ if (ctor_params ) {
1903
1902
if (zend_fcall_info_args (& fci , ctor_params ) == FAILURE ) {
1904
1903
/* Two problems why we throw exceptions here: PHP is typeless
1905
1904
* and hence passing one argument that's not an array could be
@@ -2068,20 +2067,24 @@ PHP_FUNCTION(pg_result_seek)
2068
2067
/* {{{ php_pgsql_data_info */
2069
2068
static void php_pgsql_data_info (INTERNAL_FUNCTION_PARAMETERS , int entry_type )
2070
2069
{
2071
- zval * result , * field ;
2072
- zend_long row ;
2070
+ zval * result ;
2071
+ zend_string * field_name ;
2072
+ zend_long row , field_offset ;
2073
2073
PGresult * pgsql_result ;
2074
2074
pgsql_result_handle * pg_result ;
2075
- int field_offset , pgsql_row , argc = ZEND_NUM_ARGS ();
2075
+ int pgsql_row , argc = ZEND_NUM_ARGS ();
2076
2076
2077
2077
if (argc == 2 ) {
2078
- if (zend_parse_parameters (argc , "rz" , & result , & field ) == FAILURE ) {
2079
- RETURN_THROWS ();
2080
- }
2078
+ ZEND_PARSE_PARAMETERS_START (2 , 2 )
2079
+ Z_PARAM_RESOURCE (result )
2080
+ Z_PARAM_STR_OR_LONG (field_name , field_offset )
2081
+ ZEND_PARSE_PARAMETERS_END ();
2081
2082
} else {
2082
- if (zend_parse_parameters (argc , "rlz" , & result , & row , & field ) == FAILURE ) {
2083
- RETURN_THROWS ();
2084
- }
2083
+ ZEND_PARSE_PARAMETERS_START (3 , 3 )
2084
+ Z_PARAM_RESOURCE (result )
2085
+ Z_PARAM_LONG (row )
2086
+ Z_PARAM_STR_OR_LONG (field_name , field_offset )
2087
+ ZEND_PARSE_PARAMETERS_END ();
2085
2088
}
2086
2089
2087
2090
if ((pg_result = (pgsql_result_handle * )zend_fetch_resource (Z_RES_P (result ), "PostgreSQL result" , le_result )) == NULL ) {
@@ -2106,22 +2109,17 @@ static void php_pgsql_data_info(INTERNAL_FUNCTION_PARAMETERS, int entry_type)
2106
2109
pgsql_row = (int )row ;
2107
2110
}
2108
2111
2109
- switch (Z_TYPE_P (field )) {
2110
- case IS_STRING :
2111
- field_offset = PQfnumber (pgsql_result , Z_STRVAL_P (field ));
2112
- if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
2113
- php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
2114
- RETURN_FALSE ;
2115
- }
2116
- break ;
2117
- default :
2118
- convert_to_long_ex (field );
2119
- if (Z_LVAL_P (field ) < 0 || Z_LVAL_P (field ) >= PQnfields (pgsql_result )) {
2120
- php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
2121
- RETURN_FALSE ;
2122
- }
2123
- field_offset = (int )Z_LVAL_P (field );
2124
- break ;
2112
+ if (field_name ) {
2113
+ field_offset = PQfnumber (pgsql_result , ZSTR_VAL (field_name ));
2114
+ if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
2115
+ php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
2116
+ RETURN_FALSE ;
2117
+ }
2118
+ } else {
2119
+ if (field_offset < 0 || field_offset >= PQnfields (pgsql_result )) {
2120
+ php_error_docref (NULL , E_WARNING , "Bad column offset specified" );
2121
+ RETURN_FALSE ;
2122
+ }
2125
2123
}
2126
2124
2127
2125
switch (entry_type ) {
0 commit comments