Commit 52017850 authored by zYne's avatar zYne

--no commit message

--no commit message
parent 58a5ca0c
...@@ -82,7 +82,7 @@ class Doctrine_Hydrate ...@@ -82,7 +82,7 @@ class Doctrine_Hydrate
* *
* parent the alias of the parent * parent the alias of the parent
* *
* subAgg the subquery aggregates of this component * agg the aggregates of this component
*/ */
protected $_aliasMap = array(); protected $_aliasMap = array();
/** /**
...@@ -118,7 +118,7 @@ class Doctrine_Hydrate ...@@ -118,7 +118,7 @@ class Doctrine_Hydrate
*/ */
protected $type = self::SELECT; protected $type = self::SELECT;
protected $_tableAliases = array(); protected $_tableAliases = array();
/** /**
* @var array $_tableAliasSeeds A simple array keys representing table aliases and values * @var array $_tableAliasSeeds A simple array keys representing table aliases and values
* as table alias seeds. The seeds are used for generating short table * as table alias seeds. The seeds are used for generating short table
...@@ -529,14 +529,12 @@ class Doctrine_Hydrate ...@@ -529,14 +529,12 @@ class Doctrine_Hydrate
$found = false; $found = false;
// aggregate values have numeric keys // aggregate values have numeric keys
if (isset($row[0])) { if (isset($row[0])) {
// map each aggregate value // map each aggregate value
foreach ($row as $index => $value) { foreach ($row as $index => $value) {
$agg = false; $agg = false;
if (isset($this->pendingAggregates[$alias][$index])) { if (isset($this->_aliasMap[$alias]['agg'][$index])) {
$agg = $this->pendingAggregates[$alias][$index][3]; $agg = $this->_aliasMap[$alias]['agg'][$index];
} elseif (isset($this->_aliasMap[$alias]['subAgg'][$index])) {
$agg = $this->_aliasMap[$alias]['subAgg'][$index];
} }
$record->mapValue($agg, $value); $record->mapValue($agg, $value);
$found = true; $found = true;
......
...@@ -37,8 +37,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -37,8 +37,6 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
* @param boolean $needsSubquery * @param boolean $needsSubquery
*/ */
protected $needsSubquery = false; protected $needsSubquery = false;
protected $_status = array('needsSubquery' => true);
/** /**
* @param boolean $isSubquery whether or not this query object is a subquery of another * @param boolean $isSubquery whether or not this query object is a subquery of another
* query object * query object
...@@ -46,8 +44,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -46,8 +44,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
protected $isSubquery; protected $isSubquery;
protected $isLimitSubqueryUsed = false; protected $isLimitSubqueryUsed = false;
/**
protected $neededTables = array(); * @var array $_neededTableAliases an array containing the needed table aliases
*/
protected $_neededTables = array();
/** /**
* @var array $pendingFields * @var array $pendingFields
*/ */
...@@ -58,7 +58,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -58,7 +58,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
*/ */
protected $pendingSubqueries = array(); protected $pendingSubqueries = array();
/** /**
* @var array $_parsers an array of parser objects * @var array $_parsers an array of parser objects, each DQL query part has its own parser
*/ */
protected $_parsers = array(); protected $_parsers = array();
/** /**
...@@ -191,10 +191,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -191,10 +191,10 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this->isSubquery = (bool) $bool; $this->isSubquery = (bool) $bool;
return $this; return $this;
} }
/** /**
* getAggregateAlias * getAggregateAlias
* *
* @param string $dqlAlias the dql alias of an aggregate value
* @return string * @return string
*/ */
public function getAggregateAlias($dqlAlias) public function getAggregateAlias($dqlAlias)
...@@ -241,16 +241,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -241,16 +241,20 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
*/ */
public function parseQueryPart($queryPartName, $queryPart, $append = false) public function parseQueryPart($queryPartName, $queryPart, $append = false)
{ {
// sanity check
if ($queryPart === '' || $queryPart === null) { if ($queryPart === '' || $queryPart === null) {
throw new Doctrine_Query_Exception('Empty ' . $queryPartName . ' part given.'); throw new Doctrine_Query_Exception('Empty ' . $queryPartName . ' part given.');
} }
// add query part to the dql part array
if ($append) { if ($append) {
$this->_dqlParts[$queryPartName][] = $queryPart; $this->_dqlParts[$queryPartName][] = $queryPart;
} else { } else {
$this->_dqlParts[$queryPartName] = array($queryPart); $this->_dqlParts[$queryPartName] = array($queryPart);
} }
if ( ! $this->_options['resultSetCache'] && ! $this->_options['parserCache']) {
// check for cache
if ( ! $this->_options['resultSetCache'] && ! $this->_options['parserCache']) {
$parser = $this->getParser($queryPartName); $parser = $this->getParser($queryPartName);
$sql = $parser->parse($queryPart); $sql = $parser->parse($queryPart);
...@@ -343,7 +347,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -343,7 +347,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
// subselect found in SELECT part // subselect found in SELECT part
$this->parseSubselect($reference); $this->parseSubselect($reference);
} else { } else {
$this->parseAggregateFunction2($reference); $this->parseAggregateFunction($reference);
} }
} else { } else {
...@@ -381,7 +385,16 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -381,7 +385,16 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this->pendingSubqueries[] = array($subquery, $alias); $this->pendingSubqueries[] = array($subquery, $alias);
} }
public function parseAggregateFunction2($func) /**
* parseAggregateFunction
* parses an aggregate function and returns the parsed form
*
* @see Doctrine_Expression
* @param string $func DQL aggregate function
* @throws Doctrine_Query_Exception if unknown aggregate function given
* @return array parsed form of given function
*/
public function parseAggregateFunction($func)
{ {
$e = Doctrine_Tokenizer::bracketExplode($func, ' '); $e = Doctrine_Tokenizer::bracketExplode($func, ' ');
$func = $e[0]; $func = $e[0];
...@@ -436,6 +449,15 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -436,6 +449,15 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
throw new Doctrine_Query_Exception('Unknown function ' . $func . '.'); throw new Doctrine_Query_Exception('Unknown function ' . $func . '.');
} }
} }
/**
* processPendingSubqueries
* processes pending subqueries
*
* subqueries can only be processed when the query is fully constructed
* since some subqueries may be correlated
*
* @return void
*/
public function processPendingSubqueries() public function processPendingSubqueries()
{ {
foreach ($this->pendingSubqueries as $value) { foreach ($this->pendingSubqueries as $value) {
...@@ -452,10 +474,17 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -452,10 +474,17 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this->parts['select'][] = '(' . $sql . ') AS ' . $sqlAlias; $this->parts['select'][] = '(' . $sql . ') AS ' . $sqlAlias;
$this->aggregateMap[$alias] = $sqlAlias; $this->aggregateMap[$alias] = $sqlAlias;
$this->_aliasMap[$componentAlias]['subAgg'][] = $alias; $this->_aliasMap[$componentAlias]['agg'][] = $alias;
} }
$this->pendingSubqueries = array(); $this->pendingSubqueries = array();
} }
/**
* processPendingAggregates
* processes pending aggregate values for given component alias
*
* @param string $componentAlias dql component alias
* @return void
*/
public function processPendingAggregates($componentAlias) public function processPendingAggregates($componentAlias)
{ {
$tableAlias = $this->getTableAlias($componentAlias); $tableAlias = $this->getTableAlias($componentAlias);
...@@ -501,8 +530,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -501,8 +530,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$arglist[] = $e[0]; $arglist[] = $e[0];
} }
} }
$index = count($this->aggregateMap);
$sqlAlias = $tableAlias . '__' . count($this->aggregateMap); $sqlAlias = $tableAlias . '__' . $index;
if (substr($name, 0, 1) !== '(') { if (substr($name, 0, 1) !== '(') {
$this->parts['select'][] = $name . '(' . $distinct . implode(', ', $arglist) . ') AS ' . $sqlAlias; $this->parts['select'][] = $name . '(' . $distinct . implode(', ', $arglist) . ') AS ' . $sqlAlias;
...@@ -510,6 +539,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -510,6 +539,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
$this->parts['select'][] = $name . ' AS ' . $sqlAlias; $this->parts['select'][] = $name . ' AS ' . $sqlAlias;
} }
$this->aggregateMap[$alias] = $sqlAlias; $this->aggregateMap[$alias] = $sqlAlias;
$this->_aliasMap[$componentAlias]['agg'][$index] = $alias;
$this->neededTables[] = $tableAlias; $this->neededTables[] = $tableAlias;
} }
} }
...@@ -539,8 +570,9 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -539,8 +570,9 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
} }
/** /**
* buildFromPart * buildFromPart
* builds the from part of the query and returns it
* *
* @return string * @return string the query sql from part
*/ */
public function buildFromPart() public function buildFromPart()
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment