diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index 48be1bb698e..c7616911e7b 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -20,7 +20,6 @@ use function count; use function explode; use function implode; -use function preg_match; use function sprintf; use function str_contains; use function strlen; @@ -859,30 +858,12 @@ public function supportsCommentOnStatement(): bool protected function doModifyLimitQuery(string $query, ?int $limit, int $offset): string { - if ($limit === null && $offset <= 0) { - return $query; + if ($offset > 0) { + $query .= sprintf(' OFFSET %d ROWS', $offset); } - if (preg_match('/^\s*SELECT/i', $query) === 1) { - if (preg_match('/\sFROM\s/i', $query) === 0) { - $query .= ' FROM dual'; - } - - $columns = ['a.*']; - - if ($offset > 0) { - $columns[] = 'ROWNUM AS doctrine_rownum'; - } - - $query = sprintf('SELECT %s FROM (%s) a', implode(', ', $columns), $query); - - if ($limit !== null) { - $query .= sprintf(' WHERE ROWNUM <= %d', $offset + $limit); - } - - if ($offset > 0) { - $query = sprintf('SELECT * FROM (%s) WHERE doctrine_rownum >= %d', $query, $offset + 1); - } + if ($limit !== null) { + $query .= sprintf(' FETCH NEXT %d ROWS ONLY', $limit); } return $query; diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index eecec36bb0d..6228db6114c 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -201,54 +201,6 @@ public static function getReturnsForeignKeyReferentialActionSQL(): iterable ]; } - public function testModifyLimitQuery(): void - { - $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0); - self::assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql); - } - - public function testModifyLimitQueryWithEmptyOffset(): void - { - $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10); - self::assertEquals('SELECT a.* FROM (SELECT * FROM user) a WHERE ROWNUM <= 10', $sql); - } - - public function testModifyLimitQueryWithNonEmptyOffset(): void - { - $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 10); - - self::assertEquals( - 'SELECT * FROM (' - . 'SELECT a.*, ROWNUM AS doctrine_rownum FROM (SELECT * FROM user) a WHERE ROWNUM <= 20' - . ') WHERE doctrine_rownum >= 11', - $sql - ); - } - - public function testModifyLimitQueryWithEmptyLimit(): void - { - $sql = $this->platform->modifyLimitQuery('SELECT * FROM user', null, 10); - - self::assertEquals( - 'SELECT * FROM (' - . 'SELECT a.*, ROWNUM AS doctrine_rownum FROM (SELECT * FROM user) a' - . ') WHERE doctrine_rownum >= 11', - $sql - ); - } - - public function testModifyLimitQueryWithAscOrderBy(): void - { - $sql = $this->platform->modifyLimitQuery('SELECT * FROM user ORDER BY username ASC', 10); - self::assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username ASC) a WHERE ROWNUM <= 10', $sql); - } - - public function testModifyLimitQueryWithDescOrderBy(): void - { - $sql = $this->platform->modifyLimitQuery('SELECT * FROM user ORDER BY username DESC', 10); - self::assertEquals('SELECT a.* FROM (SELECT * FROM user ORDER BY username DESC) a WHERE ROWNUM <= 10', $sql); - } - public function testGenerateTableWithAutoincrement(): void { $columnName = strtoupper('id' . uniqid());