Skip to content

Commit 720e718

Browse files
committed
Enable establishing exclusive oci8 connections
1 parent 55ef7f8 commit 720e718

File tree

3 files changed

+39
-7
lines changed

3 files changed

+39
-7
lines changed

src/Driver/OCI8/Driver.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Doctrine\DBAL\Driver\AbstractOracleDriver;
66
use Doctrine\DBAL\Driver\OCI8\Exception\ConnectionFailed;
7+
use Doctrine\DBAL\Driver\OCI8\Exception\InvalidConfiguration;
78
use SensitiveParameter;
89

910
use function oci_connect;
@@ -32,8 +33,17 @@ public function connect(
3233

3334
$connectionString = $this->getEasyConnectString($params);
3435

35-
if (! empty($params['persistent'])) {
36+
$persistent = ! empty($params['persistent']);
37+
$exclusive = ! empty($params['driverOptions']['exclusive']);
38+
39+
if ($persistent && $exclusive) {
40+
throw InvalidConfiguration::forPersistentAndExclusive();
41+
}
42+
43+
if ($persistent) {
3644
$connection = @oci_pconnect($username, $password, $connectionString, $charset, $sessionMode);
45+
} elseif ($exclusive) {
46+
$connection = @oci_new_connect($username, $password, $connectionString, $charset, $sessionMode);
3747
} else {
3848
$connection = @oci_connect($username, $password, $connectionString, $charset, $sessionMode);
3949
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Doctrine\DBAL\Driver\OCI8\Exception;
6+
7+
use Doctrine\DBAL\Driver\AbstractException;
8+
9+
/**
10+
* @internal
11+
*
12+
* @psalm-immutable
13+
*/
14+
final class InvalidConfiguration extends AbstractException
15+
{
16+
public static function forPersistentAndExclusive(): self
17+
{
18+
return new self('The "persistent" parameter and the "exclusive" driver option are mutually exclusive');
19+
}
20+
}

tests/Functional/LockMode/NoneTest.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
namespace Doctrine\DBAL\Tests\Functional\LockMode;
66

77
use Doctrine\DBAL\Connection;
8+
use Doctrine\DBAL\DriverManager;
89
use Doctrine\DBAL\Exception;
910
use Doctrine\DBAL\LockMode;
1011
use Doctrine\DBAL\Platforms\SqlitePlatform;
@@ -21,11 +22,6 @@ class NoneTest extends FunctionalTestCase
2122

2223
public function setUp(): void
2324
{
24-
if (TestUtil::isDriverOneOf('oci8')) {
25-
// https://github.com/doctrine/dbal/issues/4417
26-
self::markTestSkipped('This test fails on OCI8 for a currently unknown reason');
27-
}
28-
2925
if ($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
3026
// Use row versioning instead of locking on SQL Server (if we don't, the second connection will block when
3127
// attempting to read the row created by the first connection, instead of reading the previous version);
@@ -43,7 +39,13 @@ public function setUp(): void
4339

4440
$this->dropAndCreateTable($table);
4541

46-
$this->connection2 = TestUtil::getConnection();
42+
$params = TestUtil::getConnectionParams();
43+
44+
if (TestUtil::isDriverOneOf('oci8')) {
45+
$params['driverOptions']['exclusive'] = true;
46+
}
47+
48+
$this->connection2 = DriverManager::getConnection($params);
4749

4850
if ($this->connection2->getSchemaManager()->tablesExist('users')) {
4951
return;

0 commit comments

Comments
 (0)