Skip to content
Snippets Groups Projects
Commit aebb7c96 authored by Peter Rotich's avatar Peter Rotich
Browse files

orm: Add bitwise op. support to SqlExpression

parent 9f8d850c
No related branches found
No related tags found
No related merge requests found
......@@ -491,6 +491,24 @@ class SqlFunction {
}
}
class SqlExpr extends SqlFunction {
function __construct($args) {
$this->args = $args;
}
function toSql($compiler, $model=false, $alias=false) {
$O = array();
foreach ($this->args as $field=>$value) {
list($field, $op) = $compiler->getField($field, $model);
if (is_callable($op))
$O[] = call_user_func($op, $field, $value, $model);
else
$O[] = sprintf($op, $field, $compiler->input($value));
}
return implode(' ', $O) . ($alias ? ' AS ' . $alias : '');
}
}
class SqlExpression extends SqlFunction {
var $operator;
var $operands;
......@@ -515,6 +533,10 @@ class SqlExpression extends SqlFunction {
$operator = '+'; break;
case 'times':
$operator = '*'; break;
case 'bitand':
$operator = '&'; break;
case 'bitor':
$operator = '|'; break;
default:
throw new InvalidArgumentException('Invalid operator specified');
}
......
......@@ -126,6 +126,8 @@ class SqlFunction {
class SqlExpression {
static function plus() {}
static function bitor() {}
static function bitand() {}
}
class SqlInterval {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment