Beispiel #1
0
 /**
  * Select Mode Parser.
  */
 private function parseSelectQuery()
 {
     // Parse select ?
     $selectSql = Column::generateQueryString($this->query->select);
     // Parse table
     $fromSql = Table::generateQueryString($this->query->table);
     $whereSql = null;
     $whereBind = array();
     $sql = ['select' => $selectSql, 'from' => $fromSql, 'where' => $whereSql];
     $this->bind = array_merge($this->bind, $whereBind);
     $this->sql = $this->combineSelectQuery($sql);
 }
Beispiel #2
0
 /**
  * Select query.
  *
  * @param array|string|null $column Array of column names, null for every column.
  * You can also provide string with comma separated list of columns, just as you would do
  * with a normal query.
  * When giving array like this:
  *  column => as_name
  * You will make an alias for the selected column!
  *
  * @param bool $replace Replace existing select columns. Default false (no).
  *
  * @throws QueryBuilderException
  *
  * @return QueryBuilder
  */
 public function select($column = null, $replace = false)
 {
     // Check if mode is defined. Then stop.
     if ($this->query->mode !== Query::MODE_NONE && $this->query->mode !== Query::MODE_SELECT) {
         $this->exception = new QueryBuilderException("The query mode is already defined!");
         return $this;
     }
     // Parse when string
     if (is_string($column)) {
         if (strstr($column, ',')) {
             // Explode
             $column = explode(',', $column);
         } elseif ($column === '*') {
             $column = null;
         } else {
             $column = array($column);
         }
     }
     // Replace
     if ($replace) {
         $this->query->select = array();
     }
     // When * is given
     if ($column === null) {
         // Ignore the select here, we will just add the * to our stack.
         $part = new Column("*");
         $part->appendQuery($this->query);
         $this->query->mode = Query::MODE_SELECT;
         return $this;
     }
     // Invalid type?
     if (!is_array($column)) {
         $this->exception = new QueryException("Select column should be string or array!");
         return $this;
     }
     // Append to current select.
     foreach ($column as $key => $value) {
         $columnName = null;
         $columnAs = null;
         if (is_string($key)) {
             $columnName = trim($key);
             $columnAs = trim($value);
         } else {
             $columnName = trim($value);
         }
         $columnPart = new Column($columnName);
         $columnPart->setColumnAs($columnAs);
         $columnPart->appendQuery($this->query);
     }
     // Set mode and return self.
     $this->query->mode = Query::MODE_SELECT;
     return $this;
 }