DbQuery: Let the DbConnection do the count query

This commit is contained in:
Johannes Meyer 2015-05-19 09:34:22 +02:00
parent 9af25acf38
commit 7b6ca0826b
2 changed files with 13 additions and 1 deletions

View File

@ -212,6 +212,18 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible
return $this; return $this;
} }
/**
* Count all rows of the result set
*
* @param DbQuery $query
*
* @return int
*/
public function count(DbQuery $query)
{
return $this->dbAdapter->fetchOne($query->getCountQuery());
}
/** /**
* Retrieve an array containing all rows of the result set * Retrieve an array containing all rows of the result set
* *

View File

@ -297,7 +297,7 @@ class DbQuery extends SimpleQuery
{ {
if ($this->count === null) { if ($this->count === null) {
Benchmark::measure('DB is counting'); Benchmark::measure('DB is counting');
$this->count = $this->db->fetchOne($this->getCountQuery()); $this->count = parent::count();
Benchmark::measure('DB finished count'); Benchmark::measure('DB finished count');
} }
return $this->count; return $this->count;