[2.0][DDC-43] Fixing order of limit and offset
This commit is contained in:
parent
7ec25f196a
commit
f3f522b7f3
@ -1149,33 +1149,6 @@ abstract class AbstractPlatform
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a LIMIT/OFFSET clause to the query.
|
||||
* This default implementation writes the syntax "LIMIT x OFFSET y" to the
|
||||
* query which is supported by MySql, PostgreSql and Sqlite.
|
||||
* Any database platforms that do not support this syntax should override
|
||||
* this implementation and provide their own.
|
||||
*
|
||||
* @param string $query The SQL string to write to / append to.
|
||||
* @param mixed $limit
|
||||
* @param mixed $offset
|
||||
*/
|
||||
public function writeLimitClause($query, $limit = false, $offset = false)
|
||||
{
|
||||
$limit = (int) $limit;
|
||||
$offset = (int) $offset;
|
||||
|
||||
if ($limit && $offset) {
|
||||
$query .= ' LIMIT ' . $limit . ' OFFSET ' . $offset;
|
||||
} elseif ($limit && ! $offset) {
|
||||
$query .= ' LIMIT ' . $limit;
|
||||
} elseif ( ! $limit && $offset) {
|
||||
$query .= ' LIMIT 999999999999 OFFSET ' . $offset;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
/**
|
||||
* Some platforms need the boolean values to be converted.
|
||||
* Default conversion defined here converts to integers.
|
||||
@ -1534,14 +1507,14 @@ abstract class AbstractPlatform
|
||||
|
||||
public function modifyLimitQuery($query, $limit, $offset = null)
|
||||
{
|
||||
if ( ! is_null($offset)) {
|
||||
$query .= ' OFFSET ' . $offset;
|
||||
}
|
||||
|
||||
if ( ! is_null($limit)) {
|
||||
$query .= ' LIMIT ' . $limit;
|
||||
}
|
||||
|
||||
if ( ! is_null($offset)) {
|
||||
$query .= ' OFFSET ' . $offset;
|
||||
}
|
||||
|
||||
return $query;
|
||||
}
|
||||
|
||||
|
@ -186,7 +186,7 @@ class MySqlPlatformTest extends \Doctrine\Tests\DbalTestCase
|
||||
public function testModifyLimitQuery()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
|
||||
$this->assertEquals('SELECT * FROM user OFFSET 0 LIMIT 10', $sql);
|
||||
$this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithEmptyOffset()
|
||||
|
@ -212,7 +212,7 @@ class PostgreSqlPlatformTest extends \Doctrine\Tests\DbalTestCase
|
||||
public function testModifyLimitQuery()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
|
||||
$this->assertEquals('SELECT * FROM user OFFSET 0 LIMIT 10', $sql);
|
||||
$this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithEmptyOffset()
|
||||
|
@ -114,7 +114,7 @@ class SqlitePlatformTest extends \Doctrine\Tests\DbalTestCase
|
||||
public function testModifyLimitQuery()
|
||||
{
|
||||
$sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
|
||||
$this->assertEquals('SELECT * FROM user OFFSET 0 LIMIT 10', $sql);
|
||||
$this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
|
||||
}
|
||||
|
||||
public function testModifyLimitQueryWithEmptyOffset()
|
||||
|
@ -361,7 +361,7 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
->setMaxResults(10)
|
||||
->setFirstResult(0);
|
||||
|
||||
$this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ OFFSET 0 LIMIT 10', $q->getSql());
|
||||
$this->assertEquals('SELECT c0_.id AS id0, c0_.status AS status1, c0_.username AS username2, c0_.name AS name3 FROM cms_users c0_ LIMIT 10 OFFSET 0', $q->getSql());
|
||||
}
|
||||
|
||||
public function testSizeFunction()
|
||||
|
Loading…
x
Reference in New Issue
Block a user