Unverified Commit a77c0074 authored by Sergei Morozov's avatar Sergei Morozov

Merge branch '2.11.x' into 3.0.x

parents 37531f94 831e6fe0
...@@ -241,6 +241,33 @@ Please use other database client applications for import, e.g.: ...@@ -241,6 +241,33 @@ Please use other database client applications for import, e.g.:
# Upgrade to 2.11 # 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 ## 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: The following classes under the `Driver` namespace have been deprecated in favor of their consistently named counterparts:
...@@ -282,7 +309,7 @@ Consumers of the Connection class should not rely on connection parameters store ...@@ -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 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. - 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 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. the user-provided mode for the current database platform.
......
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
"This file is @generated automatically" "This file is @generated automatically"
], ],
"content-hash": "f61efbf7b6070380da835ef52ec3b8f0", "content-hash": "93f2611cd4d28a1389369449c8b5fa5f",
"packages": [ "packages": [
{ {
"name": "composer/package-versions-deprecated", "name": "composer/package-versions-deprecated",
...@@ -1358,16 +1358,16 @@ ...@@ -1358,16 +1358,16 @@
}, },
{ {
"name": "phpstan/phpstan", "name": "phpstan/phpstan",
"version": "0.12.30", "version": "0.12.31",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/phpstan/phpstan.git", "url": "https://github.com/phpstan/phpstan.git",
"reference": "1f2c16d3fbb5eec6e55fbe2358e32570cefa20e5" "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/phpstan/phpstan/zipball/1f2c16d3fbb5eec6e55fbe2358e32570cefa20e5", "url": "https://api.github.com/repos/phpstan/phpstan/zipball/776c8056b401e1b67f277b9e9fb334d1a274671d",
"reference": "1f2c16d3fbb5eec6e55fbe2358e32570cefa20e5", "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -1410,7 +1410,7 @@ ...@@ -1410,7 +1410,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-06-21T14:08:19+00:00" "time": "2020-06-24T20:55:29+00:00"
}, },
{ {
"name": "phpstan/phpstan-strict-rules", "name": "phpstan/phpstan-strict-rules",
...@@ -2741,16 +2741,16 @@ ...@@ -2741,16 +2741,16 @@
}, },
{ {
"name": "slevomat/coding-standard", "name": "slevomat/coding-standard",
"version": "6.3.8", "version": "6.3.10",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/slevomat/coding-standard.git", "url": "https://github.com/slevomat/coding-standard.git",
"reference": "500f55b5e2dee1dcef8e88f2038990acdba29f1c" "reference": "58fa5ea2c048357ae55185eb5e93ca2826fffde0"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/slevomat/coding-standard/zipball/500f55b5e2dee1dcef8e88f2038990acdba29f1c", "url": "https://api.github.com/repos/slevomat/coding-standard/zipball/58fa5ea2c048357ae55185eb5e93ca2826fffde0",
"reference": "500f55b5e2dee1dcef8e88f2038990acdba29f1c", "reference": "58fa5ea2c048357ae55185eb5e93ca2826fffde0",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
...@@ -2794,7 +2794,7 @@ ...@@ -2794,7 +2794,7 @@
"type": "tidelift" "type": "tidelift"
} }
], ],
"time": "2020-05-27T06:28:47+00:00" "time": "2020-06-22T11:33:09+00:00"
}, },
{ {
"name": "squizlabs/php_codesniffer", "name": "squizlabs/php_codesniffer",
......
...@@ -102,9 +102,9 @@ ...@@ -102,9 +102,9 @@
<exclude-pattern>src/Driver/SQLSrv/Result.php</exclude-pattern> <exclude-pattern>src/Driver/SQLSrv/Result.php</exclude-pattern>
</rule> </rule>
<!-- See https://github.com/slevomat/coding-standard/issues/1038 --> <!-- See https://github.com/slevomat/coding-standard/issues/770 -->
<rule ref="SlevomatCodingStandard.Namespaces.UnusedUses"> <rule ref="SlevomatCodingStandard.Namespaces.UnusedUses">
<exclude-pattern>tests/Functional/Driver/IBMDB2/StatementTest.php</exclude-pattern> <exclude-pattern>src/Driver/ExceptionConverterDriver.php</exclude-pattern>
</rule> </rule>
<!-- see https://github.com/doctrine/dbal/issues/3377 --> <!-- see https://github.com/doctrine/dbal/issues/3377 -->
......
...@@ -8,6 +8,10 @@ parameters: ...@@ -8,6 +8,10 @@ parameters:
reportUnmatchedIgnoredErrors: false reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false checkMissingIterableValueType: false
checkGenericClassInNonGenericObjectType: false checkGenericClassInNonGenericObjectType: false
earlyTerminatingMethodCalls:
Doctrine\DBAL\Connection:
- handleDriverException
- handleExceptionDuringQuery
ignoreErrors: ignoreErrors:
# removing it would be BC break # removing it would be BC break
- '~^Constructor of class Doctrine\\DBAL\\Schema\\Table has an unused parameter \$idGeneratorType\.\z~' - '~^Constructor of class Doctrine\\DBAL\\Schema\\Table has an unused parameter \$idGeneratorType\.\z~'
...@@ -31,11 +35,6 @@ parameters: ...@@ -31,11 +35,6 @@ parameters:
# weird class name, represented in stubs as OCI_(Lob|Collection) # weird class name, represented in stubs as OCI_(Lob|Collection)
- '~unknown class 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 # 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\.$~' message: '~^Call to function in_array\(\) with arguments Doctrine\\DBAL\\Schema\\Column, array<string> and true will always evaluate to false\.$~'
......
...@@ -15,6 +15,7 @@ use Doctrine\DBAL\Driver\PingableConnection; ...@@ -15,6 +15,7 @@ use Doctrine\DBAL\Driver\PingableConnection;
use Doctrine\DBAL\Driver\Result as DriverResult; use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Driver\Statement as DriverStatement;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Exception\InvalidArgumentException;
use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Query\Expression\ExpressionBuilder; use Doctrine\DBAL\Query\Expression\ExpressionBuilder;
...@@ -468,7 +469,7 @@ class Connection implements DriverConnection ...@@ -468,7 +469,7 @@ class Connection implements DriverConnection
try { try {
return $this->executeQuery($query, $params, $types)->fetchAssociative(); return $this->executeQuery($query, $params, $types)->fetchAssociative();
} catch (Throwable $e) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} }
} }
...@@ -489,7 +490,7 @@ class Connection implements DriverConnection ...@@ -489,7 +490,7 @@ class Connection implements DriverConnection
try { try {
return $this->executeQuery($query, $params, $types)->fetchNumeric(); return $this->executeQuery($query, $params, $types)->fetchNumeric();
} catch (Throwable $e) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} }
} }
...@@ -510,7 +511,7 @@ class Connection implements DriverConnection ...@@ -510,7 +511,7 @@ class Connection implements DriverConnection
try { try {
return $this->executeQuery($query, $params, $types)->fetchOne(); return $this->executeQuery($query, $params, $types)->fetchOne();
} catch (Throwable $e) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} }
} }
...@@ -772,7 +773,7 @@ class Connection implements DriverConnection ...@@ -772,7 +773,7 @@ class Connection implements DriverConnection
try { try {
return $this->executeQuery($query, $params, $types)->fetchAllNumeric(); return $this->executeQuery($query, $params, $types)->fetchAllNumeric();
} catch (Throwable $e) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} }
} }
...@@ -792,7 +793,7 @@ class Connection implements DriverConnection ...@@ -792,7 +793,7 @@ class Connection implements DriverConnection
try { try {
return $this->executeQuery($query, $params, $types)->fetchAllAssociative(); return $this->executeQuery($query, $params, $types)->fetchAllAssociative();
} catch (Throwable $e) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} }
} }
...@@ -812,7 +813,7 @@ class Connection implements DriverConnection ...@@ -812,7 +813,7 @@ class Connection implements DriverConnection
try { try {
return $this->executeQuery($query, $params, $types)->fetchFirstColumn(); return $this->executeQuery($query, $params, $types)->fetchFirstColumn();
} catch (Throwable $e) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} }
} }
...@@ -836,7 +837,7 @@ class Connection implements DriverConnection ...@@ -836,7 +837,7 @@ class Connection implements DriverConnection
yield $row; yield $row;
} }
} catch (Throwable $e) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} }
} }
...@@ -860,7 +861,7 @@ class Connection implements DriverConnection ...@@ -860,7 +861,7 @@ class Connection implements DriverConnection
yield $row; yield $row;
} }
} catch (Throwable $e) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} }
} }
...@@ -884,7 +885,7 @@ class Connection implements DriverConnection ...@@ -884,7 +885,7 @@ class Connection implements DriverConnection
yield $value; yield $value;
} }
} catch (Throwable $e) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $e, $query); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} }
} }
...@@ -901,8 +902,8 @@ class Connection implements DriverConnection ...@@ -901,8 +902,8 @@ class Connection implements DriverConnection
{ {
try { try {
return new Statement($sql, $this); return new Statement($sql, $this);
} catch (Throwable $ex) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $sql); $this->handleExceptionDuringQuery($e, $sql);
} }
} }
...@@ -952,8 +953,8 @@ class Connection implements DriverConnection ...@@ -952,8 +953,8 @@ class Connection implements DriverConnection
} }
return new Result($result, $this); return new Result($result, $this);
} catch (Throwable $ex) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} finally { } finally {
if ($logger !== null) { if ($logger !== null) {
$logger->stopQuery(); $logger->stopQuery();
...@@ -1021,8 +1022,8 @@ class Connection implements DriverConnection ...@@ -1021,8 +1022,8 @@ class Connection implements DriverConnection
try { try {
return $connection->query($sql); return $connection->query($sql);
} catch (Throwable $ex) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $sql); $this->handleExceptionDuringQuery($e, $sql);
} finally { } finally {
if ($logger !== null) { if ($logger !== null) {
$logger->stopQuery(); $logger->stopQuery();
...@@ -1069,8 +1070,8 @@ class Connection implements DriverConnection ...@@ -1069,8 +1070,8 @@ class Connection implements DriverConnection
} }
return $connection->exec($query); return $connection->exec($query);
} catch (Throwable $ex) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $query, $this->resolveParams($params, $types)); $this->handleExceptionDuringQuery($e, $query, $params, $types);
} finally { } finally {
if ($logger !== null) { if ($logger !== null) {
$logger->stopQuery(); $logger->stopQuery();
...@@ -1089,8 +1090,8 @@ class Connection implements DriverConnection ...@@ -1089,8 +1090,8 @@ class Connection implements DriverConnection
try { try {
return $connection->exec($statement); return $connection->exec($statement);
} catch (Throwable $ex) { } catch (Throwable $e) {
throw DBALException::driverExceptionDuringQuery($this->_driver, $ex, $statement); $this->handleExceptionDuringQuery($e, $statement);
} finally { } finally {
if ($logger !== null) { if ($logger !== null) {
$logger->stopQuery(); $logger->stopQuery();
...@@ -1640,6 +1641,8 @@ class Connection implements DriverConnection ...@@ -1640,6 +1641,8 @@ class Connection implements DriverConnection
* It is responsibility of the developer to handle this case * It is responsibility of the developer to handle this case
* and abort the request or reconnect manually: * and abort the request or reconnect manually:
* *
* @deprecated
*
* @return bool * @return bool
* *
* @example * @example
...@@ -1670,4 +1673,59 @@ class Connection implements DriverConnection ...@@ -1670,4 +1673,59 @@ class Connection implements DriverConnection
return false; 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;
}
} }
...@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Driver; ...@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\DriverException as TheDriverException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Platforms\DB2Platform;
use Doctrine\DBAL\Schema\DB2SchemaManager; use Doctrine\DBAL\Schema\DB2SchemaManager;
...@@ -27,4 +29,14 @@ abstract class AbstractDB2Driver implements Driver ...@@ -27,4 +29,14 @@ abstract class AbstractDB2Driver implements Driver
{ {
return new DB2SchemaManager($conn); return new DB2SchemaManager($conn);
} }
/**
* @param string $message
*
* @return DriverException
*/
public function convertException($message, TheDriverException $exception)
{
return new DriverException($message, $exception);
}
} }
...@@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection; ...@@ -6,6 +6,7 @@ use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException;
use Doctrine\DBAL\Exception\ConnectionException; use Doctrine\DBAL\Exception\ConnectionException;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Exception\DeadlockException; use Doctrine\DBAL\Exception\DeadlockException;
use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
...@@ -106,6 +107,9 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA ...@@ -106,6 +107,9 @@ abstract class AbstractMySQLDriver implements ExceptionConverterDriver, VersionA
case 2005: case 2005:
return new ConnectionException($message, $exception); return new ConnectionException($message, $exception);
case 2006:
return new ConnectionLost($message, $exception);
case 1048: case 1048:
case 1121: case 1121:
case 1138: case 1138:
......
...@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Driver; ...@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connection;
use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\DriverException as TheDriverException;
use Doctrine\DBAL\Exception\DriverException;
use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Platforms\SQLServer2012Platform;
use Doctrine\DBAL\Schema\SQLServerSchemaManager; use Doctrine\DBAL\Schema\SQLServerSchemaManager;
...@@ -27,4 +29,14 @@ abstract class AbstractSQLServerDriver implements Driver ...@@ -27,4 +29,14 @@ abstract class AbstractSQLServerDriver implements Driver
{ {
return new SQLServerSchemaManager($conn); return new SQLServerSchemaManager($conn);
} }
/**
* @param string $message
*
* @return DriverException
*/
public function convertException($message, TheDriverException $exception)
{
return new DriverException($message, $exception);
}
} }
...@@ -2,11 +2,14 @@ ...@@ -2,11 +2,14 @@
namespace Doctrine\DBAL\Driver; namespace Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver;
use Doctrine\DBAL\Driver\DriverException as TheDriverException; use Doctrine\DBAL\Driver\DriverException as TheDriverException;
use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Exception\DriverException;
/** /**
* Contract for a driver that is capable of converting DBAL driver exceptions into standardized DBAL driver exceptions. * Contract for a driver that is capable of converting DBAL driver exceptions into standardized DBAL driver exceptions.
*
* @deprecated All implementors of the {@link Driver} interface will have to implement this API.
*/ */
interface ExceptionConverterDriver interface ExceptionConverterDriver
{ {
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\IBMDB2; namespace Doctrine\DBAL\Driver\IBMDB2;
final class Connection extends DB2Connection final class Connection extends DB2Connection
......
...@@ -49,6 +49,8 @@ class DB2Statement implements StatementInterface ...@@ -49,6 +49,8 @@ class DB2Statement implements StatementInterface
private $lobs = []; private $lobs = [];
/** /**
* @internal The statement can be only instantiated by its driver connection.
*
* @param resource $stmt * @param resource $stmt
*/ */
public function __construct($stmt) public function __construct($stmt)
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\IBMDB2; namespace Doctrine\DBAL\Driver\IBMDB2;
final class Statement extends DB2Statement final class Statement extends DB2Statement
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\Mysqli; namespace Doctrine\DBAL\Driver\Mysqli;
final class Connection extends MysqliConnection final class Connection extends MysqliConnection
......
...@@ -160,6 +160,8 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection ...@@ -160,6 +160,8 @@ class MysqliConnection implements PingableConnection, ServerInfoAwareConnection
/** /**
* Pings the server and re-connects when `mysqli.reconnect = 1` * Pings the server and re-connects when `mysqli.reconnect = 1`
* *
* @deprecated
*
* @return bool * @return bool
*/ */
public function ping() public function ping()
......
...@@ -58,6 +58,8 @@ class MysqliStatement implements StatementInterface ...@@ -58,6 +58,8 @@ class MysqliStatement implements StatementInterface
protected $_values = []; protected $_values = [];
/** /**
* @internal The statement can be only instantiated by its driver connection.
*
* @param string $prepareString * @param string $prepareString
* *
* @throws MysqliException * @throws MysqliException
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\Mysqli; namespace Doctrine\DBAL\Driver\Mysqli;
final class Statement extends MysqliStatement final class Statement extends MysqliStatement
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\OCI8; namespace Doctrine\DBAL\Driver\OCI8;
final class Connection extends OCI8Connection final class Connection extends OCI8Connection
......
...@@ -55,6 +55,8 @@ class OCI8Statement implements StatementInterface ...@@ -55,6 +55,8 @@ class OCI8Statement implements StatementInterface
/** /**
* Creates a new OCI8Statement that uses the given connection handle and SQL statement. * Creates a new OCI8Statement that uses the given connection handle and SQL statement.
* *
* @internal The statement can be only instantiated by its driver connection.
*
* @param resource $dbh The connection handle. * @param resource $dbh The connection handle.
* @param string $query The SQL query. * @param string $query The SQL query.
*/ */
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\OCI8; namespace Doctrine\DBAL\Driver\OCI8;
final class Statement extends OCI8Statement final class Statement extends OCI8Statement
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\PDO; namespace Doctrine\DBAL\Driver\PDO;
use Doctrine\DBAL\Driver\PDOConnection; use Doctrine\DBAL\Driver\PDOConnection;
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\PDO; namespace Doctrine\DBAL\Driver\PDO;
use Doctrine\DBAL\Driver\PDOStatement; use Doctrine\DBAL\Driver\PDOStatement;
......
...@@ -34,6 +34,9 @@ class PDOStatement implements StatementInterface ...@@ -34,6 +34,9 @@ class PDOStatement implements StatementInterface
/** @var \PDOStatement */ /** @var \PDOStatement */
private $stmt; private $stmt;
/**
* @internal The statement can be only instantiated by its driver connection.
*/
public function __construct(\PDOStatement $stmt) public function __construct(\PDOStatement $stmt)
{ {
$this->stmt = $stmt; $this->stmt = $stmt;
......
...@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Driver; ...@@ -4,6 +4,8 @@ namespace Doctrine\DBAL\Driver;
/** /**
* An interface for connections which support a "native" ping method. * An interface for connections which support a "native" ping method.
*
* @deprecated
*/ */
interface PingableConnection extends Connection interface PingableConnection extends Connection
{ {
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\SQLSrv; namespace Doctrine\DBAL\Driver\SQLSrv;
final class Connection extends SQLSrvConnection final class Connection extends SQLSrvConnection
......
...@@ -77,6 +77,8 @@ class SQLSrvStatement implements StatementInterface ...@@ -77,6 +77,8 @@ class SQLSrvStatement implements StatementInterface
private const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;'; private const LAST_INSERT_ID_SQL = ';SELECT SCOPE_IDENTITY() AS LastInsertId;';
/** /**
* @internal The statement can be only instantiated by its driver connection.
*
* @param resource $conn * @param resource $conn
* @param string $sql * @param string $sql
*/ */
......
<?php <?php
declare(strict_types=1);
namespace Doctrine\DBAL\Driver\SQLSrv; namespace Doctrine\DBAL\Driver\SQLSrv;
class Statement extends SQLSrvStatement final class Statement extends SQLSrvStatement
{ {
} }
<?php
namespace Doctrine\DBAL\Exception;
/**
* @psalm-immutable
*/
final class ConnectionLost extends ConnectionException
{
}
...@@ -33,7 +33,7 @@ final class Result implements ResultInterface ...@@ -33,7 +33,7 @@ final class Result implements ResultInterface
try { try {
return $this->result->fetchNumeric(); return $this->result->fetchNumeric();
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->connection->getDriver(), $e); $this->connection->handleDriverException($e);
} }
} }
...@@ -47,7 +47,7 @@ final class Result implements ResultInterface ...@@ -47,7 +47,7 @@ final class Result implements ResultInterface
try { try {
return $this->result->fetchAssociative(); return $this->result->fetchAssociative();
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->connection->getDriver(), $e); $this->connection->handleDriverException($e);
} }
} }
...@@ -59,7 +59,7 @@ final class Result implements ResultInterface ...@@ -59,7 +59,7 @@ final class Result implements ResultInterface
try { try {
return $this->result->fetchOne(); return $this->result->fetchOne();
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->connection->getDriver(), $e); $this->connection->handleDriverException($e);
} }
} }
...@@ -73,7 +73,7 @@ final class Result implements ResultInterface ...@@ -73,7 +73,7 @@ final class Result implements ResultInterface
try { try {
return $this->result->fetchAllNumeric(); return $this->result->fetchAllNumeric();
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->connection->getDriver(), $e); $this->connection->handleDriverException($e);
} }
} }
...@@ -87,7 +87,7 @@ final class Result implements ResultInterface ...@@ -87,7 +87,7 @@ final class Result implements ResultInterface
try { try {
return $this->result->fetchAllAssociative(); return $this->result->fetchAllAssociative();
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->connection->getDriver(), $e); $this->connection->handleDriverException($e);
} }
} }
...@@ -101,7 +101,7 @@ final class Result implements ResultInterface ...@@ -101,7 +101,7 @@ final class Result implements ResultInterface
try { try {
return $this->result->fetchFirstColumn(); return $this->result->fetchFirstColumn();
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->connection->getDriver(), $e); $this->connection->handleDriverException($e);
} }
} }
...@@ -117,7 +117,7 @@ final class Result implements ResultInterface ...@@ -117,7 +117,7 @@ final class Result implements ResultInterface
yield $row; yield $row;
} }
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->connection->getDriver(), $e); $this->connection->handleDriverException($e);
} }
} }
...@@ -133,7 +133,7 @@ final class Result implements ResultInterface ...@@ -133,7 +133,7 @@ final class Result implements ResultInterface
yield $row; yield $row;
} }
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->connection->getDriver(), $e); $this->connection->handleDriverException($e);
} }
} }
...@@ -149,7 +149,7 @@ final class Result implements ResultInterface ...@@ -149,7 +149,7 @@ final class Result implements ResultInterface
yield $value; yield $value;
} }
} catch (DriverException $e) { } catch (DriverException $e) {
throw DBALException::driverException($this->connection->getDriver(), $e); $this->connection->handleDriverException($e);
} }
} }
......
...@@ -61,6 +61,8 @@ class Statement implements DriverStatement ...@@ -61,6 +61,8 @@ class Statement implements DriverStatement
/** /**
* Creates a new <tt>Statement</tt> for the given SQL and <tt>Connection</tt>. * Creates a new <tt>Statement</tt> for the given SQL and <tt>Connection</tt>.
* *
* @internal The statement can be only instantiated by {@link Connection}.
*
* @param string $sql The SQL of the statement. * @param string $sql The SQL of the statement.
* @param Connection $conn The connection on which the statement should be executed. * @param Connection $conn The connection on which the statement should be executed.
*/ */
...@@ -153,12 +155,7 @@ class Statement implements DriverStatement ...@@ -153,12 +155,7 @@ class Statement implements DriverStatement
$this->conn $this->conn
); );
} catch (Throwable $ex) { } catch (Throwable $ex) {
throw DBALException::driverExceptionDuringQuery( $this->conn->handleExceptionDuringQuery($ex, $this->sql, $this->params, $this->types);
$this->conn->getDriver(),
$ex,
$this->sql,
$this->conn->resolveParams($this->params, $this->types)
);
} finally { } finally {
if ($logger !== null) { if ($logger !== null) {
$logger->stopQuery(); $logger->stopQuery();
......
<?php
namespace Doctrine\DBAL\Tests\Functional\Connection;
use Doctrine\DBAL\Exception\ConnectionLost;
use Doctrine\DBAL\Platforms\MySqlPlatform;
use Doctrine\DBAL\Tests\FunctionalTestCase;
use function sleep;
class ConnectionLostTest extends FunctionalTestCase
{
protected function setUp(): void
{
parent::setUp();
if ($this->connection->getDatabasePlatform() instanceof MySqlPlatform) {
return;
}
$this->markTestSkipped('Currently only supported with MySQL');
}
protected function tearDown(): void
{
$this->resetSharedConn();
parent::tearDown();
}
public function testConnectionLost(): void
{
$this->connection->query('SET SESSION wait_timeout=1');
sleep(2);
$query = $this->connection->getDatabasePlatform()
->getDummySelectSQL();
try {
// in addition to the error, PHP 7.3 will generate a warning that needs to be
// suppressed in order to not let PHPUnit handle it before the actual error
@$this->connection->executeQuery($query);
} catch (ConnectionLost $e) {
self::assertEquals(1, $this->connection->fetchOne($query));
return;
}
self::fail('The connection should have lost');
}
}
...@@ -127,10 +127,9 @@ class StatementTest extends TestCase ...@@ -127,10 +127,9 @@ class StatementTest extends TestCase
->method('getSQLLogger') ->method('getSQLLogger')
->will(self::returnValue($logger)); ->will(self::returnValue($logger));
// Needed to satisfy construction of DBALException
$this->conn->expects(self::any()) $this->conn->expects(self::any())
->method('resolveParams') ->method('handleExceptionDuringQuery')
->will(self::returnValue([])); ->will(self::throwException(new DBALException()));
$logger->expects(self::once()) $logger->expects(self::once())
->method('startQuery'); ->method('startQuery');
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment