Unverified Commit 60578e93 authored by Sergei Morozov's avatar Sergei Morozov

Merge branch 'bpo/2.9/#3378' into 2.9

parents 3534c6c9 9a2be238
...@@ -1308,25 +1308,20 @@ SQL ...@@ -1308,25 +1308,20 @@ SQL
*/ */
protected function doModifyLimitQuery($query, $limit, $offset) protected function doModifyLimitQuery($query, $limit, $offset)
{ {
$limitOffsetClause = ''; $limitOffsetClause = $this->getTopClauseSQL($limit, $offset);
if ($limit > 0) { return $limitOffsetClause === ''
$limitOffsetClause = 'TOP ' . $limit . ' '; ? $query
: preg_replace('/^\s*(SELECT\s+(DISTINCT\s+)?)/i', '\1' . $limitOffsetClause . ' ', $query);
} }
private function getTopClauseSQL(?int $limit, ?int $offset) : string
{
if ($offset > 0) { if ($offset > 0) {
if ($limit === 0) { return sprintf('TOP %s START AT %d', $limit ?? 'ALL', $offset + 1);
$limitOffsetClause = 'TOP ALL ';
}
$limitOffsetClause .= 'START AT ' . ($offset + 1) . ' ';
} }
if ($limitOffsetClause) { return $limit === null ? '' : 'TOP ' . $limit;
return preg_replace('/^\s*(SELECT\s+(DISTINCT\s+)?)/i', '\1' . $limitOffsetClause, $query);
}
return $query;
} }
/** /**
......
...@@ -646,7 +646,7 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -646,7 +646,7 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
$this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5) $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5)
); );
self::assertEquals( 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) $this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5)
); );
} }
...@@ -659,6 +659,14 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -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() public function testPrefersIdentityColumns()
{ {
self::assertTrue($this->platform->prefersIdentityColumns()); 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