Skip to content

Commit 74e90e1

Browse files
committed
Fixed ResultSet when using unbuffered results
1 parent 23943c1 commit 74e90e1

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

src/ORM/ResultSet.php

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -143,10 +143,10 @@ public function __construct($query, $statement)
143143
$this->_hydrate = $this->_query->hydrate();
144144
$this->_entityClass = $repository->entityClass();
145145
$this->_useBuffering = $query->bufferResults();
146-
$this->count();
147146

148147
if ($this->_useBuffering) {
149-
$this->_results = new SplFixedArray($this->_count);
148+
$count = $this->count();
149+
$this->_results = new SplFixedArray($count);
150150
}
151151
}
152152

@@ -217,22 +217,26 @@ public function rewind()
217217
*/
218218
public function valid()
219219
{
220-
if ($this->_index >= $this->_count) {
220+
$valid = true;
221+
if ($this->_useBuffering) {
222+
$valid = $this->_index < $this->_count;
223+
if ($valid && $this->_results[$this->_index] !== null) {
224+
$this->_current = $this->_results[$this->_index];
225+
return true;
226+
}
227+
}
228+
229+
if (!$valid) {
221230
if ($this->_statement !== null) {
222231
$this->_statement->closeCursor();
223232
}
224233
return false;
225234
}
226235

227-
if ($this->_useBuffering && $this->_results[$this->_index] !== null) {
228-
$this->_current = $this->_results[$this->_index];
229-
return true;
230-
}
231-
232236
$this->_current = $this->_fetchResult();
233237
$valid = $this->_current !== false;
234238

235-
if ($this->_useBuffering) {
239+
if ($valid && $this->_useBuffering) {
236240
$this->_results[$this->_index] = $this->_current;
237241
}
238242

0 commit comments

Comments
 (0)