Skip to content

Commit

Permalink
fix query limit values "0" and "null" on SQL Anywhere
Browse files Browse the repository at this point in the history
  • Loading branch information
deeky666 committed Dec 4, 2018
1 parent 777994b commit b581e4a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
12 changes: 5 additions & 7 deletions lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1310,16 +1310,14 @@ protected function doModifyLimitQuery($query, $limit, $offset)
{
$limitOffsetClause = '';

if ($limit > 0) {
if ($limit !== null) {
$limitOffsetClause = 'TOP ' . $limit . ' ';
}

if ($offset > 0) {
if ($limit === 0) {
$limitOffsetClause = 'TOP ALL ';
if ($offset > 0) {
$limitOffsetClause .= 'START AT ' . ($offset + 1) . ' ';
}

$limitOffsetClause .= 'START AT ' . ($offset + 1) . ' ';
} elseif ($offset > 0) {
$limitOffsetClause = 'TOP ALL START AT ' . ($offset + 1) . ' ';
}

if ($limitOffsetClause) {
Expand Down
10 changes: 9 additions & 1 deletion tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,7 +646,7 @@ public function testModifiesLimitQueryWithOffset()
$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)
);
}
Expand All @@ -659,6 +659,14 @@ public function testModifiesLimitQueryWithSubSelect()
);
}

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());
Expand Down

0 comments on commit b581e4a

Please sign in to comment.