src/SQL/Compiler/SQLServer.php
public function select(SQLStatement $select): string
    {
        $limit = $select->getLimit();

        if ($limit <= 0) {
            return parent::select($select);
        }

        $offset = $select->getOffset();

        if ($offset < 0) {
            $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
            $sql .= 'TOP ' . $limit . ' ';
            $sql .= $this->handleColumns($select->getColumns());
            $sql .= $this->handleInto($select->getIntoTable(), $select->getIntoDatabase());
            $sql .= ' FROM ';
            $sql .= $this->handleTables($select->getTables());
            $sql .= $this->handleJoins($select->getJoins());
            $sql .= $this->handleWheres($select->getWheres());
            $sql .= $this->handleGroupings($select->getGroupBy());
            $sql .= $this->handleOrderings($select->getOrder());
            $sql .= $this->handleHavings($select->getHaving());

            return $sql;
        }

        $order = trim($this->handleOrderings($select->getOrder()));

        if (empty($order)) {
            $order = 'ORDER BY (SELECT 0)';
        }

        $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
        $sql .= $this->handleColumns($select->getColumns());
        $sql .= ', ROW_NUMBER() OVER (' . $order . ') AS opis_rownum';
        $sql .= ' FROM ';
        $sql .= $this->handleTables($select->getTables());
        $sql .= $this->handleJoins($select->getJoins());
        $sql .= $this->handleWheres($select->getWheres());
        $sql .= $this->handleGroupings($select->getGroupBy());
        $sql .= $this->handleHavings($select->getHaving());

        $limit += $offset;
        $offset++;

        return 'SELECT * FROM (' . $sql . ') AS m1 WHERE opis_rownum BETWEEN ' . $offset . ' AND ' . $limit;
    }
public function select(SQLStatement $select): string
    {
        $limit = $select->getLimit();

        if ($limit <= 0) {
            return parent::select($select);
        }

        $offset = $select->getOffset();

        if ($offset < 0) {
            $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
            $sql .= 'TOP ' . $limit . ' ';
            $sql .= $this->handleColumns($select->getColumns());
            $sql .= $this->handleInto($select->getIntoTable(), $select->getIntoDatabase());
            $sql .= ' FROM ';
            $sql .= $this->handleTables($select->getTables());
            $sql .= $this->handleJoins($select->getJoins());
            $sql .= $this->handleWheres($select->getWheres());
            $sql .= $this->handleGroupings($select->getGroupBy());
            $sql .= $this->handleOrderings($select->getOrder());
            $sql .= $this->handleHavings($select->getHaving());

            return $sql;
        }

        $order = trim($this->handleOrderings($select->getOrder()));

        if (empty($order)) {
            $order = 'ORDER BY (SELECT 0)';
        }

        $sql = $select->getDistinct() ? 'SELECT DISTINCT ' : 'SELECT ';
        $sql .= $this->handleColumns($select->getColumns());
        $sql .= ', ROW_NUMBER() OVER (' . $order . ') AS opis_rownum';
        $sql .= ' FROM ';
        $sql .= $this->handleTables($select->getTables());
        $sql .= $this->handleJoins($select->getJoins());
        $sql .= $this->handleWheres($select->getWheres());
        $sql .= $this->handleGroupings($select->getGroupBy());
        $sql .= $this->handleHavings($select->getHaving());

        $limit += $offset;
        $offset++;

        return 'SELECT * FROM (' . $sql . ') AS m1 WHERE opis_rownum BETWEEN ' . $offset . ' AND ' . $limit;
    }
public function select ( SQLStatement $ select ) : string { $ limit = $ select -> getLimit ( ) ; if ( $ limit <= 0 ) { return parent :: select ( $ select ) ; } $ offset = $ select -> getOffset ( ) ; if ( $ offset < 0 ) { $ sql = $ select -> getDistinct ( ) ? 'SELECT DISTINCT ' : 'SELECT ' ; $ sql .= 'TOP ' . $ limit . ' ' ; $ sql .= $ this -> handleColumns ( $ select -> getColumns ( ) ) ; $ sql .= $ this -> handleInto ( $ select -> getIntoTable ( ) , $ select -> getIntoDatabase ( ) ) ; $ sql .= ' FROM ' ; $ sql .= $ this -> handleTables ( $ select -> getTables ( ) ) ; $ sql .= $ this -> handleJoins ( $ select -> getJoins ( ) ) ; $ sql .= $ this -> handleWheres ( $ select -> getWheres ( ) ) ; $ sql .= $ this -> handleGroupings ( $ select -> getGroupBy ( ) ) ; $ sql .= $ this -> handleOrderings ( $ select -> getOrder ( ) ) ; $ sql .= $ this -> handleHavings ( $ select -> getHaving ( ) ) ; return $ sql ; } $ order = trim ( $ this -> handleOrderings ( $ select -> getOrder ( ) ) ) ; if ( empty ( $ order ) ) { $ order = 'ORDER BY (SELECT 0)' ; } $ sql = $ select -> getDistinct ( ) ? 'SELECT DISTINCT ' : 'SELECT ' ; $ sql .= $ this -> handleColumns ( $ select -> getColumns ( ) ) ; $ sql .= ', ROW_NUMBER() OVER (' . $ order . ') AS opis_rownum' ; $ sql .= ' FROM ' ; $ sql .= $ this -> handleTables ( $ select -> getTables ( ) ) ; $ sql .= $ this -> handleJoins ( $ select -> getJoins ( ) ) ; $ sql .= $ this -> handleWheres ( $ select -> getWheres ( ) ) ; $ sql .= $ this -> handleGroupings ( $ select -> getGroupBy ( ) ) ; $ sql .= $ this -> handleHavings ( $ select -> getHaving ( ) ) ; $ limit += $ offset ; $ offset ++ ; return 'SELECT * FROM (' . $ sql . ') AS m1 WHERE opis_rownum BETWEEN ' . $ offset . ' AND ' . $ limit ; }
Compiles a SELECT query

@param SQLStatement $select
@return string
Compiles a SELECT query