Fixed doModifyLimitQuery for SQLServerPlatform #249

Merged
merged 1 commit into from Jan 20, 2013
View
4 lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
@@ -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";
}
}
View
2 tests/Doctrine/Tests/DBAL/Platforms/SQLServerPlatformTest.php
@@ -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()