public function testAssemble()
 {
     $selector = new SumSelectExpression();
     $selector->setField('fieldname');
     $this->assertEquals('SUM(fieldname)', QueryAssembler::stringify($selector));
     $selector->setAlias('cnt');
     $this->assertEquals('SUM(fieldname) AS cnt', QueryAssembler::stringify($selector));
 }
예제 #2
0
 public function sum($property = 'id')
 {
     return $this->_getAggregate(__FUNCTION__, SumSelectExpression::create($property));
 }
 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))));
 }
예제 #4
0
 public function testArithmetic()
 {
     $this->assertEquals('(5 + (10 - 5))', QueryAssembler::stringify(AdditionExpression::create(5, SubtractExpression::create(10, 5))));
     $this->assertEquals('(SUM(amt) + (10 - 5))', QueryAssembler::stringify(AdditionExpression::create(SumSelectExpression::create('amt'), SubtractExpression::create(10, 5))));
 }