Skip to content

Commit

Permalink
Merge branch '2.11.x' into 3.0.x
Browse files Browse the repository at this point in the history
  • Loading branch information
morozov committed Jun 28, 2020
2 parents 37531f9 + 831e6fe commit a77c007
Show file tree
Hide file tree
Showing 32 changed files with 246 additions and 78 deletions.
29 changes: 28 additions & 1 deletion UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,33 @@ Please use other database client applications for import, e.g.:

# Upgrade to 2.11

##`ServerInfoAwareConnection::requiresQueryForServerVersion()` is deprecated.

The `ServerInfoAwareConnection::requiresQueryForServerVersion()` method has been deprecated as an implementation detail which is the same for almost all supported drivers.

## Statement constructors are marked internal

The driver and wrapper statement objects can be only created by the corresponding connection objects.

## The `PingableConnection` interface is deprecated

The wrapper connection will automatically handle the lost connection if the driver supports reporting it.

## The `ExceptionConverterDriver` interface is deprecated

All drivers will have to implement the exception conversion API.

## `DriverException::getErrorCode()` is deprecated

The `DriverException::getErrorCode()` is deprecated as redundant and inconsistently supported by drivers. Use `::getCode()` or `::getSQLState()` instead.

## Non-interface driver methods have been marked internal

The non-interface methods of driver-level classes have been marked internal:

- `OCI8Connection::getExecuteMode()`
- `OCI8Statement::convertPositionalToNamedPlaceholders()`

## Inconsistently and ambiguously named driver-level classes are deprecated

The following classes under the `Driver` namespace have been deprecated in favor of their consistently named counterparts:
Expand Down Expand Up @@ -282,7 +309,7 @@ Consumers of the Connection class should not rely on connection parameters store
- The usage of `Doctrine\DBAL\Driver::getDatabase()` is deprecated. Please use `Doctrine\DBAL\Connection::getDatabase()` instead.
- The behavior of the SQLite connection returning the database file path as the database is deprecated and shouldn't be relied upon.

## Deprecated `Portability\Connection::PORTABILITY_{PLATFORM}` constants`
## Deprecated `Portability\Connection::PORTABILITY_{PLATFORM}` constants

The platform-specific portability mode flags are meant to be used only by the portability layer internally to optimize
the user-provided mode for the current database platform.
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
"doctrine/coding-standard": "^8.0",
"jetbrains/phpstorm-stubs": "^2019.1",
"nikic/php-parser": "^4.4",
"phpstan/phpstan": "^0.12.30",
"phpstan/phpstan": "^0.12.31",
"phpstan/phpstan-strict-rules": "^0.12.2",
"phpunit/phpunit": "^9.2",
"psalm/plugin-phpunit": "^0.10.0",
Expand Down
22 changes: 11 additions & 11 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,9 @@
<exclude-pattern>src/Driver/SQLSrv/Result.php</exclude-pattern>
</rule>

<!-- See https://github.com/slevomat/coding-standard/issues/1038 -->
<!-- See https://github.com/slevomat/coding-standard/issues/770 -->
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<exclude-pattern>tests/Functional/Driver/IBMDB2/StatementTest.php</exclude-pattern>
<exclude-pattern>src/Driver/ExceptionConverterDriver.php</exclude-pattern>
</rule>

<!-- see https://github.com/doctrine/dbal/issues/3377 -->
Expand Down
9 changes: 4 additions & 5 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ parameters:
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false
earlyTerminatingMethodCalls:
Doctrine\DBAL\Connection:
- handleDriverException
- handleExceptionDuringQuery
ignoreErrors:
# removing it would be BC break
- '~^Constructor of class Doctrine\\DBAL\\Schema\\Table has an unused parameter \$idGeneratorType\.\z~'
Expand All @@ -31,11 +35,6 @@ parameters:
# weird class name, represented in stubs as OCI_(Lob|Collection)
- '~unknown class OCI-(Lob|Collection)~'

# https://github.com/phpstan/phpstan-src/pull/255
-
message: '~^Strict comparison using === between true and null will always evaluate to false\.$~'
path: %currentWorkingDirectory%/src/Driver/Mysqli/Result.php

# https://github.com/phpstan/phpstan/issues/3132
-
message: '~^Call to function in_array\(\) with arguments Doctrine\\DBAL\\Schema\\Column, array<string> and true will always evaluate to false\.$~'
Expand Down
96 changes: 77 additions & 19 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
Expand Down Expand Up @@ -468,7 +469,7 @@ public function fetchAssociative(string $query, array $params = [], array $types
try {
return $this->executeQuery($query, $params, $types)->fetchAssociative();
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
$this->handleExceptionDuringQuery($e, $query, $params, $types);
}
}

Expand All @@ -489,7 +490,7 @@ public function fetchNumeric(string $query, array $params = [], array $types = [
try {
return $this->executeQuery($query, $params, $types)->fetchNumeric();
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
$this->handleExceptionDuringQuery($e, $query, $params, $types);
}
}

Expand All @@ -510,7 +511,7 @@ public function fetchOne(string $query, array $params = [], array $types = [])
try {
return $this->executeQuery($query, $params, $types)->fetchOne();
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
$this->handleExceptionDuringQuery($e, $query, $params, $types);
}
}

Expand Down Expand Up @@ -772,7 +773,7 @@ public function fetchAllNumeric(string $query, array $params = [], array $types
try {
return $this->executeQuery($query, $params, $types)->fetchAllNumeric();
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
$this->handleExceptionDuringQuery($e, $query, $params, $types);
}
}

Expand All @@ -792,7 +793,7 @@ public function fetchAllAssociative(string $query, array $params = [], array $ty
try {
return $this->executeQuery($query, $params, $types)->fetchAllAssociative();
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
$this->handleExceptionDuringQuery($e, $query, $params, $types);
}
}

Expand All @@ -812,7 +813,7 @@ public function fetchFirstColumn(string $query, array $params = [], array $types
try {
return $this->executeQuery($query, $params, $types)->fetchFirstColumn();
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
$this->handleExceptionDuringQuery($e, $query, $params, $types);
}
}

Expand All @@ -836,7 +837,7 @@ public function iterateNumeric(string $query, array $params = [], array $types =
yield $row;
}
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
$this->handleExceptionDuringQuery($e, $query, $params, $types);
}
}

Expand All @@ -860,7 +861,7 @@ public function iterateAssociative(string $query, array $params = [], array $typ
yield $row;
}
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
$this->handleExceptionDuringQuery($e, $query, $params, $types);
}
}

Expand All @@ -884,7 +885,7 @@ public function iterateColumn(string $query, array $params = [], array $types =
yield $value;
}
} catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query);
$this->handleExceptionDuringQuery($e, $query, $params, $types);
}
}

Expand All @@ -901,8 +902,8 @@ public function prepare(string $sql): DriverStatement
{
try {
return new Statement($sql, $this);
} catch (Throwable $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $sql);
} catch (Throwable $e) {
$this->handleExceptionDuringQuery($e, $sql);
}
}

Expand Down Expand Up @@ -952,8 +953,8 @@ public function executeQuery(
}

return new Result($result, $this);
} catch (Throwable $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types));
} catch (Throwable $e) {
$this->handleExceptionDuringQuery($e, $query, $params, $types);
} finally {
if ($logger !== null) {
$logger->stopQuery();
Expand Down Expand Up @@ -1021,8 +1022,8 @@ public function query(string $sql): DriverResult

try {
return $connection->query($sql);
} catch (Throwable $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $sql);
} catch (Throwable $e) {
$this->handleExceptionDuringQuery($e, $sql);
} finally {
if ($logger !== null) {
$logger->stopQuery();
Expand Down Expand Up @@ -1069,8 +1070,8 @@ public function executeUpdate(string $query, array $params = [], array $types =
}

return $connection->exec($query);
} catch (Throwable $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types));
} catch (Throwable $e) {
$this->handleExceptionDuringQuery($e, $query, $params, $types);
} finally {
if ($logger !== null) {
$logger->stopQuery();
Expand All @@ -1089,8 +1090,8 @@ public function exec(string $statement): int

try {
return $connection->exec($statement);
} catch (Throwable $ex) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement);
} catch (Throwable $e) {
$this->handleExceptionDuringQuery($e, $statement);
} finally {
if ($logger !== null) {
$logger->stopQuery();
Expand Down Expand Up @@ -1640,6 +1641,8 @@ public function createQueryBuilder()
* It is responsibility of the developer to handle this case
* and abort the request or reconnect manually:
*
* @deprecated
*
* @return bool
*
* @example
Expand Down Expand Up @@ -1670,4 +1673,59 @@ public function ping()
return false;
}
}

/**
* @internal
*
* @param array<mixed> $params
* @param array<int|string|null> $types
*
* @throws DBALException
*
* @psalm-return never-return
*/
public function handleExceptionDuringQuery(Throwable $e, string $sql, array $params = [], array $types = []): void
{
$this->throw(
DBALException::driverExceptionDuringQuery(
$this->_driver,
$e,
$sql,
$this->resolveParams($params, $types)
)
);
}

/**
* @internal
*
* @throws DBALException
*
* @psalm-return never-return
*/
public function handleDriverException(Throwable $e): void
{
$this->throw(
DBALException::driverException(
$this->_driver,
$e
)
);
}

/**
* @internal
*
* @throws DBALException
*
* @psalm-return never-return
*/
private function throw(DBALException $e): void
{
if ($e instanceof ConnectionLost) {
$this->close();
}

throw $e;
}
}
12 changes: 12 additions & 0 deletions src/Driver/AbstractDB2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\DriverException as TheDriverException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager;

Expand All @@ -27,4 +29,14 @@ public function getSchemaManager(Connection $conn)
{
return new DB2SchemaManager($conn);
}

/**
* @param string $message
*
* @return DriverException
*/
public function convertException($message, TheDriverException $exception)
{
return new DriverException($message, $exception);
}
}
Loading

0 comments on commit a77c007

Please sign in to comment.