Skip to content

Commit

Permalink
DbQuery: Initialize self::$select as early as possible
Browse files Browse the repository at this point in the history
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...
  • Loading branch information
Johannes Meyer committed May 28, 2015
1 parent 5326ce6 commit 58d78f5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 20 deletions.
21 changes: 12 additions & 9 deletions library/Icinga/Data/Db/DbQuery.php
Expand Up @@ -8,7 +8,7 @@
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;

/**
Expand Down Expand Up @@ -66,6 +66,7 @@ class DbQuery extends SimpleQuery
protected function init()
{
$this->db = $this->ds->getDbAdapter();
$this->select = $this->db->select();
parent::init();
}

Expand All @@ -75,6 +76,13 @@ public function setUseSubqueryCount($useSubqueryCount = true)
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;
Expand All @@ -83,9 +91,6 @@ public function where($condition, $value = null)

protected function dbSelect()
{
if ($this->select === null) {
$this->select = $this->db->select()->from($this->target, array());
}
return clone $this->select;
}

Expand Down Expand Up @@ -151,7 +156,7 @@ protected function renderFilter($filter, $level = 0)
$op = ' AND ';
$str .= ' NOT ';
} else {
throw new IcingaException(
throw new QueryException(
'Cannot render filter: %s',
$filter
);
Expand Down Expand Up @@ -212,7 +217,7 @@ protected function valueToTimestamp($value)
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
));
Expand Down Expand Up @@ -318,9 +323,7 @@ public function dump()

public function __clone()
{
if ($this->select) {
$this->select = clone $this->select;
}
$this->select = clone $this->select;
}

/**
Expand Down
Expand Up @@ -415,21 +415,11 @@ protected function init()
} 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
*/
Expand Down

0 comments on commit 58d78f5

Please sign in to comment.