diff options
| author | Nikita Popov <nikita.ppv@gmail.com> | 2020-09-21 17:20:28 +0200 |
|---|---|---|
| committer | Nikita Popov <nikita.ppv@gmail.com> | 2020-09-21 17:22:02 +0200 |
| commit | 8ff2f2f84b2c0ea33b38f7e98aaa710ce4f3fc91 (patch) | |
| tree | e92deebd212e1134cfe3d3ad616419d1f26c99a7 /ext/pgsql/pgsql.c | |
| parent | fb4554e431e4f4063917c1a80ad2e929e6768d0b (diff) | |
| download | php-git-8ff2f2f84b2c0ea33b38f7e98aaa710ce4f3fc91.tar.gz | |
Return empty array for no rows in pg_fetch_all()
This makes it line up with pg_fetch_all_columns(), as well as
similar functions in other exts, such as mysqli_fetch_all().
Diffstat (limited to 'ext/pgsql/pgsql.c')
| -rw-r--r-- | ext/pgsql/pgsql.c | 15 |
1 files changed, 5 insertions, 10 deletions
diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index b2b08f7fc1..c08ed40d01 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -2015,10 +2015,7 @@ PHP_FUNCTION(pg_fetch_all) pgsql_result = pg_result->result; array_init(return_value); - if (php_pgsql_result2array(pgsql_result, return_value, result_type) == FAILURE) { - zend_array_destroy(Z_ARR_P(return_value)); - RETURN_FALSE; - } + php_pgsql_result2array(pgsql_result, return_value, result_type); } /* }}} */ @@ -5796,7 +5793,7 @@ PHP_FUNCTION(pg_delete) /* }}} */ /* {{{ php_pgsql_result2array */ -PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array, long result_type) +PHP_PGSQL_API void php_pgsql_result2array(PGresult *pg_result, zval *ret_array, long result_type) { zval row; char *field_name; @@ -5805,9 +5802,7 @@ PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array, l uint32_t i; assert(Z_TYPE_P(ret_array) == IS_ARRAY); - if ((pg_numrows = PQntuples(pg_result)) <= 0) { - return FAILURE; - } + pg_numrows = PQntuples(pg_result); for (pg_row = 0; pg_row < pg_numrows; pg_row++) { array_init(&row); for (i = 0, num_fields = PQnfields(pg_result); i < num_fields; i++) { @@ -5834,7 +5829,6 @@ PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array, l } add_index_zval(ret_array, pg_row, &row); } - return SUCCESS; } /* }}} */ @@ -5877,7 +5871,8 @@ PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array, l pg_result = PQexec(pg_link, ZSTR_VAL(querystr.s)); if (PQresultStatus(pg_result) == PGRES_TUPLES_OK) { - ret = php_pgsql_result2array(pg_result, ret_array, result_type); + php_pgsql_result2array(pg_result, ret_array, result_type); + ret = SUCCESS; } else { php_error_docref(NULL, E_NOTICE, "Failed to execute '%s'", ZSTR_VAL(querystr.s)); } |
