diff --git a/library/Icinga/Data/Db/DbQuery.php b/library/Icinga/Data/Db/DbQuery.php index c284f0e86..df90ef13c 100644 --- a/library/Icinga/Data/Db/DbQuery.php +++ b/library/Icinga/Data/Db/DbQuery.php @@ -8,7 +8,7 @@ use Icinga\Data\Filter\FilterChain; use Icinga\Data\Filter\FilterOr; use Icinga\Data\Filter\FilterAnd; use Icinga\Data\Filter\FilterNot; -use Icinga\Exception\IcingaException; +use Icinga\Exception\QueryException; use Zend_Db_Select; /** @@ -66,6 +66,7 @@ class DbQuery extends SimpleQuery protected function init() { $this->db = $this->ds->getDbAdapter(); + $this->select = $this->db->select(); parent::init(); } @@ -75,6 +76,13 @@ class DbQuery extends SimpleQuery return $this; } + public function from($target, array $fields = null) + { + parent::from($target, $fields); + $this->select->from($this->target, array()); + return $this; + } + public function where($condition, $value = null) { // $this->count = $this->select = null; @@ -83,9 +91,6 @@ class DbQuery extends SimpleQuery protected function dbSelect() { - if ($this->select === null) { - $this->select = $this->db->select()->from($this->target, array()); - } return clone $this->select; } @@ -151,7 +156,7 @@ class DbQuery extends SimpleQuery $op = ' AND '; $str .= ' NOT '; } else { - throw new IcingaException( + throw new QueryException( 'Cannot render filter: %s', $filter ); @@ -212,7 +217,7 @@ class DbQuery extends SimpleQuery if (! $value) { /* NOTE: It's too late to throw exceptions, we might finish in __toString - throw new IcingaException(sprintf( + throw new QueryException(sprintf( '"%s" is not a valid time expression', $value )); @@ -318,9 +323,7 @@ class DbQuery extends SimpleQuery public function __clone() { - if ($this->select) { - $this->select = clone $this->select; - } + $this->select = clone $this->select; } /** diff --git a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php index 9371399bc..0b436d7bf 100644 --- a/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php +++ b/modules/monitoring/library/Monitoring/Backend/Ido/Query/IdoQuery.php @@ -415,21 +415,11 @@ abstract class IdoQuery extends DbQuery } elseif ($dbType === 'pgsql') { $this->initializeForPostgres(); } - $this->dbSelect(); + $this->joinBaseTables(); $this->select->columns($this->columns); - //$this->joinBaseTables(); $this->prepareAliasIndexes(); } - protected function dbSelect() - { - if ($this->select === null) { - $this->select = $this->db->select(); - $this->joinBaseTables(); - } - return clone $this->select; - } - /** * Join the base tables for this query */