1
0
mirror of synced 2025-01-18 14:31:40 +03:00

added parseFunctionExpression

This commit is contained in:
zYne 2007-12-10 18:59:12 +00:00
parent e5d43b2fcc
commit 3500a6fb17

View File

@ -709,26 +709,8 @@ class Doctrine_Query extends Doctrine_Query_Abstract implements Countable, Seria
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);
$args = array(); $term[0] = $this->parseFunctionExpression($term[0]);
// 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) !== "'") {
@ -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));