Skip to content

Commit

Permalink
Merge pull request doctrine#6627 from doctrine/4.2.x
Browse files Browse the repository at this point in the history
Merge 4.2.x up into 4.3.x
  • Loading branch information
greg0ire authored Nov 24, 2024
2 parents 052545f + 3056f03 commit e9fb8d7
Show file tree
Hide file tree
Showing 12 changed files with 192 additions and 60 deletions.
85 changes: 32 additions & 53 deletions .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,8 @@ jobs:
os:
- "ubuntu-22.04"
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"
dependencies:
- "highest"
extension:
Expand Down Expand Up @@ -101,15 +99,15 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
oracle-version:
- "18"
- "21"
- "23"
include:
- php-version: "8.4"
- php-version: "8.1"
oracle-version: "23"
- php-version: "8.5"
oracle-version: "23"

services:
Expand Down Expand Up @@ -161,15 +159,15 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
oracle-version:
- "18"
- "21"
- "23"
include:
- php-version: "8.4"
- php-version: "8.1"
oracle-version: "23"
- php-version: "8.5"
oracle-version: "23"

services:
Expand Down Expand Up @@ -221,7 +219,7 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.4"
postgres-version:
- "10"
- "16"
Expand All @@ -230,16 +228,16 @@ jobs:
- "pgsql"
- "pdo_pgsql"
include:
- php-version: "8.2"
- php-version: "8.1"
postgres-version: "17"
extension: "pgsql"
- php-version: "8.3"
- php-version: "8.1"
postgres-version: "17"
extension: "pgsql"
- php-version: "8.4"
extension: "pdo_pgsql"
- php-version: "8.5"
postgres-version: "17"
extension: "pgsql"
- php-version: "8.4"
- php-version: "8.5"
postgres-version: "17"
extension: "pdo_pgsql"

Expand Down Expand Up @@ -291,31 +289,28 @@ jobs:
strategy:
matrix:
php-version:
- "8.1"
- "8.4"
mariadb-version:
# keep in sync with https://mariadb.org/about/#maintenance-policy
- "10.4" # Oldest version supported by DBAL, LTS (Jun 2024)
- "10.5" # LTS (Jun 2025)
- "10.6" # LTS (Jul 2026)
- "10.11" # LTS (Feb 2028)
- "11.1" # STS (Aug 2024)
- "11.2" # STS (Nov 2024)
- "11.3" # STS (Feb 2025)
- "10.4" # Oldest version supported by DBAL, LTS (Jun 2024) We have code specific to 10.4.3-10.5.2
- "10.5" # LTS (Jun 2025) We have code specific to 10.5.2-10.6.0
- "10.6" # LTS (Jul 2026) We have code specific to 10.6.0-10.10.0
- "10.11" # LTS (Feb 2028) We have code specific to ^10.10
- "11.4" # LTS (May 2029)
extension:
- "mysqli"
- "pdo_mysql"
include:
- php-version: "8.2"
- php-version: "8.1"
mariadb-version: "11.4"
extension: "mysqli"
- php-version: "8.3"
- php-version: "8.1"
mariadb-version: "11.4"
extension: "pdo_mysql"
- php-version: "8.4"
- php-version: "8.5"
mariadb-version: "11.4"
extension: "mysqli"
- php-version: "8.4"
- php-version: "8.5"
mariadb-version: "11.4"
extension: "pdo_mysql"

Expand Down Expand Up @@ -368,10 +363,10 @@ jobs:
strategy:
matrix:
php-version:
- "8.3"
- "8.4"
mysql-version:
- "5.7"
- "8.0"
- "8.0" # We have code specific to ^8.0
- "9.1"
extension:
- "mysqli"
Expand All @@ -381,29 +376,15 @@ jobs:
include:
- config-file-suffix: "-tls"
php-version: "8.1"
mysql-version: "8.0"
extension: "mysqli"
- php-version: "8.1"
mysql-version: "8.0"
mysql-version: "9.1"
extension: "mysqli"
- php-version: "8.1"
mysql-version: "8.0"
extension: "pdo_mysql"
# Workaround for https://bugs.mysql.com/114876
- php-version: "8.3"
mysql-version: "8.4"
mysql-version: "9.1"
extension: "mysqli"
custom-entrypoint: >-
--entrypoint sh mysql:8.4 -c "exec docker-entrypoint.sh mysqld --mysql-native-password=ON"
- php-version: "8.3"
mysql-version: "8.4"
extension: "pdo_mysql"
custom-entrypoint: >-
--entrypoint sh mysql:8.4 -c "exec docker-entrypoint.sh mysqld --mysql-native-password=ON"
- php-version: "8.4"
- php-version: "8.5"
mysql-version: "9.1"
extension: "mysqli"
- php-version: "8.4"
- php-version: "8.5"
mysql-version: "9.1"
extension: "pdo_mysql"

Expand Down Expand Up @@ -461,9 +442,8 @@ jobs:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"
extension:
- "sqlsrv"
- "pdo_sqlsrv"
Expand Down Expand Up @@ -529,9 +509,8 @@ jobs:
matrix:
php-version:
- "8.1"
- "8.2"
- "8.3"
- "8.4"
- "8.5"

services:
ibm_db2:
Expand Down
1 change: 1 addition & 0 deletions docs/en/reference/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -324,6 +324,7 @@ pdo_oci / oci8
- ``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.
- ``protocol`` (string): The protocol used to connect to Oracle (default TCP, Autonomous tends to be TCPS). See `docs.oracle.com/en/enterprise-manager/cloud-control/enterprise-manager-cloud-control/13.4/emsec/secured-communication-tcps-access-databases.html <https://docs.oracle.com/en/enterprise-manager/cloud-control/enterprise-manager-cloud-control/13.4/emsec/secured-communication-tcps-access-databases.html>`_.

pdo_sqlsrv / sqlsrv
^^^^^^^^^^^^^^^^^^^
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/AbstractOracleDriver/EasyConnectString.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static function fromConnectionParameters(array $params): self
return self::fromArray([
'DESCRIPTION' => [
'ADDRESS' => [
'PROTOCOL' => 'TCP',
'PROTOCOL' => $params['driverOptions']['protocol'] ?? 'TCP',
'HOST' => $params['host'],
'PORT' => $params['port'] ?? 1521,
],
Expand Down
12 changes: 9 additions & 3 deletions src/Driver/OCI8/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,21 @@ public function getServerVersion(): string
return $matches[1];
}

/** @throws Parser\Exception */
/**
* @throws Parser\Exception
* @throws Error
*/
public function prepare(string $sql): Statement
{
$visitor = new ConvertPositionalToNamedPlaceholders();

$this->parser->parse($sql, $visitor);

$statement = oci_parse($this->connection, $visitor->getSQL());
assert(is_resource($statement));
$statement = @oci_parse($this->connection, $visitor->getSQL());

if (! is_resource($statement)) {
throw Error::new($this->connection);
}

return new Statement($this->connection, $statement, $visitor->getParameterMap(), $this->executionMode);
}
Expand Down
3 changes: 1 addition & 2 deletions src/Driver/PDO/PDOConnect.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ private function doConnect(
string $password,
array $options,
): PDO {
// see https://github.com/php/php-src/issues/16314
if (PHP_VERSION_ID < 80400 || ($options[PDO::ATTR_PERSISTENT] ?? false) === true) {
if (PHP_VERSION_ID < 80400) {
return new PDO($dsn, $username, $password, $options);
}

Expand Down
7 changes: 6 additions & 1 deletion src/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
use function is_float;
use function is_int;
use function is_string;
use function key;
use function max;
use function mb_strlen;
use function preg_quote;
Expand Down Expand Up @@ -212,7 +213,11 @@ public function getEnumDeclarationSQL(array $column): string
throw ColumnValuesRequired::new($this, 'ENUM');
}

return $this->getStringTypeDeclarationSQL(['length' => max(...array_map(mb_strlen(...), $column['values']))]);
$length = count($column['values']) > 1
? max(...array_map(mb_strlen(...), $column['values']))
: mb_strlen($column['values'][key($column['values'])]);

return $this->getStringTypeDeclarationSQL(['length' => $length]);
}

/**
Expand Down
12 changes: 12 additions & 0 deletions tests/Driver/AbstractOracleDriver/EasyConnectStringTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,18 @@ public static function connectionParametersProvider(): iterable
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=41521))'
. '(CONNECT_DATA=(SID=XE)(INSTANCE_NAME=SALES)(SERVER=POOLED)))',
],
'tcps-params' => [
[
'host' => 'localhost',
'port' => 41521,
'dbname' => 'XE',
'instancename' => 'SALES',
'pooled' => true,
'driverOptions' => ['protocol' => 'TCPS'],
],
'(DESCRIPTION=(ADDRESS=(PROTOCOL=TCPS)(HOST=localhost)(PORT=41521))'
. '(CONNECT_DATA=(SID=XE)(INSTANCE_NAME=SALES)(SERVER=POOLED)))',
],
];
}
}
68 changes: 68 additions & 0 deletions tests/Functional/Driver/OCI8/ConnectionTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Tests\Functional\Driver\OCI8;

use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use Doctrine\DBAL\Tests\TestUtil;
use Throwable;

class ConnectionTest extends FunctionalTestCase
{
public static function setUpBeforeClass(): void
{
if (TestUtil::isDriverOneOf('oci8')) {
return;
}

self::markTestSkipped('This test requires the oci8 driver.');
}

public function testPrepareThrowsErrorOnConnectionLost(): void
{
$this->markConnectionNotReusable();
$this->killCurrentSession();

$this->expectException(DriverException::class);

$this->connection->prepare('SELECT * FROM 1');
}

/**
* Kill the current session, by using another connection
* Oracle doesn't allow you to terminate the current session, so we use a second connection
*/
private function killCurrentSession(): void
{
$row = $this->connection->fetchNumeric(
<<<'SQL'
SELECT SID, SERIAL#
FROM V$SESSION
WHERE AUDSID = USERENV('SESSIONID')
SQL,
);

self::assertNotFalse($row);
/** @psalm-suppress PossiblyUndefinedArrayOffset */
[$sid, $serialNumber] = $row;

self::assertNotNull($sid, 'SID is missing.');
self::assertNotNull($serialNumber, 'Serial number is missing.');

$params = TestUtil::getConnectionParams();
$params['driverOptions']['exclusive'] = true;
$secondConnection = DriverManager::getConnection($params);

$sessionParam = $this->connection->quote($sid . ', ' . $serialNumber);
$secondConnection->executeStatement('ALTER SYSTEM DISCONNECT SESSION ' . $sessionParam . ' IMMEDIATE');

// Ensure OCI driver is aware of connection state change by executing any statement
try {
$this->connection->executeStatement('INVALID SQL');
} catch (Throwable) {
}
}
}
9 changes: 9 additions & 0 deletions tests/Platforms/AbstractMySQLPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -696,4 +696,13 @@ protected function createComparator(): Comparator
new ComparatorConfig(),
);
}

/** @return array<string, array{array<string>, string}> */
public static function getEnumDeclarationSQLProvider(): array
{
return [
'single value' => [['foo'], "ENUM('foo')"],
'multiple values' => [['foo', 'bar1'], "ENUM('foo', 'bar1')"],
];
}
}
Loading

0 comments on commit e9fb8d7

Please sign in to comment.