Commit b1a78756 authored by zYne's avatar zYne

--no commit message

--no commit message
parent bf263fe1
......@@ -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;
}
}
......
......@@ -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
......
......@@ -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]);
}
......
......@@ -84,7 +84,7 @@ class Doctrine_Query_From extends Doctrine_Query_Part
$operator = ($last == 'INNER') ? ':' : '.';
}
return $this->query;
return null;
}
}
......@@ -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);
}
}
......@@ -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
*
......
......@@ -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;
}
}
......@@ -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;
}
}
......@@ -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);
}
}
......@@ -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);
}
*/
}
......@@ -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;
}
}
......@@ -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);
}
}
......@@ -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
......
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