]> granicus.if.org Git - php/commitdiff
Added pg_data_seek().
authorYasuo Ohgaki <yohgaki@php.net>
Wed, 2 Oct 2002 03:16:35 +0000 (03:16 +0000)
committerYasuo Ohgaki <yohgaki@php.net>
Wed, 2 Oct 2002 03:16:35 +0000 (03:16 +0000)
pg_result_seek() woudl be better name, but there is mysql_data_seek()...

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

index 0e7cd398ef724f2b30719009ff08c488775319a2..d24876594af7e59a14bdf04fe74016cdef54da19 100644 (file)
@@ -100,6 +100,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_data_seek,    NULL)
        PHP_FE(pg_affected_rows,NULL)
        PHP_FE(pg_get_result,   NULL)
        PHP_FE(pg_result_status,NULL)
@@ -1416,6 +1417,37 @@ PHP_FUNCTION(pg_fetch_all)
 }
 /* }}} */
 
+/* {{{ proto mixed pg_data_seek(resource result, int offset)
+   Set internal row offset */
+PHP_FUNCTION(pg_data_seek)
+{
+       zval *result;
+       int row;
+       PGresult *pgsql_result;
+       pgsql_result_handle *pg_result;
+
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r|l",
+                                                         &result, &row) == FAILURE) {
+               return;
+       }
+
+       ZEND_FETCH_RESOURCE(pg_result, pgsql_result_handle *, &result, -1, "PostgreSQL result", le_result);
+
+       /* Let see if we are better to have another function for this */
+       /* if offset is omitted, return current position */
+/*     if (ZEND_NUM_ARGS() == 1) */
+/*             RETURN_LONG(pg_result->row); */
+
+       if (row < 0 || row >= PQntuples(pg_result))
+               RETURN_FALSE;
+       
+       /* seek to offset */
+       pg_result->row = row;
+       RETURN_TRUE;
+}
+/* }}} */
+
+
 #define PHP_PG_DATA_LENGTH 1
 #define PHP_PG_DATA_ISNULL 2
 
index 11187ece5d05d4be87a9475972b7d500ec9dfdba..4b00fc3eed19d8f4f6f7257ece1ba83e1a0afeb8 100644 (file)
@@ -83,6 +83,7 @@ PHP_FUNCTION(pg_fetch_object);
 PHP_FUNCTION(pg_fetch_result);
 PHP_FUNCTION(pg_fetch_row);
 PHP_FUNCTION(pg_fetch_all);
+PHP_FUNCTION(pg_data_seek);
 PHP_FUNCTION(pg_affected_rows);
 PHP_FUNCTION(pg_get_result);
 PHP_FUNCTION(pg_result_status);