diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 7f235c2d0..2858dcf0f 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -241,13 +241,27 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable */ public function parseQueryPart($queryPartName, $queryPart, $append = false) { + if ($queryPart === '' || $queryPart === null) { + throw new Doctrine_Query_Exception('Empty ' . $queryPartName . ' part given.'); + } + if ($append) { $this->_dqlParts[$queryPartName][] = $queryPart; } else { $this->_dqlParts[$queryPartName] = array($queryPart); } if ( ! $this->_options['resultSetCache'] && ! $this->_options['parserCache']) { - $this->getParser($queryPartName)->parse($queryPart); + $parser = $this->getParser($queryPartName); + + $sql = $parser->parse($queryPart); + + if (isset($sql)) { + if ($append) { + $this->addQueryPart($queryPartName, $sql); + } else { + $this->setQueryPart($queryPartName, $sql); + } + } } return $this; @@ -562,7 +576,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable if ( ! empty($e2)) { $parser = new Doctrine_Query_JoinCondition($this); - $part .= ' AND ' . $parser->_parse(implode(' AND ', $e2)); + $part .= ' AND ' . $parser->parse(implode(' AND ', $e2)); } $q .= ' ' . $part; @@ -856,7 +870,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable foreach($parts as $k => $part) { $part = implode(' ', $part); - switch(strtolower($k)) { + $k = strtolower($k); + switch ($k) { case 'create': $this->type = self::CREATE; break; @@ -868,38 +883,26 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable break; case 'select': $this->type = self::SELECT; - $this->parseSelect($part); + $this->parseQueryPart($k, $part); break; case 'update': $this->type = self::UPDATE; $k = 'FROM'; case 'from': - $class = 'Doctrine_Query_' . ucwords(strtolower($k)); - $parser = new $class($this); - $parser->parse($part); + $this->parseQueryPart($k, $part); break; case 'set': - $class = 'Doctrine_Query_' . ucwords(strtolower($k)); - $parser = new $class($this); - $parser->parse($part); + $this->parseQueryPart($k, $part, true); break; case 'group': case 'order': $k .= 'by'; case 'where': case 'having': - $class = 'Doctrine_Query_' . ucwords(strtolower($k)); - $parser = new $class($this); - - $name = strtolower($k); - $parser->parse($part); - break; case 'limit': - $this->parts['limit'] = trim($part); - break; case 'offset': - $this->parts['offset'] = trim($part); + $this->parseQueryPart($k, $part); break; } } diff --git a/lib/Doctrine/Query/Abstract.php b/lib/Doctrine/Query/Abstract.php index 87806d90a..2dbeeef00 100644 --- a/lib/Doctrine/Query/Abstract.php +++ b/lib/Doctrine/Query/Abstract.php @@ -171,7 +171,7 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate */ public function set($key, $value) { - return $this->parseQueryPart('set', $key . ' = ' . $value); + return $this->parseQueryPart('set', $key . ' = ' . $value, true); } /** * from diff --git a/lib/Doctrine/Query/Condition.php b/lib/Doctrine/Query/Condition.php index 3ba0c0870..8895aad42 100644 --- a/lib/Doctrine/Query/Condition.php +++ b/lib/Doctrine/Query/Condition.php @@ -39,7 +39,7 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part * @param string $str * @return string */ - public function _parse($str) + public function parse($str) { $tmp = trim($str); @@ -49,7 +49,7 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part $ret = array(); foreach ($parts as $part) { $part = Doctrine_Tokenizer::bracketTrim($part, '(', ')'); - $ret[] = $this->_parse($part); + $ret[] = $this->parse($part); } $r = implode(' AND ', $ret); } else { @@ -59,12 +59,12 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part $ret = array(); foreach ($parts as $part) { $part = Doctrine_Tokenizer::bracketTrim($part, '(', ')'); - $ret[] = $this->_parse($part); + $ret[] = $this->parse($part); } $r = implode(' OR ', $ret); } else { if (substr($parts[0],0,1) == '(' && substr($parts[0], -1) == ')') { - return $this->_parse(substr($parts[0], 1, -1)); + return $this->parse(substr($parts[0], 1, -1)); } else { return $this->load($parts[0]); } diff --git a/lib/Doctrine/Query/From.php b/lib/Doctrine/Query/From.php index 41dcd0b37..120173f0c 100644 --- a/lib/Doctrine/Query/From.php +++ b/lib/Doctrine/Query/From.php @@ -84,7 +84,7 @@ class Doctrine_Query_From extends Doctrine_Query_Part $operator = ($last == 'INNER') ? ':' : '.'; } - return $this->query; + return null; } } diff --git a/lib/Doctrine/Query/Groupby.php b/lib/Doctrine/Query/Groupby.php index 3fe7c5d1c..59117d4b1 100644 --- a/lib/Doctrine/Query/Groupby.php +++ b/lib/Doctrine/Query/Groupby.php @@ -51,11 +51,6 @@ class Doctrine_Query_Groupby extends Doctrine_Query_Part $r[] = $this->query->getTableAlias($ref) . '.' . $field; } - if ($append) { - $this->query->addQueryPart('groupby', implode(', ', $r)); - } else { - $this->query->setQueryPart('groupby', implode(', ', $r)); - } - return $this->query; + return implode(', ', $r); } } diff --git a/lib/Doctrine/Query/Having.php b/lib/Doctrine/Query/Having.php index e9fe27571..edd92ebed 100644 --- a/lib/Doctrine/Query/Having.php +++ b/lib/Doctrine/Query/Having.php @@ -32,15 +32,6 @@ Doctrine::autoload('Doctrine_Query_Condition'); */ class Doctrine_Query_Having extends Doctrine_Query_Condition { - public function parse($str, $append = false) - { - if ($append) { - $this->query->addQueryPart('having', $this->_parse($str)); - } else { - $this->query->setQueryPart('having', $this->_parse($str)); - } - return $this->query; - } /** * DQL Aggregate Function parser * diff --git a/lib/Doctrine/Query/Limit.php b/lib/Doctrine/Query/Limit.php index 369084699..195ecaa0e 100644 --- a/lib/Doctrine/Query/Limit.php +++ b/lib/Doctrine/Query/Limit.php @@ -34,8 +34,6 @@ class Doctrine_Query_Limit extends Doctrine_Query_Part { public function parse($limit) { - $this->query->setQueryPart('limit', (int) $limit); - - return $this->query; + return (int) $limit; } } diff --git a/lib/Doctrine/Query/Offset.php b/lib/Doctrine/Query/Offset.php index fecee7e17..16de40e9b 100644 --- a/lib/Doctrine/Query/Offset.php +++ b/lib/Doctrine/Query/Offset.php @@ -34,8 +34,6 @@ class Doctrine_Query_Offset extends Doctrine_Query_Part { public function parse($offset) { - $this->query->setQueryPart('offset', (int) $offset); - - return $this->query; + return (int) $offset; } } diff --git a/lib/Doctrine/Query/Orderby.php b/lib/Doctrine/Query/Orderby.php index 686405b06..5e6566541 100644 --- a/lib/Doctrine/Query/Orderby.php +++ b/lib/Doctrine/Query/Orderby.php @@ -69,12 +69,6 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part } $ret[] = $r; } - - if ($append) { - $this->query->addQueryPart('orderby', implode(', ', $ret)); - } else { - $this->query->setQueryPart('orderby', implode(', ', $ret)); - } - return $this->query; + return implode(', ', $ret); } } diff --git a/lib/Doctrine/Query/Part.php b/lib/Doctrine/Query/Part.php index 711e8a50b..0afa8eb18 100644 --- a/lib/Doctrine/Query/Part.php +++ b/lib/Doctrine/Query/Part.php @@ -50,14 +50,4 @@ abstract class Doctrine_Query_Part { return $this->query; } - /** - public function parse($dql, $append = false) - { - $e = explode(' ', __CLASS__); - $name = end($e); - - $this->query->addDqlPart($name, $dql); - $this->_parse($dql); - } - */ } diff --git a/lib/Doctrine/Query/Select.php b/lib/Doctrine/Query/Select.php index 93a76fd83..deec3c858 100644 --- a/lib/Doctrine/Query/Select.php +++ b/lib/Doctrine/Query/Select.php @@ -34,11 +34,8 @@ class Doctrine_Query_Select extends Doctrine_Query_Part { public function parse($dql) { - if ($dql === '' || $dql === null) { - throw new Doctrine_Query_Exception('Empty select part given.'); - } $this->query->parseSelect($dql); - return $this->query; + return null; } } diff --git a/lib/Doctrine/Query/Set.php b/lib/Doctrine/Query/Set.php index 24e60893d..5b981c226 100644 --- a/lib/Doctrine/Query/Set.php +++ b/lib/Doctrine/Query/Set.php @@ -45,15 +45,13 @@ class Doctrine_Query_Set extends Doctrine_Query_Part $reference = implode('.', $e); - $alias = $this->query->getTableAlias($reference); + $alias = $this->query->getTableAlias($reference); $map = $this->query->getAliasDeclaration($reference); $result[] = $map['table']->getColumnName($field) . ' = ' . $set[1]; } - - $this->query->addQueryPart('set', implode(', ', $result)); - return $this->query; + return implode(', ', $result); } } diff --git a/lib/Doctrine/Query/Where.php b/lib/Doctrine/Query/Where.php index f8e32c5ea..6874269a8 100644 --- a/lib/Doctrine/Query/Where.php +++ b/lib/Doctrine/Query/Where.php @@ -32,15 +32,6 @@ Doctrine::autoload('Doctrine_Query_Condition'); */ class Doctrine_Query_Where extends Doctrine_Query_Condition { - public function parse($str, $append = false) - { - if ($append) { - $this->query->addQueryPart('where', $this->_parse($str)); - } else { - $this->query->setQueryPart('where', $this->_parse($str)); - } - return $this->query; - } /** * load * returns the parsed query part