Ejemplo n.º 1
0
 /**
  * Compile an SQLCommand from this query clauses.
  * 
  * Valid Clauses:
  * <ul>
  *  <li>'from'      => to add an additional from clause</li>
  *  <li>'condition' => to insert a sql condition</li>
  *  <li>'order by'  => to set an order by</li>
  *  <li>'columns'   => specify only the columns you want to select (check if it work on aliases too?)</li>
  *  <li>'limit'     => adjust the limit (this is not sended to the SQLCommand since is intended to be used with PreparedStatements)</li>
  *  <li>'offset'    => adds an offset (this is not sended to the SQLCommand since is intended to be used with PreparedStatements)</li>
  *  <li>'left join' => add a left join</li>
  * </ul>
  *
  * @return SQLCommand
  */
 public function compile()
 {
     if (isset($this->clauses['include'])) {
         $this->clauses['left join'] = Inflector::pluralize($this->clauses['include']) . ' on ' . Inflector::pluralize($this->clauses['include']) . '.id=' . Inflector::tabelize($this->owner) . '.' . $this->clauses['include'] . '_id';
     }
     $command = SQLCommand::select()->from(Inflector::tabelize($this->owner));
     if (isset($this->clauses['from'])) {
         $command->from($this->clauses['from']);
     }
     if (isset($this->clauses['condition'])) {
         $command->where($this->clauses['condition']);
     }
     if (isset($this->clauses['order by'])) {
         $command->orderBy($this->clauses['order by']);
     }
     if (isset($this->clauses['columns'])) {
         $command->columns($this->clauses['columns']);
     }
     if (isset($this->clauses['limit'])) {
         $this->limit = $this->clauses['limit'];
     }
     if (isset($this->clauses['offset'])) {
         $this->offset = $this->clauses['offset'];
     }
     if (isset($this->clauses['left join'])) {
         $command->leftJoin('left outer join ' . $this->clauses['left join']);
     }
     return $command;
 }
Ejemplo n.º 2
0
 public function setUp()
 {
     $this->command = SQLCommand::select()->from('news');
 }