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 | |
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')
-rw-r--r-- | ext/pgsql/pgsql.c | 15 | ||||
-rw-r--r-- | ext/pgsql/pgsql.stub.php | 2 | ||||
-rw-r--r-- | ext/pgsql/pgsql_arginfo.h | 9 | ||||
-rw-r--r-- | ext/pgsql/php_pgsql.h | 2 | ||||
-rw-r--r-- | ext/pgsql/tests/03sync_query.phpt | 3 |
5 files changed, 16 insertions, 15 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)); } diff --git a/ext/pgsql/pgsql.stub.php b/ext/pgsql/pgsql.stub.php index 4e2b21e4f2..a6dfb5d185 100644 --- a/ext/pgsql/pgsql.stub.php +++ b/ext/pgsql/pgsql.stub.php @@ -193,7 +193,7 @@ function pg_fetch_array($result, ?int $row_number = null, int $result_type = PGS function pg_fetch_object($result, ?int $row_number = null, string $class_name = "stdClass", ?array $ctor_params = null): object|false {} /** @param resource $result */ -function pg_fetch_all($result, int $result_type = PGSQL_ASSOC): array|false {} +function pg_fetch_all($result, int $result_type = PGSQL_ASSOC): array {} /** @param resource $result */ function pg_fetch_all_columns($result, int $field_number = 0): array {} diff --git a/ext/pgsql/pgsql_arginfo.h b/ext/pgsql/pgsql_arginfo.h index f6cc2cf69c..a0f267c8ff 100644 --- a/ext/pgsql/pgsql_arginfo.h +++ b/ext/pgsql/pgsql_arginfo.h @@ -1,5 +1,5 @@ /* This is a generated file, edit the .stub.php file instead. - * Stub hash: 3f5e097d572721b42f2ad438c2af8c0d1f9c9086 */ + * Stub hash: 9735dbc8a4ca642ee825ae8942470ac2dec89f50 */ ZEND_BEGIN_ARG_INFO_EX(arginfo_pg_connect, 0, 0, 1) ZEND_ARG_TYPE_INFO(0, connection_string, IS_STRING, 0) @@ -155,7 +155,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_fetch_object, 0, 1, MAY_BE_OB ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, ctor_params, IS_ARRAY, 1, "null") ZEND_END_ARG_INFO() -ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_fetch_all, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_pg_fetch_all, 0, 1, IS_ARRAY, 0) ZEND_ARG_INFO(0, result) ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, result_type, IS_LONG, 0, "PGSQL_ASSOC") ZEND_END_ARG_INFO() @@ -385,7 +385,10 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_result_status, 0, 1, MAY_BE_S ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, result_type, IS_LONG, 0, "PGSQL_STATUS_LONG") ZEND_END_ARG_INFO() -#define arginfo_pg_get_notify arginfo_pg_fetch_all +ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_pg_get_notify, 0, 1, MAY_BE_ARRAY|MAY_BE_FALSE) + ZEND_ARG_INFO(0, result) + ZEND_ARG_TYPE_INFO_WITH_DEFAULT_VALUE(0, result_type, IS_LONG, 0, "PGSQL_ASSOC") +ZEND_END_ARG_INFO() #define arginfo_pg_get_pid arginfo_pg_connect_poll diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h index fe52d9ce96..3da04282d9 100644 --- a/ext/pgsql/php_pgsql.h +++ b/ext/pgsql/php_pgsql.h @@ -182,7 +182,7 @@ PHP_PGSQL_API int php_pgsql_insert(PGconn *pg_link, const char *table, zval *val PHP_PGSQL_API int php_pgsql_update(PGconn *pg_link, const char *table, zval *values, zval *ids, zend_ulong opt , zend_string **sql); PHP_PGSQL_API int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids, zend_ulong opt, zend_string **sql); PHP_PGSQL_API int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids, zval *ret_array, zend_ulong opt, long fetch_option, zend_string **sql ); -PHP_PGSQL_API int php_pgsql_result2array(PGresult *pg_result, zval *ret_array, long fetch_option); +PHP_PGSQL_API void php_pgsql_result2array(PGresult *pg_result, zval *ret_array, long fetch_option); /* internal functions */ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent); diff --git a/ext/pgsql/tests/03sync_query.phpt b/ext/pgsql/tests/03sync_query.phpt index ce062cafd6..cc3b1b86b9 100644 --- a/ext/pgsql/tests/03sync_query.phpt +++ b/ext/pgsql/tests/03sync_query.phpt @@ -125,6 +125,7 @@ try { $result = pg_query($db, "INSERT INTO ".$table_name." VALUES (9999, 'ABC');"); pg_last_oid($result); +var_dump(pg_fetch_all($result)); pg_free_result($result); pg_close($db); @@ -144,4 +145,6 @@ pg_field_name(): Argument #2 ($field_number) must be greater than or equal to 0 pg_field_name(): Argument #2 ($field_number) must be less than the number of fields for this result set pg_field_table(): Argument #2 ($field_number) must be greater than or equal to 0 pg_field_table(): Argument #2 ($field_number) must be less than the number of fields for this result set +array(0) { +} OK |