lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php
public function walkSelectStatementWithoutRowNumber(SelectStatement $AST, $addMissingItemsFromOrderByToSelect = true)
    {
        // We don't want to call this recursively!
        if ($AST->orderByClause instanceof OrderByClause && $addMissingItemsFromOrderByToSelect) {
            // In the case of ordering a query by columns from joined tables, we
            // must add those columns to the select clause of the query BEFORE
            // the SQL is generated.
            $this->addMissingItemsFromOrderByToSelect($AST);
        }

        // Remove order by clause from the inner query
        // It will be re-appended in the outer select generated by this method
        $orderByClause      = $AST->orderByClause;
        $AST->orderByClause = null;

        $innerSql           = $this->getInnerSQL($AST);
        $sqlIdentifier      = $this->getSQLIdentifier($AST);
        $sqlAliasIdentifier = array_map(static function ($info) {
            return $info['alias'];
        }, $sqlIdentifier);

        // Build the counter query
        $sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', implode(', ', $sqlAliasIdentifier), $innerSql);

        // http://www.doctrine-project.org/jira/browse/DDC-1958
        $sql = $this->preserveSqlOrdering($sqlAliasIdentifier, $innerSql, $sql, $orderByClause);

        // Apply the limit and offset.
        $sql = $this->platform->modifyLimitQuery(
            $sql,
            $this->maxResults,
            $this->firstResult ?? 0
        );

        // Add the columns to the ResultSetMapping. It's not really nice but
        // it works. Preferably I'd clear the RSM or simply create a new one
        // but that is not possible from inside the output walker, so we dirty
        // up the one we have.
        foreach ($sqlIdentifier as $property => $propertyMapping) {
            $this->rsm->addScalarResult($propertyMapping['alias'], $property, $propertyMapping['type']);
        }

        // Restore orderByClause
        $AST->orderByClause = $orderByClause;

        return $sql;
    }
public function walkSelectStatementWithoutRowNumber(SelectStatement $AST, $addMissingItemsFromOrderByToSelect = true)
    {
        // We don't want to call this recursively!
        if ($AST->orderByClause instanceof OrderByClause && $addMissingItemsFromOrderByToSelect) {
            // In the case of ordering a query by columns from joined tables, we
            // must add those columns to the select clause of the query BEFORE
            // the SQL is generated.
            $this->addMissingItemsFromOrderByToSelect($AST);
        }

        // Remove order by clause from the inner query
        // It will be re-appended in the outer select generated by this method
        $orderByClause      = $AST->orderByClause;
        $AST->orderByClause = null;

        $innerSql           = $this->getInnerSQL($AST);
        $sqlIdentifier      = $this->getSQLIdentifier($AST);
        $sqlAliasIdentifier = array_map(static function ($info) {
            return $info['alias'];
        }, $sqlIdentifier);

        // Build the counter query
        $sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', implode(', ', $sqlAliasIdentifier), $innerSql);

        // http://www.doctrine-project.org/jira/browse/DDC-1958
        $sql = $this->preserveSqlOrdering($sqlAliasIdentifier, $innerSql, $sql, $orderByClause);

        // Apply the limit and offset.
        $sql = $this->platform->modifyLimitQuery(
            $sql,
            $this->maxResults,
            $this->firstResult ?? 0
        );

        // Add the columns to the ResultSetMapping. It's not really nice but
        // it works. Preferably I'd clear the RSM or simply create a new one
        // but that is not possible from inside the output walker, so we dirty
        // up the one we have.
        foreach ($sqlIdentifier as $property => $propertyMapping) {
            $this->rsm->addScalarResult($propertyMapping['alias'], $property, $propertyMapping['type']);
        }

        // Restore orderByClause
        $AST->orderByClause = $orderByClause;

        return $sql;
    }
public function walkSelectStatementWithoutRowNumber ( SelectStatement $ AST , $ addMissingItemsFromOrderByToSelect = true ) { // We don't want to call this recursively! if ( $ AST -> orderByClause instanceof OrderByClause && $ addMissingItemsFromOrderByToSelect ) { // In the case of ordering a query by columns from joined tables, we // must add those columns to the select clause of the query BEFORE // the SQL is generated. $ this -> addMissingItemsFromOrderByToSelect ( $ AST ) ; } // Remove order by clause from the inner query // It will be re-appended in the outer select generated by this method $ orderByClause = $ AST -> orderByClause ; $ AST -> orderByClause = null ; $ innerSql = $ this -> getInnerSQL ( $ AST ) ; $ sqlIdentifier = $ this -> getSQLIdentifier ( $ AST ) ; $ sqlAliasIdentifier = array_map ( static function ( $ info ) { return $ info [ 'alias' ] ; } , $ sqlIdentifier ) ; // Build the counter query $ sql = sprintf ( 'SELECT DISTINCT %s FROM (%s) dctrn_result' , implode ( ', ' , $ sqlAliasIdentifier ) , $ innerSql ) ; // http://www.doctrine-project.org/jira/browse/DDC-1958 $ sql = $ this -> preserveSqlOrdering ( $ sqlAliasIdentifier , $ innerSql , $ sql , $ orderByClause ) ; // Apply the limit and offset. $ sql = $ this -> platform -> modifyLimitQuery ( $ sql , $ this -> maxResults , $ this -> firstResult ?? 0 ) ; // Add the columns to the ResultSetMapping. It's not really nice but // it works. Preferably I'd clear the RSM or simply create a new one // but that is not possible from inside the output walker, so we dirty // up the one we have. foreach ( $ sqlIdentifier as $ property => $ propertyMapping ) { $ this -> rsm -> addScalarResult ( $ propertyMapping [ 'alias' ] , $ property , $ propertyMapping [ 'type' ] ) ; } // Restore orderByClause $ AST -> orderByClause = $ orderByClause ; return $ sql ; }
Walks down a SelectStatement AST node, wrapping it in a SELECT DISTINCT.
This method is for platforms which DO NOT support ROW_NUMBER.

@param bool $addMissingItemsFromOrderByToSelect

@return string

@throws RuntimeException
Walks down a SelectStatement AST node wrapping it in a SELECT DISTINCT . This method is for platforms which DO NOT support ROW_NUMBER .