]> granicus.if.org Git - php/commitdiff
Added pg_fetch_all_columns() function to fetch all values of a column from
authorIlia Alshanetsky <iliaa@php.net>
Fri, 8 Jul 2005 00:40:32 +0000 (00:40 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Fri, 8 Jul 2005 00:40:32 +0000 (00:40 +0000)
a result cursor.

NEWS
ext/pgsql/pgsql.c
ext/pgsql/php_pgsql.h

diff --git a/NEWS b/NEWS
index ebc98169544b48b3a6f5b79084f828f3d6bacc47..787fda0e08d897fdc6244c21f0deda0a384376c6 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -5,6 +5,8 @@ PHP                                                                        NEWS
 - Added PDO_MYSQL_ATTR_USE_BUFFERED_QUERY parameter for pdo_mysql. (Ilia)
 - Added date_timezone_set() function to set the timezone that the date
   functions will use. (Derick)
+- Added pg_fetch_all_columns() function to fetch all values of a column from
+  a result cursor. (Ilia)
 - Implemented feature request #33452 (Year belonging to ISO week). (Derick)
 - Fixed support for shared extensions on AIX. (Dmitry)
 - Fixed memory corruption in pg_copy_from() in case the as_null parameter was
index 61cd2175785e4449ed9be17770eab7400f0daf70..19e58f67c56399563b7128e024ce8283ef90a7c0 100644 (file)
@@ -127,6 +127,7 @@ function_entry pgsql_functions[] = {
        PHP_FE(pg_fetch_array,  NULL)
        PHP_FE(pg_fetch_object, NULL)
        PHP_FE(pg_fetch_all,    NULL)
+       PHP_FE(pg_fetch_all_columns,    NULL)
 #if HAVE_PQCMDTUPLES
        PHP_FE(pg_affected_rows,NULL)
 #endif
@@ -2101,6 +2102,47 @@ PHP_FUNCTION(pg_fetch_all)
 }
 /* }}} */
 
+/* {{{ proto array pg_fetch_all_columns(resource result [, int column_number])
+   Fetch all rows into array */
+PHP_FUNCTION(pg_fetch_all_columns)
+{
+       zval *result;
+       PGresult *pgsql_result;
+       pgsql_result_handle *pg_result;
+       long colno=0;
+       int pg_numrows, pg_row;
+       size_t num_fields;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l", &result, &colno) == FAILURE) {
+               RETURN_FALSE;
+       }
+
+       ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result);
+
+       pgsql_result = pg_result->result;
+
+       num_fields = PQnfields(pgsql_result);
+       if (colno >= num_fields || colno < 0) {
+               php_error_docref(NULL TSRMLS_CC, E_WARNING, "Invalid column number '%ld'", colno);
+               RETURN_FALSE;
+       }
+
+       array_init(return_value);
+
+        if ((pg_numrows = PQntuples(pgsql_result)) <= 0) {
+               return;
+       }
+
+       for (pg_row = 0; pg_row < pg_numrows; pg_row++) {
+               if (PQgetisnull(pgsql_result, pg_row, colno)) {
+                       add_next_index_null(return_value);
+               } else {
+                       add_next_index_string(return_value, PQgetvalue(pgsql_result, pg_row, colno), 1); 
+               }               
+       }
+}
+/* }}} */
+
 /* {{{ proto bool pg_result_seek(resource result, int offset)
    Set internal row offset */
 PHP_FUNCTION(pg_result_seek)
index 21f9ecde09d55ebfa018e88bb8f368007801342f..78c1cb541d054e52bf4105675c24c323d6c60536 100644 (file)
@@ -107,6 +107,7 @@ PHP_FUNCTION(pg_fetch_object);
 PHP_FUNCTION(pg_fetch_result);
 PHP_FUNCTION(pg_fetch_row);
 PHP_FUNCTION(pg_fetch_all);
+PHP_FUNCTION(pg_fetch_all_columns);
 #if HAVE_PQCMDTUPLES
 PHP_FUNCTION(pg_affected_rows);
 #endif