public function testSelectStatementWithOrder()
 {
     $table = new TableExpression('table', 't');
     $field1 = new FieldExpression('field1', $table, 'f1');
     $field2 = new FieldExpression('field2', $table);
     $field3 = new FieldExpression('field3');
     $statement = new SelectStatement();
     $statement->addField($field1);
     $statement->addField($field2);
     $statement->addField($field3);
     $statement->addTable($table);
     $statement->addOrderBy(new OrderExpression($field1));
     $statement->addOrderBy(new OrderExpression($field2, OrderExpression::DIRECTION_DESC));
     $statement->addOrderBy(new OrderExpression($field3));
     $sql = $this->parser->parseStatement($statement);
     $this->assertNotNull($sql);
     $this->assertEquals('SELECT `t`.`field1` AS `f1`, `t`.`field2`, `field3` FROM `table` AS `t` ORDER BY `f1` ASC, `t`.`field2` DESC, `field3` ASC', $sql);
 }
Example #2
0
 /**
  * Adds the order by expressions to the statement
  * @param array $orderBy Array with database order expressions
  * @return null
  */
 private function addOrderBy(array $orderBy)
 {
     foreach ($orderBy as $order) {
         $this->statement->addOrderBy($order);
     }
 }