build() public method

Generates a SELECT SQL statement from a Query object.
public build ( Query $query, array $params = [] ) : array
$query Query the [[Query]] object from which the SQL statement will be generated.
$params array 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`.
Exemplo n.º 1
0
 /**
  * @inheritdoc
  * Firebird has its own SELECT syntax
  * SELECT [FIRST (<int-expr>)] [SKIP (<int-expr>)] <columns> FROM ...
  * @author srusakov@gmail.com
  */
 public function build($query, $params = [])
 {
     list($sql, $params) = parent::build($query, $params);
     if ($this->hasLimit($query->limit) and $this->hasOffset($query->offset)) {
         $sql = preg_replace('/limit\\s\\d+/i', '', $sql, 1);
         $sql = preg_replace('/offset\\s\\d+/i', '', $sql, 1);
         $sql = preg_replace('/^SELECT /i', "SELECT FIRST {$query->limit} SKIP {$query->offset} ", $sql, 1);
     } elseif ($this->hasLimit($query->limit)) {
         $sql = preg_replace('/limit\\s\\d+/i', '', $sql, 1);
         $sql = preg_replace('/offset\\s\\d+/i', '', $sql, 1);
         $sql = preg_replace('/^SELECT /i', "SELECT FIRST {$query->limit} ", $sql, 1);
     } elseif ($this->hasOffset($query->offset)) {
         $sql = preg_replace('/limit\\s\\d+/i', '', $sql, 1);
         $sql = preg_replace('/offset\\s\\d+/i', '', $sql, 1);
         $sql = preg_replace('/^SELECT /i', "SELECT SKIP {$query->offset} ", $sql, 1);
     }
     return [$sql, $params];
 }