Skip to content
Snippets Groups Projects
Commit 8b6d2d1f authored by Jared Hancock's avatar Jared Hancock
Browse files

orm: Support Interval literals and expressions

This adds support for things like

    SqlInterval::MINUTE(3)
    SqlExpression::minus(SqlFunction::NOW(), SqlInterval::DAY(1))
parent 57d00792
No related branches found
No related tags found
No related merge requests found
...@@ -478,6 +478,47 @@ class SqlFunction { ...@@ -478,6 +478,47 @@ class SqlFunction {
} }
} }
class SqlExpression extends SqlFunction {
var $operator;
var $operands;
function toSql($compiler, $model=false, $alias=false) {
$O = array();
foreach ($this->args as $operand)
$O[] = $compiler->input($operand);
return implode(' '.$this->func.' ', $O);
}
static function __callStatic($operator, $operands) {
switch ($operator) {
case 'minus':
$operator = '-'; break;
case 'plus':
$operator = '+'; break;
default:
throw new InvalidArgumentException('Invalid operator specified');
}
return parent::__callStatic($operator, $operands);
}
}
class SqlInterval extends SqlFunction {
var $type;
function toSql($compiler, $model=false, $alias=false) {
return sprintf('INTERVAL %s %s',
$compiler->input($this->args[0]),
$this->func);
}
static function __callStatic($interval, $args) {
if (count($args) != 1) {
throw new InvalidArgumentException("Interval expects a single interval value");
}
return parent::__callStatic($interval, $args);
}
}
class Aggregate extends SqlFunction { class Aggregate extends SqlFunction {
var $func; var $func;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment