Skip to content

Commit

Permalink
Merge branch '3.7.x' into 4.0.x
Browse files Browse the repository at this point in the history
* 3.7.x:
  Update database list and vendors
  Trigger runtime deprecations for legacy API
  Update Docker image location for IBM DB2
  Leverage "shivammathur/setup-php" action for "ibm_db2" extension install
  Add MariaDB1052Platform
  Add 3.7.x branch
  [SCA] Restrict the possible values for the casing options under the `Portability\` NS
  Ensure the pg_depend relation is for a table object.
  • Loading branch information
derrabus committed Mar 6, 2023
2 parents 6cc39f0 + f4ba78c commit 3b68634
Show file tree
Hide file tree
Showing 20 changed files with 333 additions and 62 deletions.
6 changes: 6 additions & 0 deletions .doctrine-project.json
Expand Up @@ -11,6 +11,12 @@
"slug": "latest",
"upcoming": true
},
{
"name": "3.7",
"branchName": "3.7.x",
"slug": "3.7",
"upcoming": true
},
{
"name": "3.6",
"branchName": "3.6.x",
Expand Down
19 changes: 13 additions & 6 deletions .github/workflows/continuous-integration.yml
Expand Up @@ -484,7 +484,7 @@ jobs:

services:
ibm_db2:
image: "ibmcom/db2:11.5.0.0"
image: "icr.io/db2_community/db2:11.5.8.0"
env:
DB2INST1_PASSWORD: "Doctrine2018"
LICENSE: "accept"
Expand All @@ -500,22 +500,29 @@ jobs:
run: "docker logs -f ${{ job.services.ibm_db2.id }} | sed '/(*) Setup has completed./ q'"

- name: "Create temporary tablespace"
run: "docker exec ${{ job.services.ibm_db2.id }} su - db2inst1 -c 'db2 CONNECT TO doctrine && db2 CREATE USER TEMPORARY TABLESPACE doctrine_tbsp PAGESIZE 4 K'"
run: "docker exec ${{ job.services.ibm_db2.id }} su - db2inst1 -c 'db2 -t CONNECT TO doctrine; db2 -t CREATE USER TEMPORARY TABLESPACE doctrine_tbsp PAGESIZE 4 K;'"

- name: "Checkout"
uses: "actions/checkout@v3"
with:
fetch-depth: 2

- name: "Install IBM DB2 CLI driver"
working-directory: /tmp
run: |
wget https://public.dhe.ibm.com/ibmdl/export/pub/software/data/db2/drivers/odbc_cli/linuxx64_odbc_cli.tar.gz
tar xf linuxx64_odbc_cli.tar.gz
rm linuxx64_odbc_cli.tar.gz
- name: "Install PHP"
uses: "shivammathur/setup-php@v2"
with:
php-version: "${{ matrix.php-version }}"
extensions: "ibm_db2"
coverage: "pcov"
ini-values: "zend.assertions=1, extension=ibm_db2.so, ibm_db2.instance_name=db2inst1"

- name: "Install ibm_db2 extension"
run: "ci/github/ext/install-ibm_db2.sh ${{ matrix.php-version }}"
ini-values: "zend.assertions=1, ibm_db2.instance_name=db2inst1"
env:
IBM_DB2_CONFIGURE_OPTS: "--with-IBM_DB2=/tmp/clidriver"

- name: "Install dependencies with Composer"
uses: "ramsey/composer-install@v2"
Expand Down
21 changes: 0 additions & 21 deletions ci/github/ext/install-ibm_db2.sh

This file was deleted.

6 changes: 4 additions & 2 deletions docs/en/reference/introduction.rst
Expand Up @@ -13,10 +13,12 @@ the oci8 extension under the hood.

The following database vendors are currently supported:

- MySQL
- DB2 (IBM)
- MariaDB
- MySQL (Oracle)
- Oracle
- Microsoft SQL Server
- PostgreSQL
- SQL Server (Microsoft)
- SQLite

The Doctrine DBAL can be used independently of the
Expand Down
4 changes: 4 additions & 0 deletions phpstan.neon.dist
Expand Up @@ -63,6 +63,10 @@ parameters:
message: '~^Parameter #1 \$driverOptions of method Doctrine\\DBAL\\Tests\\Functional\\Driver\\Mysqli\\ConnectionTest\:\:getConnection\(\) expects array<string, mixed>, .* given\.$~'
path: tests/Functional/Driver/Mysqli/ConnectionTest.php

-
message: '~^Parameter #1 \$mode of method Doctrine\\DBAL\\Result\:\:fetch(?:All)?\(\) expects 2\|3\|7, 1 given\.$~'
path: tests/Functional/LegacyAPITest.php

# DriverManagerTest::testDatabaseUrl() should be refactored as it's too dynamic.
-
message: '~^Offset string does not exist on array{.+}\.$~'
Expand Down
10 changes: 10 additions & 0 deletions psalm.xml.dist
Expand Up @@ -31,6 +31,14 @@
<file name="src/Driver/OCI8/ConvertPositionalToNamedPlaceholders.php"/>
</errorLevel>
</ConflictingReferenceConstraint>
<DeprecatedClass>
<errorLevel type="suppress">
<!--
TODO: remove in 4.0.0
-->
<referencedClass name="Doctrine\DBAL\FetchMode"/>
</errorLevel>
</DeprecatedClass>
<DeprecatedMethod>
<errorLevel type="suppress">
<!--
Expand Down Expand Up @@ -95,6 +103,7 @@
<errorLevel type="suppress">
<!-- We're testing with invalid input here. -->
<file name="tests/Functional/Driver/Mysqli/ConnectionTest.php"/>
<file name="tests/Functional/LegacyAPITest.php"/>
<file name="tests/Platforms/AbstractPlatformTestCase.php"/>
</errorLevel>
</InvalidArgument>
Expand Down Expand Up @@ -173,6 +182,7 @@

<!-- We're checking for invalid input. -->
<directory name="src/Driver/PgSQL"/>
<file name="src/Result.php"/>

<!-- We're testing invalid input. -->
<file name="tests/Types/DateImmutableTypeTest.php"/>
Expand Down
18 changes: 16 additions & 2 deletions src/Connection.php
Expand Up @@ -1383,22 +1383,36 @@ public function executeUpdate(string $sql, array $params = [], array $types = []
/**
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated This API is deprecated and will be removed after 2022
* @deprecated Use {@see executeQuery()} instead
*/
public function query(string $sql): Result
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4163',
'%s is deprecated, please use executeQuery() instead.',
__METHOD__,
);

return $this->executeQuery($sql);
}

/**
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated This API is deprecated and will be removed after 2022
* @deprecated please use {@see executeStatement()} instead
*
* @return int|numeric-string
*/
public function exec(string $sql): int|string
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4163',
'%s is deprecated, please use executeStatement() instead.',
__METHOD__,
);

return $this->executeStatement($sql);
}
}
38 changes: 35 additions & 3 deletions src/Driver/AbstractMySQLDriver.php
Expand Up @@ -6,13 +6,15 @@

use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\API\MySQL\ExceptionConverter;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractMySQLPlatform;
use Doctrine\DBAL\Platforms\Exception\InvalidPlatformVersion;
use Doctrine\DBAL\Platforms\MariaDB1052Platform;
use Doctrine\DBAL\Platforms\MariaDBPlatform;
use Doctrine\DBAL\Platforms\MySQL80Platform;
use Doctrine\DBAL\Platforms\MySQLPlatform;
use Doctrine\DBAL\ServerVersionProvider;

use function preg_match;
use function stripos;
use function version_compare;

Expand All @@ -24,12 +26,16 @@ abstract class AbstractMySQLDriver implements Driver
/**
* {@inheritdoc}
*
* @throws Exception
* @throws InvalidPlatformVersion
*/
public function getDatabasePlatform(ServerVersionProvider $versionProvider): AbstractMySQLPlatform
{
$version = $versionProvider->getServerVersion();
if (stripos($version, 'MariaDB') !== false) {
if (stripos($version, 'mariadb') !== false) {
if (version_compare($this->getMariaDbMysqlVersionNumber($version), '10.5.2', '>=')) {
return new MariaDB1052Platform();
}

return new MariaDBPlatform();
}

Expand All @@ -44,4 +50,30 @@ public function getExceptionConverter(): ExceptionConverter
{
return new ExceptionConverter();
}

/**
* Detect MariaDB server version, including hack for some mariadb distributions
* that starts with the prefix '5.5.5-'
*
* @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial'
*
* @throws InvalidPlatformVersion
*/
private function getMariaDbMysqlVersionNumber(string $versionString): string
{
if (
preg_match(
'/^(?:5\.5\.5-)?(mariadb-)?(?P<major>\d+)\.(?P<minor>\d+)\.(?P<patch>\d+)/i',
$versionString,
$versionParts,
) === 0
) {
throw InvalidPlatformVersion::new(
$versionString,
'^(?:5\.5\.5-)?(mariadb-)?<major_version>.<minor_version>.<patch_version>',
);
}

return $versionParts['major'] . '.' . $versionParts['minor'] . '.' . $versionParts['patch'];
}
}
2 changes: 2 additions & 0 deletions src/FetchMode.php
Expand Up @@ -6,6 +6,8 @@

/**
* Legacy Class that keeps BC for using the legacy APIs fetch()/fetchAll().
*
* @deprecated Use the dedicated fetch*() methods for the desired fetch mode instead.
*/
class FetchMode
{
Expand Down
40 changes: 40 additions & 0 deletions src/Platforms/MariaDB1052Platform.php
@@ -0,0 +1,40 @@
<?php

declare(strict_types=1);

namespace Doctrine\DBAL\Platforms;

use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\TableDiff;

/**
* Provides the behavior, features and SQL dialect of the MariaDB 10.5 (10.5.2 GA) database platform.
*
* Note: Should not be used with versions prior to 10.5.2.
*/
class MariaDB1052Platform extends MariaDBPlatform
{
/**
* {@inheritdoc}
*/
protected function getPreAlterTableRenameIndexForeignKeySQL(TableDiff $diff): array
{
return AbstractMySQLPlatform::getPreAlterTableRenameIndexForeignKeySQL($diff);
}

/**
* {@inheritdoc}
*/
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff): array
{
return AbstractMySQLPlatform::getPostAlterTableIndexForeignKeySQL($diff);
}

/**
* {@inheritdoc}
*/
protected function getRenameIndexSQL(string $oldIndexName, Index $index, $tableName): array
{
return ['ALTER TABLE ' . $tableName . ' RENAME INDEX ' . $oldIndexName . ' TO ' . $index->getQuotedName($this)];
}
}
20 changes: 14 additions & 6 deletions src/Portability/Converter.php
Expand Up @@ -12,8 +12,14 @@
use function is_string;
use function rtrim;

use const CASE_LOWER;
use const CASE_UPPER;

final class Converter
{
public const CASE_LOWER = CASE_LOWER;
public const CASE_UPPER = CASE_UPPER;

private readonly Closure $convertNumeric;
private readonly Closure $convertAssociative;
private readonly Closure $convertOne;
Expand All @@ -22,10 +28,12 @@ final class Converter
private readonly Closure $convertFirstColumn;

/**
* @param bool $convertEmptyStringToNull Whether each empty string should be converted to NULL
* @param bool $rightTrimString Whether each string should right-trimmed
* @param int|null $case Convert the case of the column names
* (one of {@see CASE_LOWER} and {@see CASE_UPPER})
* @param bool $convertEmptyStringToNull Whether each empty string should
* be converted to NULL
* @param bool $rightTrimString Whether each string should right-trimmed
* @param self::CASE_LOWER|self::CASE_UPPER|null $case Convert the case of the column names
* (one of {@see self::CASE_LOWER} and
* {@see self::CASE_UPPER})
*/
public function __construct(bool $convertEmptyStringToNull, bool $rightTrimString, ?int $case)
{
Expand Down Expand Up @@ -168,8 +176,8 @@ private function createConvertValue(bool $convertEmptyStringToNull, bool $rightT
/**
* Creates a function that will convert each array-row retrieved from the database
*
* @param Closure|null $function The function that will convert each value
* @param int|null $case Column name case
* @param Closure|null $function The function that will convert each value
* @param self::CASE_LOWER|self::CASE_UPPER|null $case Column name case
*
* @return Closure|null The resulting function or NULL if no conversion is needed
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Portability/OptimizeFlags.php
Expand Up @@ -17,7 +17,7 @@ final class OptimizeFlags
* Platform-specific portability flags that need to be excluded from the user-provided mode
* since the platform already operates in this mode to avoid unnecessary conversion overhead.
*
* @var array<string,int>
* @var array<class-string, int>
*/
private static array $platforms = [
DB2Platform::class => 0,
Expand Down
23 changes: 21 additions & 2 deletions src/Result.php
Expand Up @@ -7,6 +7,7 @@
use Doctrine\DBAL\Driver\Exception as DriverException;
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Exception\NoKeyValue;
use Doctrine\Deprecations\Deprecation;
use LogicException;
use Traversable;

Expand Down Expand Up @@ -266,12 +267,21 @@ private function ensureHasKeyValue(): void
/**
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated This API is deprecated and will be removed after 2022
* @deprecated Use {@see fetchNumeric()}, {@see fetchAssociative()} or {@see fetchOne()} instead.
*
* @psalm-param FetchMode::* $mode
*
* @throws Exception
*/
public function fetch(int $mode = FetchMode::ASSOCIATIVE): mixed
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4007',
'%s is deprecated, please use fetchNumeric(), fetchAssociative() or fetchOne() instead.',
__METHOD__,
);

if (func_num_args() > 1) {
throw new LogicException('Only invocations with one argument are still supported by this legacy API.');
}
Expand All @@ -294,14 +304,23 @@ public function fetch(int $mode = FetchMode::ASSOCIATIVE): mixed
/**
* BC layer for a wide-spread use-case of old DBAL APIs
*
* @deprecated This API is deprecated and will be removed after 2022
* @deprecated Use {@see fetchAllNumeric()}, {@see fetchAllAssociative()} or {@see fetchFirstColumn()} instead.
*
* @psalm-param FetchMode::* $mode
*
* @return list<mixed>
*
* @throws Exception
*/
public function fetchAll(int $mode = FetchMode::ASSOCIATIVE): array
{
Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/4007',
'%s is deprecated, please use fetchAllNumeric(), fetchAllAssociative() or fetchFirstColumn() instead.',
__METHOD__,
);

if (func_num_args() > 1) {
throw new LogicException('Only invocations with one argument are still supported by this legacy API.');
}
Expand Down

0 comments on commit 3b68634

Please sign in to comment.