Commit 3500a6fb authored by zYne's avatar zYne

added parseFunctionExpression

parent e5d43b2f
......@@ -709,26 +709,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
if ($pos !== false) {
$name = substr($term[0], 0, $pos);
if ($name !== '') {
$argStr = substr($term[0], ($pos + 1), -1);
$args = array();
// parse args
foreach ($this->_tokenizer->sqlExplode($argStr, ',') as $expr) {
$args[] = $this->parseClause($expr);
}
// convert DQL function to its RDBMS specific equivalent
try {
$expr = call_user_func_array(array($this->_conn->expression, $name), $args);
} catch (Doctrine_Expression_Exception $e) {
throw new Doctrine_Query_Exception('Unknown function ' . $expr . '.');
}
$term[0] = $expr;
} else {
$term[0] = $this->parseSubquery($term[0]);
}
$term[0] = $this->parseFunctionExpression($term[0]);
} else {
if (substr($term[0], 0, 1) !== "'" && substr($term[0], -1) !== "'") {
......@@ -838,6 +820,34 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
}
return $str;
}
public function parseFunctionExpression($expr)
{
$pos = strpos($expr, '(');
$name = substr($expr, 0, $pos);
if ($name === '') {
return $this->parseSubquery($expr);
}
$argStr = substr($expr, ($pos + 1), -1);
$args = array();
// parse args
foreach ($this->_tokenizer->sqlExplode($argStr, ',') as $arg) {
$args[] = $this->parseClause($arg);
}
// convert DQL function to its RDBMS specific equivalent
try {
$expr = call_user_func_array(array($this->_conn->expression, $name), $args);
} catch (Doctrine_Expression_Exception $e) {
throw new Doctrine_Query_Exception('Unknown function ' . $name . '.');
}
return $expr;
}
public function parseSubquery($subquery)
{
$trimmed = trim($this->_tokenizer->bracketTrim($subquery));
......
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