From 7b6ca0826bf78c69807595db33325c9cfda8c364 Mon Sep 17 00:00:00 2001 From: Johannes Meyer Date: Tue, 19 May 2015 09:34:22 +0200 Subject: [PATCH] DbQuery: Let the DbConnection do the count query --- library/Icinga/Data/Db/DbConnection.php | 12 ++++++++++++ library/Icinga/Data/Db/DbQuery.php | 2 +- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/library/Icinga/Data/Db/DbConnection.php b/library/Icinga/Data/Db/DbConnection.php index f6398831d..9960fd491 100644 --- a/library/Icinga/Data/Db/DbConnection.php +++ b/library/Icinga/Data/Db/DbConnection.php @@ -212,6 +212,18 @@ class DbConnection implements Selectable, Extensible, Updatable, Reducible 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 * diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index 45a586b9a..1149fbeec 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -297,7 +297,7 @@ class DbQuery extends SimpleQuery { if ($this->count === null) { Benchmark::measure('DB is counting'); - $this->count = $this->db->fetchOne($this->getCountQuery()); + $this->count = parent::count(); Benchmark::measure('DB finished count'); } return $this->count;