Skip to content
Browse files

Merge pull request #2310 from asgrim/fix-order-of-params-for-migrations

[DB2] Move row number to the end of the field list in query limit/offset modification
2 parents a500e1a + 2ee02ed commit 625dd63568e386e11c01022c22e50adc2a8a7af6 @deeky666 deeky666 committed
View
2 lib/Doctrine/DBAL/Platforms/DB2Platform.php
@@ -749,7 +749,7 @@ protected function doModifyLimitQuery($query, $limit, $offset = null)
$offset = (int) (($offset)?:0);
// Todo OVER() needs ORDER BY data!
- $sql = 'SELECT db22.* FROM (SELECT ROW_NUMBER() OVER() AS DC_ROWNUM, db21.* '.
+ $sql = 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM '.
'FROM (' . $query . ') db21) db22 WHERE db22.DC_ROWNUM BETWEEN ' . ($offset+1) .' AND ' . ($offset+$limit);
return $sql;
View
8 tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php
@@ -347,21 +347,21 @@ public function testModifiesLimitQuery()
);
$this->assertEquals(
- 'SELECT db22.* FROM (SELECT ROW_NUMBER() OVER() AS DC_ROWNUM, db21.* FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM BETWEEN 1 AND 10',
+ 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM BETWEEN 1 AND 10',
$this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0)
);
$this->assertEquals(
- 'SELECT db22.* FROM (SELECT ROW_NUMBER() OVER() AS DC_ROWNUM, db21.* FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM BETWEEN 1 AND 10',
+ 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM BETWEEN 1 AND 10',
$this->_platform->modifyLimitQuery('SELECT * FROM user', 10)
);
$this->assertEquals(
- 'SELECT db22.* FROM (SELECT ROW_NUMBER() OVER() AS DC_ROWNUM, db21.* FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM BETWEEN 6 AND 15',
+ 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM BETWEEN 6 AND 15',
$this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 5)
);
$this->assertEquals(
- 'SELECT db22.* FROM (SELECT ROW_NUMBER() OVER() AS DC_ROWNUM, db21.* FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM BETWEEN 6 AND 5',
+ 'SELECT db22.* FROM (SELECT db21.*, ROW_NUMBER() OVER() AS DC_ROWNUM FROM (SELECT * FROM user) db21) db22 WHERE db22.DC_ROWNUM BETWEEN 6 AND 5',
$this->_platform->modifyLimitQuery('SELECT * FROM user', 0, 5)
);
}

0 comments on commit 625dd63

Please sign in to comment.
Something went wrong with that request. Please try again.