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 ...@@ -241,13 +241,27 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
*/ */
public function parseQueryPart($queryPartName, $queryPart, $append = false) public function parseQueryPart($queryPartName, $queryPart, $append = false)
{ {
if ($queryPart === '' || $queryPart === null) {
throw new Doctrine_Query_Exception('Empty ' . $queryPartName . ' part given.');
}
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']) { 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; return $this;
...@@ -562,7 +576,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -562,7 +576,7 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
if ( ! empty($e2)) { if ( ! empty($e2)) {
$parser = new Doctrine_Query_JoinCondition($this); $parser = new Doctrine_Query_JoinCondition($this);
$part .= ' AND ' . $parser->_parse(implode(' AND ', $e2)); $part .= ' AND ' . $parser->parse(implode(' AND ', $e2));
} }
$q .= ' ' . $part; $q .= ' ' . $part;
...@@ -856,7 +870,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -856,7 +870,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
foreach($parts as $k => $part) { foreach($parts as $k => $part) {
$part = implode(' ', $part); $part = implode(' ', $part);
switch(strtolower($k)) { $k = strtolower($k);
switch ($k) {
case 'create': case 'create':
$this->type = self::CREATE; $this->type = self::CREATE;
break; break;
...@@ -868,38 +883,26 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable ...@@ -868,38 +883,26 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable
break; break;
case 'select': case 'select':
$this->type = self::SELECT; $this->type = self::SELECT;
$this->parseSelect($part); $this->parseQueryPart($k, $part);
break; break;
case 'update': case 'update':
$this->type = self::UPDATE; $this->type = self::UPDATE;
$k = 'FROM'; $k = 'FROM';
case 'from': case 'from':
$class = 'Doctrine_Query_' . ucwords(strtolower($k)); $this->parseQueryPart($k, $part);
$parser = new $class($this);
$parser->parse($part);
break; break;
case 'set': case 'set':
$class = 'Doctrine_Query_' . ucwords(strtolower($k)); $this->parseQueryPart($k, $part, true);
$parser = new $class($this);
$parser->parse($part);
break; break;
case 'group': case 'group':
case 'order': case 'order':
$k .= 'by'; $k .= 'by';
case 'where': case 'where':
case 'having': case 'having':
$class = 'Doctrine_Query_' . ucwords(strtolower($k));
$parser = new $class($this);
$name = strtolower($k);
$parser->parse($part);
break;
case 'limit': case 'limit':
$this->parts['limit'] = trim($part);
break;
case 'offset': case 'offset':
$this->parts['offset'] = trim($part); $this->parseQueryPart($k, $part);
break; break;
} }
} }
......
...@@ -171,7 +171,7 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate ...@@ -171,7 +171,7 @@ abstract class Doctrine_Query_Abstract extends Doctrine_Hydrate
*/ */
public function set($key, $value) public function set($key, $value)
{ {
return $this->parseQueryPart('set', $key . ' = ' . $value); return $this->parseQueryPart('set', $key . ' = ' . $value, true);
} }
/** /**
* from * from
......
...@@ -39,7 +39,7 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part ...@@ -39,7 +39,7 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part
* @param string $str * @param string $str
* @return string * @return string
*/ */
public function _parse($str) public function parse($str)
{ {
$tmp = trim($str); $tmp = trim($str);
...@@ -49,7 +49,7 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part ...@@ -49,7 +49,7 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part
$ret = array(); $ret = array();
foreach ($parts as $part) { foreach ($parts as $part) {
$part = Doctrine_Tokenizer::bracketTrim($part, '(', ')'); $part = Doctrine_Tokenizer::bracketTrim($part, '(', ')');
$ret[] = $this->_parse($part); $ret[] = $this->parse($part);
} }
$r = implode(' AND ', $ret); $r = implode(' AND ', $ret);
} else { } else {
...@@ -59,12 +59,12 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part ...@@ -59,12 +59,12 @@ abstract class Doctrine_Query_Condition extends Doctrine_Query_Part
$ret = array(); $ret = array();
foreach ($parts as $part) { foreach ($parts as $part) {
$part = Doctrine_Tokenizer::bracketTrim($part, '(', ')'); $part = Doctrine_Tokenizer::bracketTrim($part, '(', ')');
$ret[] = $this->_parse($part); $ret[] = $this->parse($part);
} }
$r = implode(' OR ', $ret); $r = implode(' OR ', $ret);
} else { } else {
if (substr($parts[0],0,1) == '(' && substr($parts[0], -1) == ')') { 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 { } else {
return $this->load($parts[0]); return $this->load($parts[0]);
} }
......
...@@ -84,7 +84,7 @@ class Doctrine_Query_From extends Doctrine_Query_Part ...@@ -84,7 +84,7 @@ class Doctrine_Query_From extends Doctrine_Query_Part
$operator = ($last == 'INNER') ? ':' : '.'; $operator = ($last == 'INNER') ? ':' : '.';
} }
return $this->query; return null;
} }
} }
...@@ -51,11 +51,6 @@ class Doctrine_Query_Groupby extends Doctrine_Query_Part ...@@ -51,11 +51,6 @@ class Doctrine_Query_Groupby extends Doctrine_Query_Part
$r[] = $this->query->getTableAlias($ref) . '.' . $field; $r[] = $this->query->getTableAlias($ref) . '.' . $field;
} }
if ($append) { return implode(', ', $r);
$this->query->addQueryPart('groupby', implode(', ', $r));
} else {
$this->query->setQueryPart('groupby', implode(', ', $r));
}
return $this->query;
} }
} }
...@@ -32,15 +32,6 @@ Doctrine::autoload('Doctrine_Query_Condition'); ...@@ -32,15 +32,6 @@ Doctrine::autoload('Doctrine_Query_Condition');
*/ */
class Doctrine_Query_Having extends 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 * DQL Aggregate Function parser
* *
......
...@@ -34,8 +34,6 @@ class Doctrine_Query_Limit extends Doctrine_Query_Part ...@@ -34,8 +34,6 @@ class Doctrine_Query_Limit extends Doctrine_Query_Part
{ {
public function parse($limit) public function parse($limit)
{ {
$this->query->setQueryPart('limit', (int) $limit); return (int) $limit;
return $this->query;
} }
} }
...@@ -34,8 +34,6 @@ class Doctrine_Query_Offset extends Doctrine_Query_Part ...@@ -34,8 +34,6 @@ class Doctrine_Query_Offset extends Doctrine_Query_Part
{ {
public function parse($offset) public function parse($offset)
{ {
$this->query->setQueryPart('offset', (int) $offset); return (int) $offset;
return $this->query;
} }
} }
...@@ -69,12 +69,6 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part ...@@ -69,12 +69,6 @@ class Doctrine_Query_Orderby extends Doctrine_Query_Part
} }
$ret[] = $r; $ret[] = $r;
} }
return implode(', ', $ret);
if ($append) {
$this->query->addQueryPart('orderby', implode(', ', $ret));
} else {
$this->query->setQueryPart('orderby', implode(', ', $ret));
}
return $this->query;
} }
} }
...@@ -50,14 +50,4 @@ abstract class Doctrine_Query_Part ...@@ -50,14 +50,4 @@ abstract class Doctrine_Query_Part
{ {
return $this->query; 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 ...@@ -34,11 +34,8 @@ class Doctrine_Query_Select extends Doctrine_Query_Part
{ {
public function parse($dql) public function parse($dql)
{ {
if ($dql === '' || $dql === null) {
throw new Doctrine_Query_Exception('Empty select part given.');
}
$this->query->parseSelect($dql); $this->query->parseSelect($dql);
return $this->query; return null;
} }
} }
...@@ -51,9 +51,7 @@ class Doctrine_Query_Set extends Doctrine_Query_Part ...@@ -51,9 +51,7 @@ class Doctrine_Query_Set extends Doctrine_Query_Part
$result[] = $map['table']->getColumnName($field) . ' = ' . $set[1]; $result[] = $map['table']->getColumnName($field) . ' = ' . $set[1];
} }
$this->query->addQueryPart('set', implode(', ', $result)); return implode(', ', $result);
return $this->query;
} }
} }
...@@ -32,15 +32,6 @@ Doctrine::autoload('Doctrine_Query_Condition'); ...@@ -32,15 +32,6 @@ Doctrine::autoload('Doctrine_Query_Condition');
*/ */
class Doctrine_Query_Where extends 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 * load
* returns the parsed query part * 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