Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Fixed doModifyLimitQuery for SQLServerPlatform #249

Merged
merged 1 commit into from about 1 year ago

3 participants

Norbert Orzechowicz doctrinebot Benjamin Eberlei
Norbert Orzechowicz

It seems that there is a problem in SQLServerPlatform doModifyLimitQuery method.
I can't use Doctrine ORM Paginator because of wrong position of DISTINCT statement in final limit subquery, here is the exception message I'm getting.
SQLSTATE[42000]: [Microsoft][SQL Server Native Client 10.0][SQL Server]Incorrect syntax near the keyword 'DISTINCT'.

My proposition is to change doModifyLimitQuery result from:

SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY username DESC) AS doctrine_rownum, * FROM user) ...

into:

SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username DESC) AS doctrine_rownum FROM user) ...

doctrinebot
Collaborator

Hello,

thank you for positing this Pull Request. I have automatically opened an issue on our Jira Bug Tracker for you with the details of this Pull-Request. See the Link:

http://doctrine-project.org/jira/browse/DBAL-416

Norbert Orzechowicz

@beberlei this PR works fine with simple Doctrine Paginator and it fix first point from this list (second point seems to be already done), I can also check those 2 other points and eventually think about some solution if you want.

Benjamin Eberlei
Owner

@norzechowicz thanks, help is very much appreciated with SQL Server, we don't have a core member that is using it in production and could always use somebody that offers some time for maintaining the complicated parts :-)

Benjamin Eberlei beberlei merged commit f3374cb into from January 20, 2013
Benjamin Eberlei beberlei closed this January 20, 2013
Norbert Orzechowicz norzechowicz deleted the branch January 20, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Showing 1 unique commit by 1 author.

Jan 18, 2013
Fixed doModifyLimitQuery for SQLServerPlatform d381339
This page is out of date. Refresh to see the latest.
4  lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
@@ -687,12 +687,12 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
687 687
 
688 688
                 // Remove ORDER BY clause from $query
689 689
                 $query = preg_replace('/\s+ORDER BY(.*)/', '', $query);
690  
-                $query = preg_replace('/^SELECT\s/', '', $query);
  690
+                $query = preg_replace('/\sFROM/i', ", ROW_NUMBER() OVER ($over) AS doctrine_rownum FROM", $query);
691 691
 
692 692
                 $start = $offset + 1;
693 693
                 $end = $offset + $limit;
694 694
 
695  
-                $query = "SELECT * FROM (SELECT ROW_NUMBER() OVER ($over) AS doctrine_rownum, $query) AS doctrine_tbl WHERE doctrine_rownum BETWEEN $start AND $end";
  695
+                $query = "SELECT * FROM ($query) AS doctrine_tbl WHERE doctrine_rownum BETWEEN $start AND $end";
696 696
             }
697 697
         }
698 698
 
2  tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php
@@ -154,7 +154,7 @@ public function testModifyLimitQueryWithEmptyOffset()
154 154
     public function testModifyLimitQueryWithOffset()
155 155
     {
156 156
         $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5);
157  
-        $this->assertEquals('SELECT * FROM (SELECT ROW_NUMBER() OVER (ORDER BY username DESC) AS doctrine_rownum, * FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
  157
+        $this->assertEquals('SELECT * FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY username DESC) AS doctrine_rownum FROM user) AS doctrine_tbl WHERE doctrine_rownum BETWEEN 6 AND 15', $sql);
158 158
     }
159 159
 
160 160
     public function testModifyLimitQueryWithAscOrderBy()
Commit_comment_tip

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.