Skip to content

Commit

Permalink
Fixed ResultSet when using unbuffered results
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzo committed Jan 9, 2015
1 parent 23943c1 commit 74e90e1
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/ORM/ResultSet.php
Expand Up @@ -143,10 +143,10 @@ public function __construct($query, $statement)
$this->_hydrate = $this->_query->hydrate();
$this->_entityClass = $repository->entityClass();
$this->_useBuffering = $query->bufferResults();
$this->count();

if ($this->_useBuffering) {
$this->_results = new SplFixedArray($this->_count);
$count = $this->count();
$this->_results = new SplFixedArray($count);
}
}

Expand Down Expand Up @@ -217,22 +217,26 @@ public function rewind()
*/
public function valid()
{
if ($this->_index >= $this->_count) {
$valid = true;
if ($this->_useBuffering) {
$valid = $this->_index < $this->_count;
if ($valid && $this->_results[$this->_index] !== null) {
$this->_current = $this->_results[$this->_index];
return true;
}
}

if (!$valid) {
if ($this->_statement !== null) {
$this->_statement->closeCursor();
}
return false;
}

if ($this->_useBuffering && $this->_results[$this->_index] !== null) {
$this->_current = $this->_results[$this->_index];
return true;
}

$this->_current = $this->_fetchResult();
$valid = $this->_current !== false;

if ($this->_useBuffering) {
if ($valid && $this->_useBuffering) {
$this->_results[$this->_index] = $this->_current;
}

Expand Down

0 comments on commit 74e90e1

Please sign in to comment.