forked from doctrine/orm
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
copy fix from chihiro-adachi for mysql 5.7
copy fixed doctrine#5622 - mysql 5.7 ONLY_FULL_GROUP_BY doctrine#6143 chihiro-adachi wants to merge 2 commits into doctrine:master from chihiro-adachi:patch-1
- Loading branch information
Showing
1 changed file
with
34 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,20 @@ | ||
<?php | ||
/** | ||
* Doctrine ORM | ||
* | ||
* LICENSE | ||
/* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* This source file is subject to the new BSD license that is bundled | ||
* with this package in the file LICENSE.txt. | ||
* If you did not receive a copy of the license and are unable to | ||
* obtain it through the world-wide-web, please send an email | ||
* to [email protected] so I can send you a copy immediately. | ||
* This software consists of voluntary contributions made by many individuals | ||
* and is licensed under the MIT license. For more information, see | ||
* <http://www.doctrine-project.org>. | ||
*/ | ||
|
||
namespace Doctrine\ORM\Tools\Pagination; | ||
|
@@ -18,18 +24,9 @@ | |
use Doctrine\DBAL\Platforms\PostgreSqlPlatform; | ||
use Doctrine\DBAL\Platforms\SQLAnywherePlatform; | ||
use Doctrine\DBAL\Platforms\SQLServerPlatform; | ||
use Doctrine\ORM\Query\AST\ArithmeticExpression; | ||
use Doctrine\ORM\Query\AST\ArithmeticFactor; | ||
use Doctrine\ORM\Query\AST\ArithmeticTerm; | ||
use Doctrine\ORM\Query\AST\Literal; | ||
use Doctrine\ORM\Query\AST\OrderByClause; | ||
use Doctrine\ORM\Query\AST\OrderByItem; | ||
use Doctrine\ORM\Query\AST\PartialObjectExpression; | ||
use Doctrine\ORM\Query\AST\PathExpression; | ||
use Doctrine\ORM\Query\AST\SelectExpression; | ||
use Doctrine\ORM\Query\AST\SimpleArithmeticExpression; | ||
use Doctrine\ORM\Query\Expr\OrderBy; | ||
use Doctrine\ORM\Query\Expr\Select; | ||
use Doctrine\ORM\Query\SqlWalker; | ||
use Doctrine\ORM\Query\AST\SelectStatement; | ||
|
||
|
@@ -376,14 +373,30 @@ private function preserveSqlOrdering(array $sqlIdentifier, $innerSql, $sql, $ord | |
/* @var array $orderBy an array of rebuilt order by items */ | ||
$orderBy = $this->rebuildOrderByClauseForOuterScope($orderByClause); | ||
|
||
// Build the select distinct statement | ||
$innerSqlIdentifier = $sqlIdentifier; | ||
|
||
foreach ($orderBy as $field) { | ||
$field = preg_replace('/((\S+)\s+(ASC|DESC)\s*,?)*/', '${2}', $field); | ||
|
||
// skip fields that are selected by identifiers, | ||
// if those are ordered by in the query | ||
if (in_array($field, $sqlIdentifier, true)) { | ||
continue; | ||
} | ||
$innerSqlIdentifier[] = $field; | ||
} | ||
|
||
// Build the innner select statement | ||
$sql = sprintf( | ||
'SELECT DISTINCT %s FROM (%s) dctrn_result ORDER BY %s', | ||
implode(', ', $sqlIdentifier), | ||
'SELECT DISTINCT %s FROM (%s) dctrn_result_inner ORDER BY %s', | ||
implode(', ', $innerSqlIdentifier), | ||
$innerSql, | ||
implode(', ', $orderBy) | ||
); | ||
|
||
// now only select distinct identifier | ||
$sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', implode(', ', $sqlIdentifier), $sql); | ||
|
||
return $sql; | ||
} | ||
|
||
|
@@ -440,7 +453,6 @@ private function rebuildOrderByClauseForOuterScope(OrderByClause $orderByClause) | |
$otherClassMetadata = $this->em->getClassMetadata($fieldMapping['declared']); | ||
if (!$otherClassMetadata->isMappedSuperclass) { | ||
$sqlTableAliasForFieldAlias = $this->getSQLTableAlias($otherClassMetadata->getTableName(), $dqlAliasForFieldAlias); | ||
|
||
} | ||
} | ||
|
||
|