Commit 3500a6fb authored by zYne's avatar zYne

added parseFunctionExpression

parent e5d43b2f
...@@ -706,32 +706,14 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -706,32 +706,14 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
$str = ''; $str = '';
foreach ($terms as $term) { foreach ($terms as $term) {
$pos = strpos($term[0], '('); $pos = strpos($term[0], '(');
if ($pos !== false) { if ($pos !== false) {
$name = substr($term[0], 0, $pos); $name = substr($term[0], 0, $pos);
if ($name !== '') {
$argStr = substr($term[0], ($pos + 1), -1); $term[0] = $this->parseFunctionExpression($term[0]);
$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]);
}
} else { } else {
if (substr($term[0], 0, 1) !== "'" && substr($term[0], -1) !== "'") { if (substr($term[0], 0, 1) !== "'" && substr($term[0], -1) !== "'") {
if (strpos($term[0], '.') !== false) { if (strpos($term[0], '.') !== false) {
if ( ! is_numeric($term[0])) { if ( ! is_numeric($term[0])) {
$e = explode('.', $term[0]); $e = explode('.', $term[0]);
...@@ -838,6 +820,34 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria ...@@ -838,6 +820,34 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
} }
return $str; 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) public function parseSubquery($subquery)
{ {
$trimmed = trim($this->_tokenizer->bracketTrim($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