Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge pull request #249 from norzechowicz/sqlserver-platform

Fixed doModifyLimitQuery for SQLServerPlatform
  • Loading branch information...
commit f3374cb1daca1b3eb0ed2a78117a877c2928f6d2 2 parents 6137eac + d381339
Benjamin Eberlei beberlei authored
4 lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
View
@@ -687,12 +687,12 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
// Remove ORDER BY clause from $query
$query = preg_replace('/\s+ORDER BY(.*)/', '', $query);
- $query = preg_replace('/^SELECT\s/', '', $query);
+ $query = preg_replace('/\sFROM/i', ", ROW_NUMBER() OVER ($over) AS doctrine_rownum FROM", $query);
$start = $offset + 1;
$end = $offset + $limit;
- $query = "SELECT * FROM (SELECT ROW_NUMBER() OVER ($over) AS doctrine_rownum, $query) AS doctrine_tbl WHERE doctrine_rownum BETWEEN $start AND $end";
+ $query = "SELECT * FROM ($query) AS doctrine_tbl WHERE doctrine_rownum BETWEEN $start AND $end";
}
}
2  tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php
View
@@ -154,7 +154,7 @@ public function testModifyLimitQueryWithEmptyOffset()
public function testModifyLimitQueryWithOffset()
{
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10, 5);
- $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);
+ $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);
}
public function testModifyLimitQueryWithAscOrderBy()
Please sign in to comment.
Something went wrong with that request. Please try again.