Skip to content

Commit

Permalink
Merge branch '3.8.x' into 4.0.x
Browse files Browse the repository at this point in the history
* 3.8.x:
  Add `QueryBuilder::resetOrderBy()` (#6190)
  Enable establishing exclusive oci8 connections (#6182)
  • Loading branch information
derrabus committed Oct 15, 2023
2 parents 9f24ecb + e8479d1 commit 5061ea5
Show file tree
Hide file tree
Showing 7 changed files with 78 additions and 7 deletions.
3 changes: 3 additions & 0 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,9 @@ pdo_oci / oci8
parameters will no longer be used. Note that when using this parameter, the ``getHost``
and ``getPort`` methods from ``Doctrine\DBAL\Connection`` will no longer function as expected.
- ``persistent`` (boolean): Whether to establish a persistent connection.
- ``driverOptions`` (array):
- ``exclusive`` (boolean): Once specified for an ``oci8`` connection, forces the driver to always establish
a new connection instead of reusing an existing one from the connection pool.

pdo_sqlsrv / sqlsrv
^^^^^^^^^^^^^^^^^^^
Expand Down
12 changes: 11 additions & 1 deletion src/Driver/OCI8/Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use Doctrine\DBAL\Driver\AbstractOracleDriver;
use Doctrine\DBAL\Driver\OCI8\Exception\ConnectionFailed;
use Doctrine\DBAL\Driver\OCI8\Exception\InvalidConfiguration;
use SensitiveParameter;

use function oci_connect;
Expand All @@ -32,8 +33,17 @@ public function connect(

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

if (! empty($params['persistent'])) {
$persistent = ! empty($params['persistent']);
$exclusive = ! empty($params['driverOptions']['exclusive']);

if ($persistent && $exclusive) {
throw InvalidConfiguration::forPersistentAndExclusive();
}

if ($persistent) {
$connection = @oci_pconnect($username, $password, $connectionString, $charset, $sessionMode);
} elseif ($exclusive) {
$connection = @oci_new_connect($username, $password, $connectionString, $charset, $sessionMode);
} else {
$connection = @oci_connect($username, $password, $connectionString, $charset, $sessionMode);
}
Expand Down
20 changes: 20 additions & 0 deletions src/Driver/OCI8/Exception/InvalidConfiguration.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Driver\OCI8\Exception;

use Doctrine\DBAL\Driver\AbstractException;

/**
* @internal
*
* @psalm-immutable
*/
final class InvalidConfiguration extends AbstractException
{
public static function forPersistentAndExclusive(): self
{
return new self('The "persistent" parameter and the "exclusive" driver option are mutually exclusive');
}
}
13 changes: 13 additions & 0 deletions src/Query/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1139,6 +1139,19 @@ public function addOrderBy(string $sort, ?string $order = null): self
return $this;
}

/**
* Resets the ordering for the query.
*
* @return $this This QueryBuilder instance.
*/
public function resetOrderBy(): self
{
$this->orderBy = [];
$this->sql = null;

Check failure on line 1150 in src/Query/QueryBuilder.php

View workflow job for this annotation

GitHub Actions / Coding Standards / Coding Standards (8.2)

Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space

return $this;
}

/** @throws QueryException */
private function getSQLForSelect(): string
{
Expand Down
12 changes: 12 additions & 0 deletions tests/Driver/OCI8/DriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,22 @@

use Doctrine\DBAL\Driver as DriverInterface;
use Doctrine\DBAL\Driver\OCI8\Driver;
use Doctrine\DBAL\Driver\OCI8\Exception\InvalidConfiguration;
use Doctrine\DBAL\Tests\Driver\AbstractOracleDriverTestCase;

/** @requires extension oci8 */
class DriverTest extends AbstractOracleDriverTestCase
{
public function testPersistentAndExclusiveAreMutuallyExclusive(): void
{
$this->expectException(InvalidConfiguration::class);

(new Driver())->connect([
'persistent' => true,
'driverOptions' => ['exclusive' => true],
]);
}

protected function createDriver(): DriverInterface
{
return new Driver();
Expand Down
14 changes: 8 additions & 6 deletions tests/Functional/LockMode/NoneTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Doctrine\DBAL\Tests\Functional\LockMode;

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\LockMode;
use Doctrine\DBAL\Platforms\SQLitePlatform;
Expand All @@ -21,11 +22,6 @@ class NoneTest extends FunctionalTestCase

public function setUp(): void
{
if (TestUtil::isDriverOneOf('oci8')) {
// https://github.com/doctrine/dbal/issues/4417
self::markTestSkipped('This test fails on OCI8 for a currently unknown reason');
}

if ($this->connection->getDatabasePlatform() instanceof SQLServerPlatform) {
// Use row versioning instead of locking on SQL Server (if we don't, the second connection will block when
// attempting to read the row created by the first connection, instead of reading the previous version);
Expand All @@ -43,7 +39,13 @@ public function setUp(): void

$this->dropAndCreateTable($table);

$this->connection2 = TestUtil::getConnection();
$params = TestUtil::getConnectionParams();

if (TestUtil::isDriverOneOf('oci8')) {
$params['driverOptions']['exclusive'] = true;
}

$this->connection2 = DriverManager::getConnection($params);

if ($this->connection2->createSchemaManager()->tableExists('users')) {
return;
Expand Down
11 changes: 11 additions & 0 deletions tests/Query/QueryBuilderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,17 @@ public function testSetFirstResult(): void
self::assertEquals(10, $qb->getFirstResult());
}

public function testResetOrderBy(): void
{
$qb = new QueryBuilder($this->conn);

$qb->select('u.*')->from('users', 'u')->orderBy('u.name', 'ASC');

self::assertEquals('SELECT u.* FROM users u ORDER BY u.name ASC', (string) $qb);
$qb->resetOrderBy();
self::assertEquals('SELECT u.* FROM users u', (string) $qb);
}

public function testCreateNamedParameter(): void
{
$qb = new QueryBuilder($this->conn);
Expand Down

0 comments on commit 5061ea5

Please sign in to comment.