From b581e4ade2d1fa5333bee7eef1d1f6fddb2f52a5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steve=20M=C3=BCller?= Date: Tue, 4 Dec 2018 10:04:27 +0100 Subject: [PATCH] fix query limit values "0" and "null" on SQL Anywhere --- lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php | 12 +++++------- .../Tests/DBAL/Platforms/SQLAnywherePlatformTest.php | 10 +++++++++- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index a8fbfeb46e4..bbe0bb0693e 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -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) { diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 294b9836e2e..219119c2cc1 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -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) ); } @@ -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());