Skip to content

Commit 792b79d

Browse files
committed
Merge branch '3.8.x' into 4.0.x
* 3.8.x: Add `QueryBuilder::resetOrderBy()` (doctrine#6190) Enable establishing exclusive oci8 connections (doctrine#6182)
2 parents 9f24ecb + e8479d1 commit 792b79d

File tree

7 files changed

+78
-7
lines changed

7 files changed

+78
-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
@@ -6,6 +6,7 @@
66

77
use Doctrine\DBAL\Driver\AbstractOracleDriver;
88
use Doctrine\DBAL\Driver\OCI8\Exception\ConnectionFailed;
9+
use Doctrine\DBAL\Driver\OCI8\Exception\InvalidConfiguration;
910
use SensitiveParameter;
1011

1112
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+
}

src/Query/QueryBuilder.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1139,6 +1139,19 @@ public function addOrderBy(string $sort, ?string $order = null): self
11391139
return $this;
11401140
}
11411141

1142+
/**
1143+
* Resets the ordering for the query.
1144+
*
1145+
* @return $this This QueryBuilder instance.
1146+
*/
1147+
public function resetOrderBy(): self
1148+
{
1149+
$this->orderBy = [];
1150+
$this->sql = null;
1151+
1152+
return $this;
1153+
}
1154+
11421155
/** @throws QueryException */
11431156
private function getSQLForSelect(): string
11441157
{

tests/Driver/OCI8/DriverTest.php

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

77
use Doctrine\DBAL\Driver as DriverInterface;
88
use Doctrine\DBAL\Driver\OCI8\Driver;
9+
use Doctrine\DBAL\Driver\OCI8\Exception\InvalidConfiguration;
910
use Doctrine\DBAL\Tests\Driver\AbstractOracleDriverTestCase;
1011

12+
/** @requires extension oci8 */
1113
class DriverTest extends AbstractOracleDriverTestCase
1214
{
15+
public function testPersistentAndExclusiveAreMutuallyExclusive(): void
16+
{
17+
$this->expectException(InvalidConfiguration::class);
18+
19+
(new Driver())->connect([
20+
'persistent' => true,
21+
'driverOptions' => ['exclusive' => true],
22+
]);
23+
}
24+
1325
protected function createDriver(): DriverInterface
1426
{
1527
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->createSchemaManager()->tableExists('users')) {
4951
return;

tests/Query/QueryBuilderTest.php

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -503,6 +503,17 @@ public function testSetFirstResult(): void
503503
self::assertEquals(10, $qb->getFirstResult());
504504
}
505505

506+
public function testResetOrderBy(): void
507+
{
508+
$qb = new QueryBuilder($this->conn);
509+
510+
$qb->select('u.*')->from('users', 'u')->orderBy('u.name', 'ASC');
511+
512+
self::assertEquals('SELECT u.* FROM users u ORDER BY u.name ASC', (string) $qb);
513+
$qb->resetOrderBy();
514+
self::assertEquals('SELECT u.* FROM users u', (string) $qb);
515+
}
516+
506517
public function testCreateNamedParameter(): void
507518
{
508519
$qb = new QueryBuilder($this->conn);

0 commit comments

Comments
 (0)