Exemple #1
0
 /**
  * Compiles an array of ORDER BY statements into an SQL partial.
  *
  * @param  array $columns sorting columns
  * @return string
  */
 protected function compileOrderBy(array $columns)
 {
     $sort = array();
     foreach ($columns as $group) {
         list($column, $direction) = $group;
         if (is_array($column)) {
             $column = $this->quoter->quoteIdentifier(end($column));
         } else {
             $column = $this->quoter->quoteColumn($column);
         }
         if ($direction) {
             $direction = ' ' . strtoupper($direction);
         }
         $sort[] = $column . $direction;
     }
     return 'ORDER BY ' . implode(', ', $sort);
 }
Exemple #2
0
 /**
  * Compile the SQL partial for a JOIN statement and return it.
  *
  * @return  string
  */
 public function compile()
 {
     if (null !== $this->type) {
         $sql = strtoupper($this->type) . ' JOIN';
     } else {
         $sql = 'JOIN';
     }
     $sql .= ' ' . $this->quoter->quoteTable($this->table);
     if (!empty($this->using)) {
         $sql .= ' USING (' . implode(', ', array_map(array($this->quoter, 'quoteColumn'), $this->using)) . ')';
     } else {
         $conditions = array();
         foreach ($this->on as $condition) {
             list($c1, $op, $c2) = $condition;
             if ($op) {
                 $op = ' ' . strtoupper($op);
             }
             $conditions[] = $this->quoter->quoteColumn($c1) . $op . ' ' . $this->quoter->quoteColumn($c2);
         }
         $sql .= ' ON (' . implode(' AND ', $conditions) . ')';
     }
     return $sql;
 }
Exemple #3
0
 /**
  * Creates a new SQL query of the specified type.
  *
  * @param   string   $sql   query string
  */
 public function __construct($sql)
 {
     $this->sql = $sql;
     $this->quoter = Quoter::instance();
 }