Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix OFFSET without LIMIT cause MySQL syntax error. #261

Closed
wants to merge 7 commits into from
19 changes: 19 additions & 0 deletions lib/Doctrine/DBAL/Platforms/MySqlPlatform.php
Expand Up @@ -36,6 +36,25 @@
*/
class MySqlPlatform extends AbstractPlatform
{

/**
* Adds MySQL-specific LIMIT clause to the query
* 18446744073709551615 is 2^64-1 maximum of unsigned BIGINT the biggest limit possible
*/
protected function doModifyLimitQuery($query, $limit, $offset)
{
if ($limit !== null) {
$query .= ' LIMIT ' . $limit;
if ($offset !== null) {
$query .= ' OFFSET ' . $offset;
}
}elseif ($offset !== null) {
$query .= ' LIMIT 18446744073709551615 OFFSET ' . $offset;
}

return $query;
}

/**
* {@inheritDoc}
*/
Expand Down
6 changes: 6 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/MySqlPlatformTest.php
Expand Up @@ -16,6 +16,12 @@ public function createPlatform()
return new MysqlPlatform;
}

public function testdoModifyLimitQuery()
{
$sql=$this->_platform->doModifyLimitQuery('SELECT n FROM Foo', null , 10);
$this->assertEquals('SELECT n FROM Foo LIMIT 18446744073709551615 OFFSET 10',$sql);
}

public function testGenerateMixedCaseTableCreate()
{
$table = new Table("Foo");
Expand Down