mirror of
https://github.com/doctrine/orm.git
synced 2026-03-24 06:52:09 +01:00
DDC-2687: Paginator with ORDER BY not working in MSSQL #3369
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @doctrinebot on GitHub (Sep 18, 2013).
Originally assigned to: @beberlei on GitHub.
Jira issue originally created by user flip101:
This bug report is similar to this one:
http://www.doctrine-project.org/jira/browse/DDC-2622
It's decided to make a new bug report to keep things cleaner (commits have already been done on the other report).
PHP code to test (A symfony 2.3 controller):
Schema:
One User to Many Reports
SQL ERROR:
FIX:
Change
sqlORDER BY r0_.aangemaakt DESCto
sqlORDER BY aangemaakt3 DESCThis fix should only be applied in case of the Paginator scenario, which looks like this:
When getting a normal result, like this:
it works fine without any problems.
The "normal" result should keep working correctly!
The SQL produced by the non-paginator result:
Notice
sqlORDER BY r0_.aangemaakt DESCthis is correct!The difference is that the Paginator wraps the query in in a query with distinct, this is done here:
https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php#L160
So far i know two different solutions.
Detect the wrapping query in SQLServerPlatform::doModifyLimitQuery with regex. See relevant code snippet below
This code would replace:
https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php#L856-L870
And takes two lines of codes from this commit:
5d7bcb6637/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php (L860-L861)Another solution is that the Paginator should be responsible for notifying the SQLServerPlatform::doModifyLimitQuery method if the query is wrapped or not. In that case, this line of code
https://github.com/doctrine/doctrine2/blob/master/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php#L171
should be replaced by
And this line of code:
https://github.com/doctrine/dbal/blob/master/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php#L818
should be replaced by
Of course parts of the code from the previous solution are still needed. But the $isWrapped detection is not done anymore by regex this way.