diff --git a/lib/Doctrine/ORM/Query/Exec/FinalizedSelectExecutor.php b/lib/Doctrine/ORM/Query/Exec/FinalizedSelectExecutor.php new file mode 100644 index 00000000000..b777b3d68cc --- /dev/null +++ b/lib/Doctrine/ORM/Query/Exec/FinalizedSelectExecutor.php @@ -0,0 +1,26 @@ +sqlStatements = $sql; + } + + public function execute(Connection $conn, array $params, array $types): Result + { + return $conn->executeQuery($this->getSqlStatements(), $params, $types, $this->queryCacheProfile); + } +} diff --git a/lib/Doctrine/ORM/Query/Exec/SingleSelectSqlFinalizer.php b/lib/Doctrine/ORM/Query/Exec/SingleSelectSqlFinalizer.php new file mode 100644 index 00000000000..1420bf39c1a --- /dev/null +++ b/lib/Doctrine/ORM/Query/Exec/SingleSelectSqlFinalizer.php @@ -0,0 +1,60 @@ +sql = $sql; + } + + /** + * @internal + * + * @psalm-internal Doctrine\ORM + * + * This method exists temporarily to support old SqlWalker interfaces. + */ + public function finalizeSql(Query $query): string + { + $platform = $query->getEntityManager()->getConnection()->getDatabasePlatform(); + + $sql = $platform->modifyLimitQuery($this->sql, $query->getMaxResults(), $query->getFirstResult()); + + $lockMode = $query->getHint(Query::HINT_LOCK_MODE) ?: LockMode::NONE; + + if ($lockMode !== LockMode::NONE && $lockMode !== LockMode::OPTIMISTIC && $lockMode !== LockMode::PESSIMISTIC_READ && $lockMode !== LockMode::PESSIMISTIC_WRITE) { + throw QueryException::invalidLockMode(); + } + + if ($lockMode === LockMode::PESSIMISTIC_READ) { + $sql .= ' ' . $platform->getReadLockSQL(); + } elseif ($lockMode === LockMode::PESSIMISTIC_WRITE) { + $sql .= ' ' . $platform->getWriteLockSQL(); + } + + return $sql; + } + + public function createExecutor(Query $query): AbstractSqlExecutor + { + return new FinalizedSelectExecutor($this->finalizeSql($query)); + } +}