ENHANCEMENT: Don't unncessarily call seek() on Query; this helps use make use of forward-only recordsets.

git-svn-id: svn://svn.silverstripe.com/silverstripe/open/modules/sapphire/trunk@78045 467b73ca-7a2a-4603-9d3b-597d59a354a9
This commit is contained in:
Sam Minnee 2009-05-28 02:06:12 +00:00
parent 7323a652bd
commit a338a8d6a9

View File

@ -695,6 +695,11 @@ abstract class Query extends Object implements Iterator {
* @var int
*/
private $rowNum = -1;
/**
* Flag to keep track of whether iteration has begun, to prevent unnecessary seeks
*/
private $queryHasBegun = false;
/**
* Return an array containing all values in the leftmost column.
@ -789,7 +794,8 @@ abstract class Query extends Object implements Iterator {
* @return array
*/
public function rewind() {
if($this->numRecords() > 0) {
if($this->queryHasBegun && $this->numRecords() > 0) {
$this->queryHasBegun = false;
return $this->seek(0);
}
}
@ -829,6 +835,7 @@ abstract class Query extends Object implements Iterator {
* @return array
*/
public function next() {
$this->queryHasBegun = true;
$this->currentRecord = $this->nextRecord();
$this->rowNum++;
return $this->currentRecord;