Example #1
0
 /**
  * Compiles the GROUP BY clause of a SQL query.
  *
  * @return  array
  */
 private function compileGroup()
 {
     if (!$this->group) {
         return null;
     }
     $parts = [];
     foreach ($this->group as $column) {
         $parts[] = e\columnize($column, $this->alias);
     }
     return 'GROUP BY ' . implode($parts, ', ');
 }
Example #2
0
 /**
  * Compiles the ORDER BY clause of a SQL query.
  *
  * @return  array
  */
 private function compileOrder()
 {
     if (!$this->order) {
         return null;
     }
     $parts = [];
     foreach ($this->order as $source => $dir) {
         $parts[] = e\columnize($source, $this->alias) . ' ' . strtoupper($dir);
     }
     return 'ORDER BY ' . implode($parts, ', ');
 }
Example #3
0
 /**
  * @return  array
  */
 private function compilePart($alias, $type, $expr, array $params)
 {
     $ret = [];
     // Passing a simple string like 'foo.bar = ?', [$bar] should
     // work fine, so we can skip the complicated array syntax.
     if (is_string($expr)) {
         return [['expr' => $expr, 'params' => $params, 'type' => $type]];
     }
     // Allow passing completely bare expressions.
     if ($expr instanceof ExpressionInterface) {
         return [['expr' => $expr->getExpr($alias), 'params' => $expr->getBinds(), 'type' => $type]];
     }
     foreach ($expr as $column => $value) {
         // Allow passing a literal string, which is useful for
         // completely literal expressions (such as those used for joins).
         if (is_int($column)) {
             $ret[] = ['expr' => $value, 'type' => $type, 'params' => []];
             continue;
         }
         // Try and provide a table alias if possible.
         $column = e\columnize($column, $alias);
         // And automatically detect an IN if possible.
         if (is_array($value)) {
             $value = e\in($value);
         }
         if (!$value instanceof ExpressionInterface) {
             $value = e\eq($value);
         }
         $ret[] = ['expr' => $value->getExpr($column), 'params' => $value->getBinds(), 'type' => $type];
     }
     return $ret;
 }
Example #4
0
 /**
  * Compiles the columns to select in a SELECT.
  *
  * @return  string
  */
 private function compileColumns()
 {
     if (!$this->select) {
         $this->select = ['*'];
     }
     $parts = [];
     foreach ($this->select as $column => $alias) {
         // Allow no aliasing as well, as denoted by an it key
         if (is_int($column)) {
             $parts[] = e\columnize($alias, $this->alias);
         } else {
             $column = e\columnize($column, $this->alias);
             $parts[] = e\alias($column, $alias);
         }
     }
     return implode($parts, ', ');
 }