DbQuery: Initialize self::$select as early as possible

I'd like to use Zend's implementation instead of re-inventing the wheel just
because someone decided to only work with a copy of it in the frameworks
query but do exactly the opposite in the monitoring module's IDO query...
This commit is contained in:
Johannes Meyer 2015-05-28 13:49:36 +02:00
parent 5326ce6bca
commit 58d78f59f3
2 changed files with 13 additions and 20 deletions

View File

@ -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;
}
/**

View File

@ -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
*/