public function testAssemble()
 {
     $predicate = new GreaterThanOrEqualPredicate();
     $predicate->setField('field');
     $this->assertEquals('field >= NULL', QueryAssembler::stringify($predicate));
     $predicate->setExpression((new NumericExpression())->setValue(1));
     $this->assertEquals('field >= 1', QueryAssembler::stringify($predicate));
     $predicate->setExpression((new NumericExpression())->setValue('1'));
     $this->assertEquals('field >= 1', QueryAssembler::stringify($predicate));
     $predicate->setExpression((new StringExpression())->setValue('abc'));
     $this->assertEquals('field >= "abc"', QueryAssembler::stringify($predicate));
 }
 public function testExpressionSelectExpression()
 {
     $this->assertEquals('(SUM(field1) + SUM(field2)) AS sum_field', QueryAssembler::stringify(ExpressionSelectExpression::createWithAlias(AdditionExpression::create(SumSelectExpression::create('field1'), SumSelectExpression::create('field2')), 'sum_field')));
     $this->assertEquals('SELECT (SUM(field1) + SUM(field2)) AS sum_field FROM tbl HAVING sum_field >= 5', QueryAssembler::stringify(QueryBuilder::select(ExpressionSelectExpression::createWithAlias(AdditionExpression::create(SumSelectExpression::create('field1'), SumSelectExpression::create('field2')), 'sum_field'))->from('tbl')->having(GreaterThanOrEqualPredicate::create('sum_field', 5))));
 }
Exemplo n.º 3
0
 public function assembleBetween(BetweenPredicate $betweenPredicate)
 {
     $gte = new GreaterThanOrEqualPredicate();
     $gte->setField($betweenPredicate->getField());
     $lte = new LessThanOrEqualPredicate();
     $lte->setField($betweenPredicate->getField());
     $set = new PredicateSet();
     if ($betweenPredicate instanceof NotBetweenPredicate) {
         $gte->setExpression($betweenPredicate->getRangeEnd());
         $lte->setExpression($betweenPredicate->getRangeStart());
         $set->addPredicate($lte);
         $set->addPredicate($gte);
     } else {
         $gte->setExpression($betweenPredicate->getRangeStart());
         $lte->setExpression($betweenPredicate->getRangeEnd());
         $set->addPredicate($gte);
         $set->addPredicate($lte);
     }
     return $this->assembleSegment($set);
 }