DQL-to-SQL lazy conversion
This commit is contained in:
parent
4346c9f818
commit
a770f83d45
@ -71,7 +71,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
*/
|
||||
protected $_dqlParts = array(
|
||||
'select' => array(),
|
||||
'distinct' => false,
|
||||
'forUpdate' => false,
|
||||
'from' => array(),
|
||||
'set' => array(),
|
||||
@ -99,6 +98,17 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
{
|
||||
return new Doctrine_Query($conn);
|
||||
}
|
||||
public function reset()
|
||||
{
|
||||
$this->_enumParams = array();
|
||||
$this->_pendingJoinConditions = array();
|
||||
$this->pendingSubqueries = array();
|
||||
$this->pendingFields = array();
|
||||
$this->_neededTables = array();
|
||||
$this->subqueryAliases = array();
|
||||
$this->needsSubquery = false;
|
||||
$this->isLimitSubqueryUsed = false;
|
||||
}
|
||||
/**
|
||||
* setOption
|
||||
*
|
||||
@ -266,20 +276,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
$this->_dqlParts[$queryPartName] = array($queryPart);
|
||||
}
|
||||
|
||||
// check for cache
|
||||
if ( ! $this->_options['resultSetCache']) {
|
||||
$parser = $this->getParser($queryPartName);
|
||||
|
||||
$sql = $parser->parse($queryPart);
|
||||
|
||||
if (isset($sql)) {
|
||||
if ($append) {
|
||||
$this->addQueryPart($queryPartName, $sql);
|
||||
} else {
|
||||
$this->setQueryPart($queryPartName, $sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
}
|
||||
@ -639,16 +635,36 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
public function getQuery($params = array())
|
||||
{
|
||||
// check if parser cache is on
|
||||
if ($this->_cache) {
|
||||
|
||||
$this->_aliasMap = array();
|
||||
$this->pendingAggregates = array();
|
||||
$this->aggregateMap = array();
|
||||
|
||||
$this->reset();
|
||||
|
||||
foreach ($this->_dqlParts as $queryPartName => $queryParts) {
|
||||
$this->parts[$queryPartName] = array();
|
||||
if (is_array($queryParts) && ! empty($queryParts)) {
|
||||
|
||||
foreach ($queryParts as $queryPart) {
|
||||
$this->getParser($queryPartName)->parse($queryPart);
|
||||
$parser = $this->getParser($queryPartName);
|
||||
|
||||
|
||||
$sql = $parser->parse($queryPart);
|
||||
|
||||
if (isset($sql)) {
|
||||
if ($queryPartName == 'limit' ||
|
||||
$queryPartName == 'offset') {
|
||||
|
||||
$this->setQueryPart($queryPartName, $sql);
|
||||
} else {
|
||||
$this->addQueryPart($queryPartName, $sql);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($this->parts['from'])) {
|
||||
return false;
|
||||
}
|
||||
@ -687,7 +703,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
|
||||
|
||||
$modifyLimit = true;
|
||||
if ( ! empty($this->parts["limit"]) || ! empty($this->parts["offset"])) {
|
||||
if ( ! empty($this->parts['limit']) || ! empty($this->parts['offset'])) {
|
||||
|
||||
if ($needsSubQuery) {
|
||||
$subquery = $this->getLimitSubquery();
|
||||
@ -922,8 +938,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
break;
|
||||
case 'update':
|
||||
$this->type = self::UPDATE;
|
||||
$k = 'FROM';
|
||||
|
||||
$k = 'from';
|
||||
case 'from':
|
||||
$this->parseQueryPart($k, $part);
|
||||
break;
|
||||
@ -1155,6 +1170,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
*/
|
||||
public function count($params = array())
|
||||
{
|
||||
$this->getQuery();
|
||||
|
||||
// initialize temporary variables
|
||||
$where = $this->parts['where'];
|
||||
$having = $this->parts['having'];
|
||||
@ -1162,6 +1179,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
|
||||
$componentAlias = key($this->_aliasMap);
|
||||
$table = $map['table'];
|
||||
|
||||
|
||||
// build the query base
|
||||
$q = 'SELECT COUNT(DISTINCT ' . $this->getTableAlias($componentAlias)
|
||||
. '.' . $table->getIdentifier()
|
||||
|
Loading…
Reference in New Issue
Block a user