public function getSelectSql()
    {
        $sql = "SELECT ";

        $sql .= $this->implodeSqlClauses($this->columns, ", ").
            " FROM `".$this->schemaName."` AS `".$this->getAlias()."`";

        foreach($this->joins as $join){
            $joinsSql = $join->getSql($this);
            if (strpos($joinsSql," ") !== false){
                $joinsSql = "(".$joinsSql.")";
            }

            $sql .= " ".$join->joinType." ".$joinsSql." AS `".$join->statement->getAlias()."` ON `".$this->getAlias()."`.`".
                $join->parentColumn."` = `".$join->statement->getAlias()."`.`".$join->childColumn."`";
        }

        if ($this->whereExpression) {
            $havingSql = $this->whereExpression->getWhereSql($this);
            if ($havingSql != "" ){
                $sql .= " WHERE ".$havingSql;
            }
        }
        
        if (count($this->groups)){
            $sql .= " GROUP BY ".$this->implodeSqlClauses($this->groups, ", ");
        }

        if ($this->whereExpression) {
            $havingSql = $this->whereExpression->getHavingSql($this);
            if ($havingSql != "" ){
                $sql .= " HAVING ".$havingSql;
            }
        }

        if (count($this->sorts)){
            $sql .= " ORDER BY ".$this->implodeSqlClauses($this->sorts, ", ");
        }

        if ($this->hasLimit()){
            $sql .= " LIMIT ".$this->limitStart.", ".$this->limitCount;
        }

        return $sql;
    }
public function getSelectSql()
    {
        $sql = "SELECT ";

        $sql .= $this->implodeSqlClauses($this->columns, ", ").
            " FROM `".$this->schemaName."` AS `".$this->getAlias()."`";

        foreach($this->joins as $join){
            $joinsSql = $join->getSql($this);
            if (strpos($joinsSql," ") !== false){
                $joinsSql = "(".$joinsSql.")";
            }

            $sql .= " ".$join->joinType." ".$joinsSql." AS `".$join->statement->getAlias()."` ON `".$this->getAlias()."`.`".
                $join->parentColumn."` = `".$join->statement->getAlias()."`.`".$join->childColumn."`";
        }

        if ($this->whereExpression) {
            $havingSql = $this->whereExpression->getWhereSql($this);
            if ($havingSql != "" ){
                $sql .= " WHERE ".$havingSql;
            }
        }
        
        if (count($this->groups)){
            $sql .= " GROUP BY ".$this->implodeSqlClauses($this->groups, ", ");
        }

        if ($this->whereExpression) {
            $havingSql = $this->whereExpression->getHavingSql($this);
            if ($havingSql != "" ){
                $sql .= " HAVING ".$havingSql;
            }
        }

        if (count($this->sorts)){
            $sql .= " ORDER BY ".$this->implodeSqlClauses($this->sorts, ", ");
        }

        if ($this->hasLimit()){
            $sql .= " LIMIT ".$this->limitStart.", ".$this->limitCount;
        }

        return $sql;
    }
public function getSelectSql ( ) { $ sql = "SELECT " ; $ sql .= $ this -> implodeSqlClauses ( $ this -> columns , ", " ) . " FROM `" . $ this -> schemaName . "` AS `" . $ this -> getAlias ( ) . "`" ; foreach ( $ this -> joins as $ join ) { $ joinsSql = $ join -> getSql ( $ this ) ; if ( strpos ( $ joinsSql , " " ) !== false ) { $ joinsSql = "(" . $ joinsSql . ")" ; } $ sql .= " " . $ join -> joinType . " " . $ joinsSql . " AS `" . $ join -> statement -> getAlias ( ) . "` ON `" . $ this -> getAlias ( ) . "`.`" . $ join -> parentColumn . "` = `" . $ join -> statement -> getAlias ( ) . "`.`" . $ join -> childColumn . "`" ; } if ( $ this -> whereExpression ) { $ havingSql = $ this -> whereExpression -> getWhereSql ( $ this ) ; if ( $ havingSql != "" ) { $ sql .= " WHERE " . $ havingSql ; } } if ( count ( $ this -> groups ) ) { $ sql .= " GROUP BY " . $ this -> implodeSqlClauses ( $ this -> groups , ", " ) ; } if ( $ this -> whereExpression ) { $ havingSql = $ this -> whereExpression -> getHavingSql ( $ this ) ; if ( $ havingSql != "" ) { $ sql .= " HAVING " . $ havingSql ; } } if ( count ( $ this -> sorts ) ) { $ sql .= " ORDER BY " . $ this -> implodeSqlClauses ( $ this -> sorts , ", " ) ; } if ( $ this -> hasLimit ( ) ) { $ sql .= " LIMIT " . $ this -> limitStart . ", " . $ this -> limitCount ; } return $ sql ; }
Returns the SELECT statement required to fetch the data.
@return string
Returns the SELECT statement required to fetch the data .