From 36e80ddc15b42048abbad5958aaaa75d3de4d21f Mon Sep 17 00:00:00 2001 From: Yasuo Ohgaki Date: Sun, 21 Jul 2002 07:25:10 +0000 Subject: [PATCH] Added pg_fetch_all() that fetch all rows in result. Useful and faster when there is enough memory. @Added pg_fetch_all() that fetch all rows in result. (Yasuo) --- ext/pgsql/pgsql.c | 25 +++++++++++++++++++++++++ ext/pgsql/php_pgsql.h | 2 ++ 2 files changed, 27 insertions(+) diff --git a/ext/pgsql/pgsql.c b/ext/pgsql/pgsql.c index 32fe5132ae..1c39701282 100644 --- a/ext/pgsql/pgsql.c +++ b/ext/pgsql/pgsql.c @@ -97,6 +97,7 @@ function_entry pgsql_functions[] = { PHP_FE(pg_fetch_row, NULL) PHP_FE(pg_fetch_array, NULL) PHP_FE(pg_fetch_object, NULL) + PHP_FE(pg_fetch_all, NULL) PHP_FE(pg_affected_rows,NULL) PHP_FE(pg_get_result, NULL) PHP_FE(pg_result_status,NULL) @@ -1356,6 +1357,30 @@ PHP_FUNCTION(pg_fetch_object) } /* }}} */ +/* {{{ proto array pg_fetch_all(resource result) + Fetch all rows into array */ +PHP_FUNCTION(pg_fetch_all) +{ + zval *result; + PGresult *pgsql_result; + pgsql_result_handle *pg_result; + + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", + &result) == FAILURE) { + return; + } + + ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result); + + pgsql_result = pg_result->result; + array_init(return_value); + if (php_pgsql_result2array(pgsql_result, return_value TSRMLS_CC) == FAILURE) { + zval_dtor(return_value); + RETURN_FALSE; + } +} +/* }}} */ + #define PHP_PG_DATA_LENGTH 1 #define PHP_PG_DATA_ISNULL 2 diff --git a/ext/pgsql/php_pgsql.h b/ext/pgsql/php_pgsql.h index 4d0bfd749b..a18c7b598d 100644 --- a/ext/pgsql/php_pgsql.h +++ b/ext/pgsql/php_pgsql.h @@ -80,6 +80,7 @@ PHP_FUNCTION(pg_fetch_array); PHP_FUNCTION(pg_fetch_object); PHP_FUNCTION(pg_fetch_result); PHP_FUNCTION(pg_fetch_row); +PHP_FUNCTION(pg_fetch_all); PHP_FUNCTION(pg_affected_rows); PHP_FUNCTION(pg_get_result); PHP_FUNCTION(pg_result_status); @@ -153,6 +154,7 @@ PHPAPI int php_pgsql_insert(PGconn *pg_link, const char *table, zval *values, ul PHPAPI int php_pgsql_update(PGconn *pg_link, const char *table, zval *values, zval *ids, ulong opt , char **sql TSRMLS_DC); PHPAPI int php_pgsql_delete(PGconn *pg_link, const char *table, zval *ids, ulong opt, char **sql TSRMLS_DC); PHPAPI int php_pgsql_select(PGconn *pg_link, const char *table, zval *ids, zval *ret_array, ulong opt, char **sql TSRMLS_DC); +PHPAPI int php_pgsql_result2array(PGresult *pg_result, zval *ret_array TSRMLS_DC); /* internal functions */ static void php_pgsql_do_connect(INTERNAL_FUNCTION_PARAMETERS,int persistent); -- 2.40.0