Unverified Commit 9a2be238 authored by Steve Müller's avatar Steve Müller Committed by Sergei Morozov

fix query limit values "0" and "null" on SQL Anywhere

parent 9d382e69
......@@ -1308,25 +1308,20 @@ SQL
*/
protected function doModifyLimitQuery($query, $limit, $offset)
{
$limitOffsetClause = '';
$limitOffsetClause = $this->getTopClauseSQL($limit, $offset);
if ($limit > 0) {
$limitOffsetClause = 'TOP ' . $limit . ' ';
return $limitOffsetClause === ''
? $query
: preg_replace('/^\s*(SELECT\s+(DISTINCT\s+)?)/i', '\1' . $limitOffsetClause . ' ', $query);
}
private function getTopClauseSQL(?int $limit, ?int $offset) : string
{
if ($offset > 0) {
if ($limit === 0) {
$limitOffsetClause = 'TOP ALL ';
}
$limitOffsetClause .= 'START AT ' . ($offset + 1) . ' ';
return sprintf('TOP %s START AT %d', $limit ?? 'ALL', $offset + 1);
}
if ($limitOffsetClause) {
return preg_replace('/^\s*(SELECT\s+(DISTINCT\s+)?)/i', '\1' . $limitOffsetClause, $query);
}
return $query;
return $limit === null ? '' : 'TOP ' . $limit;
}
/**
......
......@@ -646,7 +646,7 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
$this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5)
);
self::assertEquals(
'SELECT TOP ALL START AT 6 * FROM user',
'SELECT TOP 0 START AT 6 * FROM user',
$this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5)
);
}
......@@ -659,6 +659,14 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
);
}
public function testModifiesLimitQueryWithoutLimit()
{
self::assertEquals(
'SELECT TOP ALL START AT 11 n FROM Foo',
$this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10)
);
}
public function testPrefersIdentityColumns()
{
self::assertTrue($this->platform->prefersIdentityColumns());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment