Example #1
0
 /**
  * Generates a SELECT SQL statement from a [[Query]] object.
  * @param Query $query the [[Query]] object from which the SQL statement will be generated.
  * @param array $params the parameters to be bound to the generated SQL statement. These parameters will
  * be included in the result with the additional parameters generated during the query building process.
  * @return array the generated SQL statement (the first array element) and the corresponding
  * parameters to be bound to the SQL statement (the second array element). The parameters returned
  * include those provided in `$params`.
  */
 public function build($query, $params = [])
 {
     $query->prepareBuild($this);
     $params = empty($params) ? $query->params : array_merge($params, $query->params);
     $clauses = [$this->buildSelect($query->select, $params, $query->distinct, $query->selectOption), $this->buildFrom($query->from, $params), $this->buildJoin($query->join, $params), $this->buildWhere($query->where, $params), $this->buildGroupBy($query->groupBy), $this->buildHaving($query->having, $params), $this->buildOrderBy($query->orderBy), $this->buildLimit($query->limit, $query->offset)];
     $sql = implode($this->separator, array_filter($clauses));
     $union = $this->buildUnion($query->union, $params);
     if ($union !== '') {
         $sql = "({$sql}){$this->separator}{$union}";
     }
     return [$sql, $params];
 }