Skip to content

Commit 191938e

Browse files
committed
Enable establishing exclusive oci8 connections
1 parent 55ef7f8 commit 191938e

File tree

5 files changed

+54
-7
lines changed

5 files changed

+54
-7
lines changed

docs/en/reference/configuration.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,9 @@ pdo_oci / oci8
319319
parameters will no longer be used. Note that when using this parameter, the ``getHost``
320320
and ``getPort`` methods from ``Doctrine\DBAL\Connection`` will no longer function as expected.
321321
- ``persistent`` (boolean): Whether to establish a persistent connection.
322+
- ``driverOptions`` (array):
323+
- ``exclusive`` (boolean): Once specified for an ``oci8`` connection, forces the driver to always establish
324+
a new connection instead of reusing an existing one from the connection pool.
322325

323326
pdo_sqlsrv / sqlsrv
324327
^^^^^^^^^^^^^^^^^^^

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/Driver/OCI8/DriverTest.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,22 @@
44

55
use Doctrine\DBAL\Driver as DriverInterface;
66
use Doctrine\DBAL\Driver\OCI8\Driver;
7+
use Doctrine\DBAL\Driver\OCI8\Exception\InvalidConfiguration;
78
use Doctrine\DBAL\Tests\Driver\AbstractOracleDriverTestCase;
89

10+
/** @requires extension oci8 */
911
class DriverTest extends AbstractOracleDriverTestCase
1012
{
13+
public function testPersistentAndExclusiveAreMutuallyExclusive(): void
14+
{
15+
$this->expectException(InvalidConfiguration::class);
16+
17+
(new Driver())->connect([
18+
'persistent' => true,
19+
'driverOptions' => ['exclusive' => true],
20+
]);
21+
}
22+
1123
protected function createDriver(): DriverInterface
1224
{
1325
return new Driver();

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)