public function __construct($oClass, $oClassAlias, BinaryExpression $oExpression) { $this->m_oClass = $oClass; $this->m_oClassAlias = $oClassAlias; $this->m_oLeftField = $oExpression->GetLeftExpr(); $this->m_oRightField = $oExpression->GetRightExpr(); $this->m_oRightField = $oExpression->GetRightExpr(); $this->m_sOperator = $oExpression->GetOperator(); }
$this->visit($node->right); $right = $this->stack->pop(); $left = $this->stack->pop(); switch ($node->op) { case '+': $this->stack->push($left + $right); return; case '-': $this->stack->push($left - $right); return; case '*': $this->stack->push($left * $right); return; case '/': $this->stack->push($left / $right); return; } throw new \Exception("Operator {$node->op} is not supported"); } } $x = new ConstExpression(1); $y = new ConstExpression(2); $z = new ConstExpression(3); $op1 = new BinaryExpression("+", $x, $y); $op2 = new UnaryExpression("-", $op1); $exp = new BinaryExpression("*", $op2, $z); $printer = new PrintExpressionVisitor(); $interpreter = new InterpreterVisitor(); $exp->accept($printer); $exp->accept($interpreter); echo $interpreter->getResult();
public function testSelectGet() { $dialect = $this->getDbByType('PgSQL')->getDialect(); $query = OSQL::select()->from('test_table')->get(DBField::create('field1', 'test_table'), 'alias1')->get(DBField::create('field2', 'test_table'))->get('field3', 'alias3')->get('field4')->get(SQLFunction::create('count', DBField::create('field5', 'test_table'))->setAggregateDistinct()->setAlias('alias5'))->get(SQLFunction::create('substring', BinaryExpression::create(DBField::create('field6', 'test_table'), DBValue::create('a..b'), 'from')->noBrackets())); $this->assertEquals($query->toDialectString($dialect), 'SELECT ' . '"test_table"."field1" AS "alias1", ' . '"test_table"."field2", ' . '"test_table"."field3" AS "alias3", ' . '"test_table"."field4", ' . 'count(DISTINCT "test_table"."field5") AS "alias5", ' . 'substring("test_table"."field6" from \'a..b\') ' . 'FROM "test_table"'); }
function __call($operator, $operands) { array_unshift($operands, $this); return BinaryExpression::__callStatic($operator, $operands); }
public function testSqlFunction() { $criteria = Criteria::create(TestCity::dao())->addProjection(Projection::property(SQLFunction::create('count', SQLFunction::create('substring', BinaryExpression::create('name', BinaryExpression::create(DBValue::create('M....w'), DBValue::create('#'), 'for')->noBrackets(), 'from')->noBrackets()))->setAggregateDistinct()->setAlias('my_alias'))); $this->assertEquals($criteria->toDialectString(ImaginaryDialect::me()), 'SELECT count(DISTINCT substring(custom_table.name from M....w for #)) AS my_alias FROM custom_table'); }
/** * Creates new instance of ArithmeticExpression * * @param AbstractExpression $left left expression * @param AbstractExpression $right right Expression * @param ExpressionType $nodeType Expression node type * @param IType $type Expression type */ public function __construct($left, $right, $nodeType, $type) { $this->nodeType = $nodeType; $this->type = $type; parent::__construct($left, $right); }