From: Derick Rethans Date: Sat, 2 Mar 2002 19:53:11 +0000 (+0000) Subject: - Make the 2nd parameter to pgsql_fetch_* support NULL in case 3 parameters X-Git-Tag: php-4.2.0RC1~186 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bc7e0b55121755e35e1a659e1d82822e3b7fcde8;p=php - Make the 2nd parameter to pgsql_fetch_* support NULL in case 3 parameters are supplied, but you do not want to provide a row number yourself. @- Make the 2nd parameter to pgsql_fetch_* support NULL in case 3 @ parameters are supplied, but you do not want to provide a row number @ yourself. (Derick) --- diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 4ed4046844..6e6e5ced5f 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -1162,8 +1162,7 @@ PHP_FUNCTION(pg_fetch_result) } /* }}} */ -/* {{{ void php_pgsql_fetch_hash - */ +/* {{{ void php_pgsql_fetch_hash */ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) { zval **result, **row, **arg3; @@ -1175,7 +1174,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) switch (ZEND_NUM_ARGS()) { case 1: - if (zend_get_parameters_ex(1, &result)==FAILURE) { + if (zend_get_parameters_ex(1, &result) == FAILURE) { RETURN_FALSE; } if (!result_type) { @@ -1183,7 +1182,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) } break; case 2: - if (zend_get_parameters_ex(2, &result, &row)==FAILURE) { + if (zend_get_parameters_ex(2, &result, &row) == FAILURE) { RETURN_FALSE; } if (!result_type) { @@ -1191,7 +1190,7 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) } break; case 3: - if (zend_get_parameters_ex(3, &result, &row, &arg3)==FAILURE) { + if (zend_get_parameters_ex(3, &result, &row, &arg3) == FAILURE) { RETURN_FALSE; } convert_to_long_ex(arg3); @@ -1213,16 +1212,25 @@ static void php_pgsql_fetch_hash(INTERNAL_FUNCTION_PARAMETERS, int result_type) RETURN_FALSE; } } else { - convert_to_long_ex(row); - pgsql_row = Z_LVAL_PP(row); - pg_result->row = pgsql_row; - if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) { - php_error(E_WARNING,"Unable to jump to row %d on PostgreSQL result index %d", Z_LVAL_PP(row), Z_LVAL_PP(result)); - RETURN_FALSE; + if (Z_TYPE_PP(row) != IS_NULL) { + convert_to_long_ex(row); + pgsql_row = Z_LVAL_PP(row); + pg_result->row = pgsql_row; + if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) { + php_error(E_WARNING, "Unable to jump to row %d on PostgreSQL result index %d", Z_LVAL_PP(row), Z_LVAL_PP(result)); + RETURN_FALSE; + } + } else { + /* If 2nd param is NULL, ignore it and use the normal way of accessing the next row */ + pg_result->row++; + pgsql_row = pg_result->row; + if (pgsql_row < 0 || pgsql_row >= PQntuples(pgsql_result)) { + RETURN_FALSE; + } } } array_init(return_value); - for (i = 0, num_fields = PQnfields(pgsql_result); i