Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API Rescue Master Branch PR: Update PostgreSQLQuery to use generators #135

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 5 additions & 17 deletions code/PostgreSQLQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace SilverStripe\PostgreSQL;

use Iterator;
use SilverStripe\ORM\Connect\Query;

/**
Expand Down Expand Up @@ -56,31 +57,18 @@ public function __destruct()
}
}

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()
{
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
Expand Down