Drivers\Abstraction\Sql::command PHP Method

command() public method

Build the SQL statement.
public command ( ) : string
return string The complited SQL statement
    public function command()
    {
        $query = 'SELECT ';
        if ($this->distinct) {
            $query .= 'DISTINCT ';
            $this->distinct = false;
        }
        $column = '*';
        if (is_array($this->column)) {
            $column = implode(', ', $this->column);
            $this->column = '*';
        }
        $query .= $column;
        if (!empty($this->tables)) {
            $query .= ' FROM ' . implode(', ', $this->tables);
            $this->tables = array();
        }
        if (!is_null($this->joins)) {
            if (!is_null($this->joinsType)) {
                $query .= ' ' . strtoupper($this->joinsType);
                $this->joinsType = null;
            }
            $query .= ' JOIN ' . $this->joins;
            if (!empty($this->joinsOn)) {
                $query .= ' ON (' . implode(' ', $this->joinsOn) . ')';
                $this->joinsOn = array();
            }
            $this->joins = null;
        }
        if (!empty($this->criteria)) {
            $cr = implode(' ', $this->criteria);
            $query .= ' WHERE ' . rtrim(rtrim($cr, 'AND'), 'OR');
            $this->criteria = array();
        }
        if (!is_null($this->groupBy)) {
            $query .= ' GROUP BY ' . $this->groupBy;
            $this->groupBy = null;
        }
        if (!empty($this->isHaving)) {
            $query .= ' HAVING ' . implode(' ', $this->isHaving);
            $this->isHaving = array();
        }
        if (!is_null($this->orderBy)) {
            $query .= ' ORDER BY ' . $this->orderBy . ' ' . strtoupper($this->order);
            $this->orderBy = null;
        }
        if (!is_null($this->limit)) {
            $query .= ' LIMIT ' . $this->limit;
            if (!is_null($this->offset)) {
                $query .= ' OFFSET ' . $this->offset;
                $this->offset = null;
            }
            $this->limit = null;
        }
        $this->returnType = 'object';
        return $query;
    }