From 7962f7c919df2c18634d454df0e0f49d6c8d1826 Mon Sep 17 00:00:00 2001 From: Loz Calver Date: Fri, 16 Mar 2018 16:43:07 +0000 Subject: [PATCH] API Update PostgreSQLQuery to use generators --- code/PostgreSQLQuery.php | 22 +++++----------------- 1 file changed, 5 insertions(+), 17 deletions(-) diff --git a/code/PostgreSQLQuery.php b/code/PostgreSQLQuery.php index f010a11..67a6faa 100644 --- a/code/PostgreSQLQuery.php +++ b/code/PostgreSQLQuery.php @@ -2,6 +2,7 @@ namespace SilverStripe\PostgreSQL; +use Iterator; use SilverStripe\ORM\Connect\Query; /** @@ -56,12 +57,11 @@ class PostgreSQLQuery extends Query } } - public function seek($row) + public function getIterator(): Iterator { - // Specifying the zero-th record here will reset the pointer - $result = pg_fetch_array($this->handle, $row, PGSQL_NUM); - - return $this->parseResult($result); + while ($row = pg_fetch_array($this->handle, null, PGSQL_NUM)) { + yield $this->parseResult($row); + } } public function numRecords() @@ -69,18 +69,6 @@ class PostgreSQLQuery extends Query return pg_num_rows($this->handle); } - public function nextRecord() - { - $row = pg_fetch_array($this->handle, null, PGSQL_NUM); - - // Correct non-string types - if ($row) { - return $this->parseResult($row); - } - - return false; - } - /** * @param array $row * @return array