diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index 61496426f92..1d4578979a1 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/Platforms/OraclePlatform.php @@ -35,24 +35,6 @@ */ class OraclePlatform extends AbstractPlatform { - /** - * Returns the FOR UPDATE expression. - * - * @return string - */ - public function getForUpdateSQL() - { - return ''; - } - - /** - * Returns the SKIP LOCKED expression. - */ - public function getSkipLockedSQL(): string - { - return ''; - } - /** * Assertion for Oracle identifiers. * diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 5e3e897723a..7b870d5e5ea 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -1366,15 +1366,14 @@ private function getSQLForSelect(): string . ($this->sqlParts['where'] !== null ? ' WHERE ' . ((string) $this->sqlParts['where']) : '') . ($this->sqlParts['groupBy'] ? ' GROUP BY ' . implode(', ', $this->sqlParts['groupBy']) : '') . ($this->sqlParts['having'] !== null ? ' HAVING ' . ((string) $this->sqlParts['having']) : '') - . ($this->sqlParts['orderBy'] ? ' ORDER BY ' . implode(', ', $this->sqlParts['orderBy']) : '') - . ($platform->isLockLocatedAtTheEnd() ? $locksSql : ''); + . ($this->sqlParts['orderBy'] ? ' ORDER BY ' . implode(', ', $this->sqlParts['orderBy']) : ''); if ($this->isLimitQuery()) { - return $platform->modifyLimitQuery( - $query, - $this->maxResults, - $this->firstResult, - ); + $query = $platform->modifyLimitQuery($query, $this->maxResults, $this->firstResult); + } + + if ($platform->isLockLocatedAtTheEnd()) { + $query .= $locksSql; } return $query; diff --git a/tests/Functional/Query/QueryBuilderTest.php b/tests/Functional/Query/QueryBuilderTest.php index a1eb0544204..d697786edd1 100644 --- a/tests/Functional/Query/QueryBuilderTest.php +++ b/tests/Functional/Query/QueryBuilderTest.php @@ -4,14 +4,12 @@ namespace Doctrine\DBAL\Tests\Functional\Query; -use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Platforms\DB2Platform; -use Doctrine\DBAL\Platforms\MariaDb1027Platform; -use Doctrine\DBAL\Platforms\MariaDb1043Platform; -use Doctrine\DBAL\Platforms\MariaDb1052Platform; -use Doctrine\DBAL\Platforms\MySQL57Platform; -use Doctrine\DBAL\Platforms\OraclePlatform; -use Doctrine\DBAL\Platforms\PostgreSQL94Platform; +use Doctrine\DBAL\Platforms\MariaDb1060Platform; +use Doctrine\DBAL\Platforms\MariaDBPlatform; +use Doctrine\DBAL\Platforms\MySQL80Platform; +use Doctrine\DBAL\Platforms\MySQLPlatform; +use Doctrine\DBAL\Platforms\PostgreSQL100Platform; +use Doctrine\DBAL\Platforms\PostgreSQLPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Schema\Table; @@ -22,29 +20,27 @@ use Throwable; use function get_class; -use function sprintf; final class QueryBuilderTest extends FunctionalTestCase { - private function platformSupportsLocks(AbstractPlatform $platform): bool - { - return ! $platform instanceof DB2Platform - && ! $platform instanceof MariaDb1027Platform - && ! $platform instanceof MariaDb1043Platform - && ! $platform instanceof MariaDb1052Platform - && ! $platform instanceof MySQL57Platform - && ! $platform instanceof PostgreSQL94Platform - && ! $platform instanceof OraclePlatform - && ! $platform instanceof SqlitePlatform; - } - public function testConcurrentConnectionSkipsLockedRows(): void { $platform = $this->connection->getDatabasePlatform(); - if (! $this->platformSupportsLocks($platform)) { - self::markTestSkipped( - sprintf('Skipping, because platform %s does not support locks', get_class($platform)), - ); + + if ($platform instanceof MariaDBPlatform && ! $platform instanceof MariaDb1060Platform) { + self::markTestSkipped('Skipping on MariaDB older than 10.6'); + } + + if ($platform instanceof MySQLPlatform && ! $platform instanceof MySQL80Platform) { + self::markTestSkipped('Skipping on MySQL older than 8.0'); + } + + if ($platform instanceof PostgreSQLPlatform && ! $platform instanceof PostgreSQL100Platform) { + self::markTestSkipped('Skipping on PostgreSQL older than 10.0'); + } + + if ($platform instanceof SqlitePlatform) { + self::markTestSkipped('Skipping on SQLite'); } $tableName = 'users'; @@ -79,9 +75,7 @@ public function testConcurrentConnectionSkipsLockedRows(): void ); } - $resultList = $result->fetchAllAssociative(); - self::assertCount(1, $resultList); - self::assertEquals(1, $resultList[0]['id']); + self::assertEquals([1], $result->fetchFirstColumn()); $connection2 = TestUtil::getConnection(); self::assertTrue( @@ -99,19 +93,15 @@ public function testConcurrentConnectionSkipsLockedRows(): void ->skipLocked(); self::assertTrue($connection1->isTransactionActive(), 'A transaction should still be active on connection 1'); - $result = $connection2->executeQuery($qb2->getSQL()); - $resultList = $result->fetchAllAssociative(); - self::assertCount(1, $resultList); - self::assertEquals(2, $resultList[0]['id']); + $result = $connection2->executeQuery($qb2->getSQL()); + self::assertEquals([2], $result->fetchFirstColumn()); $connection1->commit(); self::assertFalse( $connection1->isTransactionActive(), 'A transaction should not be active anymore on connection 1', ); - $result = $connection2->executeQuery($qb2->getSQL()); - $resultList = $result->fetchAllAssociative(); - self::assertCount(1, $resultList); - self::assertEquals(1, $resultList[0]['id']); + $result = $connection2->executeQuery($qb2->getSQL()); + self::assertEquals([1], $result->fetchFirstColumn()); } }