diff --git a/UPGRADE.md b/UPGRADE.md index 3e2192c8d31..0fedf7f1218 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -1,5 +1,37 @@ # Upgrade to 2.11 +## 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: + +- `DriverException` → `Exception` +- `AbstractDriverException` → `AbstractException` +- `IBMDB2\DB2Driver` → `IBMDB2\Driver` +- `IBMDB2\DB2Connection` → `IBMDB2\Connection` +- `IBMDB2\DB2Statement` → `IBMDB2\Statement` +- `Mysqli\MysqliConnection` → `Mysqli\Connection` +- `Mysqli\MysqliStatement` → `Mysqli\Statement` +- `OCI8\OCI8Connection` → `OCI8\Connection` +- `OCI8\OCI8Statement` → `OCI8\Statement` +- `SQLSrv\SQLSrvConnection` → `SQLSrv\Connection` +- `SQLSrv\SQLSrvStatement` → `SQLSrv\Statement` +- `PDOConnection` → `PDO\Connection` +- `PDOStatement` → `PDO\Statement` + +All driver-specific exception classes have been deprecated: + +- `IBMDB2\DB2Exception` +- `Mysqli\MysqliException` +- `OCI8\OCI8Exception` +- `PDOException` +- `SQLSrv\SQLSrvException` + +A driver-level exception should be only identified as a subtype of `Driver\Exception`. +Internal driver-level exception implementations may use `Driver\AbstractException` as the base class. +Driver-specific exception handling has to be implemented either in the driver or based on the type of the `Driver` implementation. + +The `Driver\AbstractException` class has been marked internal. + ## `Connection::getParams()` has been marked internal Consumers of the Connection class should not rely on connection parameters stored in the connection object. If needed, they should be obtained from a different source, e.g. application configuration. diff --git a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php index a3697529e75..34381e23b1c 100644 --- a/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php +++ b/lib/Doctrine/DBAL/Cache/ResultCacheStatement.php @@ -4,7 +4,7 @@ use ArrayIterator; use Doctrine\Common\Cache\Cache; -use Doctrine\DBAL\Driver\DriverException; +use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Driver\FetchUtils; use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\ResultStatement; @@ -297,7 +297,7 @@ public function free(): void /** * @return array|false * - * @throws DriverException + * @throws Exception */ private function doFetch() { diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index dda63310675..9a85c110bb8 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL; -use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface; +use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; use Doctrine\DBAL\Driver\ExceptionConverterDriver; use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -168,7 +168,7 @@ private static function wrapException(Driver $driver, Throwable $driverEx, strin return $driverEx; } - if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DriverExceptionInterface) { + if ($driver instanceof ExceptionConverterDriver && $driverEx instanceof DeprecatedDriverException) { return $driver->convertException($msg, $driverEx); } diff --git a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php index f57de38f09c..bf104545e41 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractDriverException.php +++ b/lib/Doctrine/DBAL/Driver/AbstractDriverException.php @@ -2,55 +2,11 @@ namespace Doctrine\DBAL\Driver; -use Exception; - /** - * Abstract base implementation of the {@link DriverException} interface. + * @deprecated * * @psalm-immutable */ -abstract class AbstractDriverException extends Exception implements DriverException +class AbstractDriverException extends AbstractException { - /** - * The driver specific error code. - * - * @var int|string|null - */ - private $errorCode; - - /** - * The SQLSTATE of the driver. - * - * @var string|null - */ - private $sqlState; - - /** - * @param string $message The driver error message. - * @param string|null $sqlState The SQLSTATE the driver is in at the time the error occurred, if any. - * @param int|string|null $errorCode The driver specific error code if any. - */ - public function __construct($message, $sqlState = null, $errorCode = null) - { - parent::__construct($message); - - $this->errorCode = $errorCode; - $this->sqlState = $sqlState; - } - - /** - * {@inheritdoc} - */ - public function getErrorCode() - { - return $this->errorCode; - } - - /** - * {@inheritdoc} - */ - public function getSQLState() - { - return $this->sqlState; - } } diff --git a/lib/Doctrine/DBAL/Driver/AbstractException.php b/lib/Doctrine/DBAL/Driver/AbstractException.php new file mode 100644 index 00000000000..65a9708ad65 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/AbstractException.php @@ -0,0 +1,60 @@ +errorCode = $errorCode; + $this->sqlState = $sqlState; + } + + /** + * {@inheritdoc} + */ + public function getErrorCode() + { + return $this->errorCode; + } + + /** + * {@inheritdoc} + */ + public function getSQLState() + { + return $this->sqlState; + } +} diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index 276322e28cd..565d055353d 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -5,7 +5,19 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; +use Doctrine\DBAL\Exception\ConnectionException; +use Doctrine\DBAL\Exception\DeadlockException; +use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; +use Doctrine\DBAL\Exception\InvalidFieldNameException; +use Doctrine\DBAL\Exception\LockWaitTimeoutException; +use Doctrine\DBAL\Exception\NonUniqueFieldNameException; +use Doctrine\DBAL\Exception\NotNullConstraintViolationException; +use Doctrine\DBAL\Exception\SyntaxErrorException; +use Doctrine\DBAL\Exception\TableExistsException; +use Doctrine\DBAL\Exception\TableNotFoundException; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; use Doctrine\DBAL\Platforms\MySQL80Platform; @@ -19,7 +31,7 @@ use function version_compare; /** - * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for MySQL based drivers. + * Abstract base implementation of the {@link Driver} interface for MySQL based drivers. */ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver { @@ -29,44 +41,44 @@ abstract class AbstractMySQLDriver implements Driver, ExceptionConverterDriver, * @link https://dev.mysql.com/doc/refman/8.0/en/client-error-reference.html * @link https://dev.mysql.com/doc/refman/8.0/en/server-error-reference.html */ - public function convertException($message, DriverException $exception) + public function convertException($message, DeprecatedDriverException $exception) { switch ($exception->getErrorCode()) { case '1213': - return new Exception\DeadlockException($message, $exception); + return new DeadlockException($message, $exception); case '1205': - return new Exception\LockWaitTimeoutException($message, $exception); + return new LockWaitTimeoutException($message, $exception); case '1050': - return new Exception\TableExistsException($message, $exception); + return new TableExistsException($message, $exception); case '1051': case '1146': - return new Exception\TableNotFoundException($message, $exception); + return new TableNotFoundException($message, $exception); case '1216': case '1217': case '1451': case '1452': case '1701': - return new Exception\ForeignKeyConstraintViolationException($message, $exception); + return new ForeignKeyConstraintViolationException($message, $exception); case '1062': case '1557': case '1569': case '1586': - return new Exception\UniqueConstraintViolationException($message, $exception); + return new UniqueConstraintViolationException($message, $exception); case '1054': case '1166': case '1611': - return new Exception\InvalidFieldNameException($message, $exception); + return new InvalidFieldNameException($message, $exception); case '1052': case '1060': case '1110': - return new Exception\NonUniqueFieldNameException($message, $exception); + return new NonUniqueFieldNameException($message, $exception); case '1064': case '1149': @@ -80,7 +92,7 @@ public function convertException($message, DriverException $exception) case '1541': case '1554': case '1626': - return new Exception\SyntaxErrorException($message, $exception); + return new SyntaxErrorException($message, $exception); case '1044': case '1045': @@ -94,7 +106,7 @@ public function convertException($message, DriverException $exception) case '1429': case '2002': case '2005': - return new Exception\ConnectionException($message, $exception); + return new ConnectionException($message, $exception); case '1048': case '1121': @@ -104,10 +116,10 @@ public function convertException($message, DriverException $exception) case '1263': case '1364': case '1566': - return new Exception\NotNullConstraintViolationException($message, $exception); + return new NotNullConstraintViolationException($message, $exception); } - return new Exception\DriverException($message, $exception); + return new DriverException($message, $exception); } /** diff --git a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php index bd1802f324e..b3b58e58db6 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractOracleDriver.php @@ -5,56 +5,66 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\AbstractOracleDriver\EasyConnectString; -use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; +use Doctrine\DBAL\Exception\ConnectionException; +use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; +use Doctrine\DBAL\Exception\InvalidFieldNameException; +use Doctrine\DBAL\Exception\NonUniqueFieldNameException; +use Doctrine\DBAL\Exception\NotNullConstraintViolationException; +use Doctrine\DBAL\Exception\SyntaxErrorException; +use Doctrine\DBAL\Exception\TableExistsException; +use Doctrine\DBAL\Exception\TableNotFoundException; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\OracleSchemaManager; /** - * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for Oracle based drivers. + * Abstract base implementation of the {@link Driver} interface for Oracle based drivers. */ abstract class AbstractOracleDriver implements Driver, ExceptionConverterDriver { /** * {@inheritdoc} */ - public function convertException($message, DriverException $exception) + public function convertException($message, DeprecatedDriverException $exception) { switch ($exception->getErrorCode()) { case '1': case '2299': case '38911': - return new Exception\UniqueConstraintViolationException($message, $exception); + return new UniqueConstraintViolationException($message, $exception); case '904': - return new Exception\InvalidFieldNameException($message, $exception); + return new InvalidFieldNameException($message, $exception); case '918': case '960': - return new Exception\NonUniqueFieldNameException($message, $exception); + return new NonUniqueFieldNameException($message, $exception); case '923': - return new Exception\SyntaxErrorException($message, $exception); + return new SyntaxErrorException($message, $exception); case '942': - return new Exception\TableNotFoundException($message, $exception); + return new TableNotFoundException($message, $exception); case '955': - return new Exception\TableExistsException($message, $exception); + return new TableExistsException($message, $exception); case '1017': case '12545': - return new Exception\ConnectionException($message, $exception); + return new ConnectionException($message, $exception); case '1400': - return new Exception\NotNullConstraintViolationException($message, $exception); + return new NotNullConstraintViolationException($message, $exception); case '2266': case '2291': case '2292': - return new Exception\ForeignKeyConstraintViolationException($message, $exception); + return new ForeignKeyConstraintViolationException($message, $exception); } - return new Exception\DriverException($message, $exception); + return new DriverException($message, $exception); } /** diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index 5aabb977f17..bf0ac0d2a5f 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -5,7 +5,18 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; +use Doctrine\DBAL\Exception\ConnectionException; +use Doctrine\DBAL\Exception\DeadlockException; +use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; +use Doctrine\DBAL\Exception\InvalidFieldNameException; +use Doctrine\DBAL\Exception\NonUniqueFieldNameException; +use Doctrine\DBAL\Exception\NotNullConstraintViolationException; +use Doctrine\DBAL\Exception\SyntaxErrorException; +use Doctrine\DBAL\Exception\TableExistsException; +use Doctrine\DBAL\Exception\TableNotFoundException; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Platforms\PostgreSQL100Platform; use Doctrine\DBAL\Platforms\PostgreSQL91Platform; use Doctrine\DBAL\Platforms\PostgreSQL92Platform; @@ -20,7 +31,7 @@ use function version_compare; /** - * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for PostgreSQL based drivers. + * Abstract base implementation of the {@link Driver} interface for PostgreSQL based drivers. */ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver { @@ -29,58 +40,58 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri * * @link http://www.postgresql.org/docs/9.3/static/errcodes-appendix.html */ - public function convertException($message, DriverException $exception) + public function convertException($message, DeprecatedDriverException $exception) { switch ($exception->getSQLState()) { case '40001': case '40P01': - return new Exception\DeadlockException($message, $exception); + return new DeadlockException($message, $exception); case '0A000': // Foreign key constraint violations during a TRUNCATE operation // are considered "feature not supported" in PostgreSQL. if (strpos($exception->getMessage(), 'truncate') !== false) { - return new Exception\ForeignKeyConstraintViolationException($message, $exception); + return new ForeignKeyConstraintViolationException($message, $exception); } break; case '23502': - return new Exception\NotNullConstraintViolationException($message, $exception); + return new NotNullConstraintViolationException($message, $exception); case '23503': - return new Exception\ForeignKeyConstraintViolationException($message, $exception); + return new ForeignKeyConstraintViolationException($message, $exception); case '23505': - return new Exception\UniqueConstraintViolationException($message, $exception); + return new UniqueConstraintViolationException($message, $exception); case '42601': - return new Exception\SyntaxErrorException($message, $exception); + return new SyntaxErrorException($message, $exception); case '42702': - return new Exception\NonUniqueFieldNameException($message, $exception); + return new NonUniqueFieldNameException($message, $exception); case '42703': - return new Exception\InvalidFieldNameException($message, $exception); + return new InvalidFieldNameException($message, $exception); case '42P01': - return new Exception\TableNotFoundException($message, $exception); + return new TableNotFoundException($message, $exception); case '42P07': - return new Exception\TableExistsException($message, $exception); + return new TableExistsException($message, $exception); case '7': // In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code. // The exception code is always set to 7 here. // We have to match against the SQLSTATE in the error message in these cases. if (strpos($exception->getMessage(), 'SQLSTATE[08006]') !== false) { - return new Exception\ConnectionException($message, $exception); + return new ConnectionException($message, $exception); } break; } - return new Exception\DriverException($message, $exception); + return new DriverException($message, $exception); } /** diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php index 12296ab9603..52ecd4bcef2 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php @@ -5,7 +5,19 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; +use Doctrine\DBAL\Exception\ConnectionException; +use Doctrine\DBAL\Exception\DeadlockException; +use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; +use Doctrine\DBAL\Exception\InvalidFieldNameException; +use Doctrine\DBAL\Exception\LockWaitTimeoutException; +use Doctrine\DBAL\Exception\NonUniqueFieldNameException; +use Doctrine\DBAL\Exception\NotNullConstraintViolationException; +use Doctrine\DBAL\Exception\SyntaxErrorException; +use Doctrine\DBAL\Exception\TableExistsException; +use Doctrine\DBAL\Exception\TableNotFoundException; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Platforms\SQLAnywhere11Platform; use Doctrine\DBAL\Platforms\SQLAnywhere12Platform; use Doctrine\DBAL\Platforms\SQLAnywhere16Platform; @@ -18,7 +30,7 @@ use function version_compare; /** - * Abstract base implementation of the {@link Doctrine\DBAL\Driver} interface for SAP Sybase SQL Anywhere based drivers. + * Abstract base implementation of the {@link Driver} interface for SAP Sybase SQL Anywhere based drivers. */ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDriver, VersionAwarePlatformDriver { @@ -27,54 +39,54 @@ abstract class AbstractSQLAnywhereDriver implements Driver, ExceptionConverterDr * * @link http://dcx.sybase.com/index.html#sa160/en/saerrors/sqlerror.html */ - public function convertException($message, DriverException $exception) + public function convertException($message, DeprecatedDriverException $exception) { switch ($exception->getErrorCode()) { case '-306': case '-307': case '-684': - return new Exception\DeadlockException($message, $exception); + return new DeadlockException($message, $exception); case '-210': case '-1175': case '-1281': - return new Exception\LockWaitTimeoutException($message, $exception); + return new LockWaitTimeoutException($message, $exception); case '-100': case '-103': case '-832': - return new Exception\ConnectionException($message, $exception); + return new ConnectionException($message, $exception); case '-143': - return new Exception\InvalidFieldNameException($message, $exception); + return new InvalidFieldNameException($message, $exception); case '-193': case '-196': - return new Exception\UniqueConstraintViolationException($message, $exception); + return new UniqueConstraintViolationException($message, $exception); case '-194': case '-198': - return new Exception\ForeignKeyConstraintViolationException($message, $exception); + return new ForeignKeyConstraintViolationException($message, $exception); case '-144': - return new Exception\NonUniqueFieldNameException($message, $exception); + return new NonUniqueFieldNameException($message, $exception); case '-184': case '-195': - return new Exception\NotNullConstraintViolationException($message, $exception); + return new NotNullConstraintViolationException($message, $exception); case '-131': - return new Exception\SyntaxErrorException($message, $exception); + return new SyntaxErrorException($message, $exception); case '-110': - return new Exception\TableExistsException($message, $exception); + return new TableExistsException($message, $exception); case '-141': case '-1041': - return new Exception\TableNotFoundException($message, $exception); + return new TableNotFoundException($message, $exception); } - return new Exception\DriverException($message, $exception); + return new DriverException($message, $exception); } /** diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver/PortWithoutHost.php b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver/Exception/PortWithoutHost.php similarity index 55% rename from lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver/PortWithoutHost.php rename to lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver/Exception/PortWithoutHost.php index e968421fe7a..ea8dcc461e5 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver/PortWithoutHost.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver/Exception/PortWithoutHost.php @@ -2,16 +2,16 @@ declare(strict_types=1); -namespace Doctrine\DBAL\Driver\AbstractSQLServerDriver; +namespace Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception; -use Doctrine\DBAL\Driver\AbstractDriverException; +use Doctrine\DBAL\Driver\AbstractException; /** * @internal * * @psalm-immutable */ -final class PortWithoutHost extends AbstractDriverException +final class PortWithoutHost extends AbstractException { public static function new(): self { diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php index d0ec0b687bb..f0cf8433e3d 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php @@ -4,7 +4,19 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Exception; +use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; +use Doctrine\DBAL\Exception\ConnectionException; +use Doctrine\DBAL\Exception\DriverException; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; +use Doctrine\DBAL\Exception\InvalidFieldNameException; +use Doctrine\DBAL\Exception\LockWaitTimeoutException; +use Doctrine\DBAL\Exception\NonUniqueFieldNameException; +use Doctrine\DBAL\Exception\NotNullConstraintViolationException; +use Doctrine\DBAL\Exception\ReadOnlyException; +use Doctrine\DBAL\Exception\SyntaxErrorException; +use Doctrine\DBAL\Exception\TableExistsException; +use Doctrine\DBAL\Exception\TableNotFoundException; +use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\SqliteSchemaManager; @@ -20,10 +32,10 @@ abstract class AbstractSQLiteDriver implements Driver, ExceptionConverterDriver * * @link http://www.sqlite.org/c3ref/c_abort.html */ - public function convertException($message, DriverException $exception) + public function convertException($message, DeprecatedDriverException $exception) { if (strpos($exception->getMessage(), 'database is locked') !== false) { - return new Exception\LockWaitTimeoutException($message, $exception); + return new LockWaitTimeoutException($message, $exception); } if ( @@ -32,49 +44,49 @@ public function convertException($message, DriverException $exception) strpos($exception->getMessage(), 'are not unique') !== false || strpos($exception->getMessage(), 'UNIQUE constraint failed') !== false ) { - return new Exception\UniqueConstraintViolationException($message, $exception); + return new UniqueConstraintViolationException($message, $exception); } if ( strpos($exception->getMessage(), 'may not be NULL') !== false || strpos($exception->getMessage(), 'NOT NULL constraint failed') !== false ) { - return new Exception\NotNullConstraintViolationException($message, $exception); + return new NotNullConstraintViolationException($message, $exception); } if (strpos($exception->getMessage(), 'no such table:') !== false) { - return new Exception\TableNotFoundException($message, $exception); + return new TableNotFoundException($message, $exception); } if (strpos($exception->getMessage(), 'already exists') !== false) { - return new Exception\TableExistsException($message, $exception); + return new TableExistsException($message, $exception); } if (strpos($exception->getMessage(), 'has no column named') !== false) { - return new Exception\InvalidFieldNameException($message, $exception); + return new InvalidFieldNameException($message, $exception); } if (strpos($exception->getMessage(), 'ambiguous column name') !== false) { - return new Exception\NonUniqueFieldNameException($message, $exception); + return new NonUniqueFieldNameException($message, $exception); } if (strpos($exception->getMessage(), 'syntax error') !== false) { - return new Exception\SyntaxErrorException($message, $exception); + return new SyntaxErrorException($message, $exception); } if (strpos($exception->getMessage(), 'attempt to write a readonly database') !== false) { - return new Exception\ReadOnlyException($message, $exception); + return new ReadOnlyException($message, $exception); } if (strpos($exception->getMessage(), 'unable to open database file') !== false) { - return new Exception\ConnectionException($message, $exception); + return new ConnectionException($message, $exception); } if (strpos($exception->getMessage(), 'FOREIGN KEY constraint failed') !== false) { - return new Exception\ForeignKeyConstraintViolationException($message, $exception); + return new ForeignKeyConstraintViolationException($message, $exception); } - return new Exception\DriverException($message, $exception); + return new DriverException($message, $exception); } /** diff --git a/lib/Doctrine/DBAL/Driver/DriverException.php b/lib/Doctrine/DBAL/Driver/DriverException.php index a7f4008e1b7..2e83e82bee1 100644 --- a/lib/Doctrine/DBAL/Driver/DriverException.php +++ b/lib/Doctrine/DBAL/Driver/DriverException.php @@ -2,34 +2,11 @@ namespace Doctrine\DBAL\Driver; -use Throwable; - /** - * Contract for a driver exception. - * - * Driver exceptions provide the SQLSTATE of the driver - * and the driver specific error code at the time the error occurred. + * @deprecated Use {@link Exception} instead * * @psalm-immutable */ -interface DriverException extends Throwable +interface DriverException extends Exception { - /** - * Returns the driver specific error code if available. - * - * Returns null if no driver specific error code is available - * for the error raised by the driver. - * - * @return int|string|null - */ - public function getErrorCode(); - - /** - * Returns the SQLSTATE the driver was in at the time the error occurred. - * - * Returns null if the driver does not provide a SQLSTATE for the error occurred. - * - * @return string|null - */ - public function getSQLState(); } diff --git a/lib/Doctrine/DBAL/Driver/Exception.php b/lib/Doctrine/DBAL/Driver/Exception.php new file mode 100644 index 00000000000..f65591f90ca --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/Exception.php @@ -0,0 +1,32 @@ +> * - * @throws DriverException + * @throws Exception */ public static function fetchAllNumeric(Result $result): array { @@ -44,7 +44,7 @@ public static function fetchAllNumeric(Result $result): array /** * @return array> * - * @throws DriverException + * @throws Exception */ public static function fetchAllAssociative(Result $result): array { @@ -60,7 +60,7 @@ public static function fetchAllAssociative(Result $result): array /** * @return array * - * @throws DriverException + * @throws Exception */ public static function fetchFirstColumn(Result $result): array { diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Connection.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Connection.php new file mode 100644 index 00000000000..66d77c10406 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Connection.php @@ -0,0 +1,9 @@ +toString(); - return new DB2Connection( + return new Connection( $params, (string) $username, (string) $password, diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php index f66d0e533f9..aa9ee29c056 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Exception.php @@ -5,6 +5,8 @@ use Doctrine\DBAL\Driver\AbstractDriverException; /** + * @deprecated Use {@link Exception} instead + * * @psalm-immutable */ class DB2Exception extends AbstractDriverException diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php index 4f74c2a1f7f..71954994e53 100644 --- a/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/DB2Statement.php @@ -3,9 +3,12 @@ namespace Doctrine\DBAL\Driver\IBMDB2; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotCopyStreamToStream; +use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotCreateTemporaryFile; +use Doctrine\DBAL\Driver\IBMDB2\Exception\CannotWriteToTemporaryFile; use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError; use Doctrine\DBAL\Driver\Result; -use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\Driver\Statement as StatementInterface; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; @@ -53,7 +56,10 @@ use const DB2_PARAM_FILE; use const DB2_PARAM_IN; -class DB2Statement implements IteratorAggregate, Statement, Result +/** + * @deprecated Use {@link Statement} instead + */ +class DB2Statement implements IteratorAggregate, StatementInterface, Result { /** @var resource */ private $stmt; @@ -519,7 +525,7 @@ private function createTemporaryFile() $handle = @tmpfile(); if ($handle === false) { - throw new DB2Exception('Could not create temporary file: ' . error_get_last()['message']); + throw CannotCreateTemporaryFile::new(error_get_last()['message']); } return $handle; @@ -534,7 +540,7 @@ private function createTemporaryFile() private function copyStreamToStream($source, $target): void { if (@stream_copy_to_stream($source, $target) === false) { - throw new DB2Exception('Could not copy source stream to temporary file: ' . error_get_last()['message']); + throw CannotCopyStreamToStream::new(error_get_last()['message']); } } @@ -546,7 +552,7 @@ private function copyStreamToStream($source, $target): void private function writeStringToStream(string $string, $target): void { if (@fwrite($target, $string) === false) { - throw new DB2Exception('Could not write string to temporary file: ' . error_get_last()['message']); + throw CannotWriteToTemporaryFile::new(error_get_last()['message']); } } } diff --git a/lib/Doctrine/DBAL/Driver/IBMDB2/Driver.php b/lib/Doctrine/DBAL/Driver/IBMDB2/Driver.php new file mode 100644 index 00000000000..dcc84b32d05 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/IBMDB2/Driver.php @@ -0,0 +1,9 @@ +error, $connection->sqlstate, $connection->errno); + } +} diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php b/lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php new file mode 100644 index 00000000000..f73e07c32fa --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php @@ -0,0 +1,21 @@ +connect_error, 'HY000', $connection->connect_errno); + } +} diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Exception/FailedReadingStreamOffset.php b/lib/Doctrine/DBAL/Driver/Mysqli/Exception/FailedReadingStreamOffset.php new file mode 100644 index 00000000000..d3aaf8fbed4 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Exception/FailedReadingStreamOffset.php @@ -0,0 +1,22 @@ +error, $statement->sqlstate, $statement->errno); + } +} diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Exception/UnknownType.php b/lib/Doctrine/DBAL/Driver/Mysqli/Exception/UnknownType.php new file mode 100644 index 00000000000..0282b4d1b32 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Exception/UnknownType.php @@ -0,0 +1,25 @@ +conn->real_connect($params['host'], $username, $password, $dbname, $port, $socket, $flags)) { - throw new MysqliException($this->conn->connect_error, $this->conn->sqlstate ?? 'HY000', $this->conn->connect_errno); + throw ConnectionFailed::new($this->conn); } } finally { restore_error_handler(); @@ -130,7 +136,7 @@ public function requiresQueryForServerVersion() */ public function prepare($prepareString) { - return new MysqliStatement($this->conn, $prepareString); + return new Statement($this->conn, $prepareString); } /** @@ -160,7 +166,7 @@ public function quote($input, $type = ParameterType::STRING) public function exec($statement) { if ($this->conn->query($statement) === false) { - throw new MysqliException($this->conn->error, $this->conn->sqlstate, $this->conn->errno); + throw ConnectionError::new($this->conn); } return $this->conn->affected_rows; @@ -254,9 +260,7 @@ private function setDriverOptions(array $driverOptions = []): void } if (! in_array($option, $supportedDriverOptions, true)) { - throw new MysqliException( - sprintf($exceptionMsg, 'Unsupported', $option, $value) - ); + throw InvalidOption::fromOption($option, $value); } if (@mysqli_options($this->conn, $option, $value)) { diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php index 8e8e697c4a3..6fbff4291d1 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliException.php @@ -5,7 +5,7 @@ use Doctrine\DBAL\Driver\AbstractDriverException; /** - * Exception thrown in case the mysqli driver errors. + * @deprecated Use {@link Exception} instead * * @psalm-immutable */ diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php index c3f893fc127..0b07f87761a 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/MysqliStatement.php @@ -3,8 +3,12 @@ namespace Doctrine\DBAL\Driver\Mysqli; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\Mysqli\Exception\ConnectionError; +use Doctrine\DBAL\Driver\Mysqli\Exception\FailedReadingStreamOffset; +use Doctrine\DBAL\Driver\Mysqli\Exception\StatementError; +use Doctrine\DBAL\Driver\Mysqli\Exception\UnknownType; use Doctrine\DBAL\Driver\Result; -use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\Driver\Statement as StatementInterface; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\FetchMode; @@ -27,7 +31,10 @@ use function sprintf; use function str_repeat; -class MysqliStatement implements IteratorAggregate, Statement, Result +/** + * @deprecated Use {@link Statement} instead + */ +class MysqliStatement implements IteratorAggregate, StatementInterface, Result { /** @var string[] */ protected static $_paramTypeMap = [ @@ -86,7 +93,7 @@ public function __construct(mysqli $conn, $prepareString) $stmt = $conn->prepare($prepareString); if ($stmt === false) { - throw new MysqliException($this->_conn->error, $this->_conn->sqlstate, $this->_conn->errno); + throw ConnectionError::new($this->_conn); } $this->_stmt = $stmt; @@ -108,7 +115,7 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l assert(is_int($column)); if (! isset(self::$_paramTypeMap[$type])) { - throw new MysqliException(sprintf("Unknown type: '%s'", $type)); + throw UnknownType::new($type); } $this->_bindedValues[$column] =& $variable; @@ -125,7 +132,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING) assert(is_int($param)); if (! isset(self::$_paramTypeMap[$type])) { - throw new MysqliException(sprintf("Unknown type: '%s'", $type)); + throw UnknownType::new($type); } $this->_values[$param] = $value; @@ -143,7 +150,7 @@ public function execute($params = null) if ($this->_bindedValues !== null) { if ($params !== null) { if (! $this->bindUntypedValues($params)) { - throw new MysqliException($this->_stmt->error, $this->_stmt->errno); + throw StatementError::new($this->_stmt); } } else { $this->bindTypedParameters(); @@ -151,7 +158,7 @@ public function execute($params = null) } if (! $this->_stmt->execute()) { - throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); + throw StatementError::new($this->_stmt); } if ($this->_columnNames === null) { @@ -198,7 +205,7 @@ public function execute($params = null) } if (! $this->_stmt->bind_result(...$refs)) { - throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); + throw StatementError::new($this->_stmt); } } @@ -240,7 +247,7 @@ private function bindTypedParameters(): void } if (! $this->_stmt->bind_param($types, ...$values)) { - throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); + throw StatementError::new($this->_stmt); } $this->sendLongData($streams); @@ -260,11 +267,11 @@ private function sendLongData(array $streams): void $chunk = fread($stream, 8192); if ($chunk === false) { - throw new MysqliException("Failed reading the stream resource for parameter offset ${paramNr}."); + throw FailedReadingStreamOffset::new($paramNr); } if (! $this->_stmt->send_long_data($paramNr - 1, $chunk)) { - throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); + throw StatementError::new($this->_stmt); } } } @@ -334,7 +341,7 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX } if ($values === false) { - throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); + throw StatementError::new($this->_stmt); } if ($fetchMode === FetchMode::NUMERIC) { @@ -420,7 +427,7 @@ public function fetchNumeric() } if ($values === false) { - throw new MysqliException($this->_stmt->error, $this->_stmt->sqlstate, $this->_stmt->errno); + throw StatementError::new($this->_stmt); } return $values; diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Statement.php b/lib/Doctrine/DBAL/Driver/Mysqli/Statement.php new file mode 100644 index 00000000000..308dd14dbff --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Statement.php @@ -0,0 +1,9 @@ +_constructDsn($params), diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Exception/NonTerminatedStringLiteral.php b/lib/Doctrine/DBAL/Driver/OCI8/Exception/NonTerminatedStringLiteral.php new file mode 100644 index 00000000000..870e4136970 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/OCI8/Exception/NonTerminatedStringLiteral.php @@ -0,0 +1,27 @@ +dbh, $prepareString, $this); + return new Statement($this->dbh, $prepareString, $this); } /** @@ -164,7 +167,7 @@ public function lastInsertId($name = null) $result = $stmt->fetchColumn(); if ($result === false) { - throw new OCI8Exception('lastInsertId failed: Query was executed but no result was returned.'); + throw SequenceDoesNotExist::new(); } return (int) $result; diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php index 83b078097a4..ab1449f3b56 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Exception.php @@ -5,6 +5,8 @@ use Doctrine\DBAL\Driver\AbstractDriverException; /** + * @deprecated Use {@link Exception} instead + * * @psalm-immutable */ class OCI8Exception extends AbstractDriverException diff --git a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php index 4f04a46a5cf..e023532d405 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/OCI8Statement.php @@ -3,8 +3,10 @@ namespace Doctrine\DBAL\Driver\OCI8; use Doctrine\DBAL\Driver\FetchUtils; +use Doctrine\DBAL\Driver\OCI8\Exception\NonTerminatedStringLiteral; +use Doctrine\DBAL\Driver\OCI8\Exception\UnknownParameterIndex; use Doctrine\DBAL\Driver\Result; -use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\Driver\Statement as StatementInterface; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; @@ -31,7 +33,6 @@ use function oci_parse; use function preg_match; use function preg_quote; -use function sprintf; use function substr; use const OCI_ASSOC; @@ -50,8 +51,10 @@ /** * The OCI8 implementation of the Statement interface. + * + * @deprecated Use {@link Statement} instead */ -class OCI8Statement implements IteratorAggregate, Statement, Result +class OCI8Statement implements IteratorAggregate, StatementInterface, Result { /** @var resource */ protected $_dbh; @@ -161,10 +164,7 @@ public static function convertPositionalToNamedPlaceholders($statement) } while ($result); if ($currentLiteralDelimiter) { - throw new OCI8Exception(sprintf( - 'The statement contains non-terminated string literal starting at offset %d', - $tokenOffset - 1 - )); + throw NonTerminatedStringLiteral::new($tokenOffset - 1); } $fragments[] = substr($statement, $fragmentOffset); @@ -284,7 +284,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le { if (is_int($param)) { if (! isset($this->_paramMap[$param])) { - throw new OCI8Exception(sprintf('Could not find variable mapping with index %d, in the SQL statement', $param)); + throw UnknownParameterIndex::new($param); } $param = $this->_paramMap[$param]; diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Statement.php b/lib/Doctrine/DBAL/Driver/OCI8/Statement.php new file mode 100644 index 00000000000..706b402e3df --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/OCI8/Statement.php @@ -0,0 +1,9 @@ +setAttribute(PDO::ATTR_STATEMENT_CLASS, [PDOStatement::class, []]); + $this->setAttribute(PDO::ATTR_STATEMENT_CLASS, [Statement::class, []]); $this->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } @@ -43,8 +50,8 @@ public function exec($statement) assert($result !== false); return $result; - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } @@ -60,24 +67,24 @@ public function getServerVersion() * @param string $prepareString * @param array $driverOptions * - * @return \PDOStatement + * @return PDOStatement */ public function prepare($prepareString, $driverOptions = []) { try { $statement = parent::prepare($prepareString, $driverOptions); - assert($statement instanceof \PDOStatement); + assert($statement instanceof PDOStatement); return $statement; - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } /** * {@inheritdoc} * - * @return \PDOStatement + * @return PDOStatement */ public function query() { @@ -85,11 +92,11 @@ public function query() try { $stmt = parent::query(...$args); - assert($stmt instanceof \PDOStatement); + assert($stmt instanceof PDOStatement); return $stmt; - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } @@ -112,8 +119,8 @@ public function lastInsertId($name = null) } return parent::lastInsertId($name); - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } diff --git a/lib/Doctrine/DBAL/Driver/PDOException.php b/lib/Doctrine/DBAL/Driver/PDOException.php index c2571032b80..e82bcbcfc6b 100644 --- a/lib/Doctrine/DBAL/Driver/PDOException.php +++ b/lib/Doctrine/DBAL/Driver/PDOException.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL\Driver; /** - * Tiny wrapper for PDOException instances to implement the {@link DriverException} interface. + * @deprecated Use {@link Exception} instead * * @psalm-immutable */ diff --git a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php index 20332adbd16..0543d8786e7 100644 --- a/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOIbm/Driver.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL\Driver\PDOIbm; use Doctrine\DBAL\Driver\AbstractDB2Driver; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDO\Connection; /** * Driver for the PDO IBM extension. @@ -17,7 +17,7 @@ class Driver extends AbstractDB2Driver */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { - return new PDOConnection( + return new Connection( $this->_constructPdoDsn($params), $username, $password, diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php index 3058febd05a..e6df0bbad21 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractMySQLDriver; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDO\Connection; use PDOException; /** @@ -18,7 +18,7 @@ class Driver extends AbstractMySQLDriver public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { try { - $conn = new PDOConnection( + $conn = new Connection( $this->constructPdoDsn($params), $username, $password, diff --git a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php index f1239eafbd4..88aa01a5434 100644 --- a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractOracleDriver; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDO\Connection; use PDOException; /** @@ -23,7 +23,7 @@ class Driver extends AbstractOracleDriver public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { try { - return new PDOConnection( + return new Connection( $this->constructPdoDsn($params), $username, $password, diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index 43f06cb7b7f..e3f15ab610f 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDO\Connection; use PDO; use PDOException; @@ -21,7 +21,7 @@ class Driver extends AbstractPostgreSQLDriver public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { try { - $pdo = new PDOConnection( + $pdo = new Connection( $this->_constructPdoDsn($params), $username, $password, diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index 4566f649578..304043b9cdd 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -4,7 +4,7 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractSQLiteDriver; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDO\Connection; use Doctrine\DBAL\Platforms\SqlitePlatform; use PDOException; @@ -36,7 +36,7 @@ public function connect(array $params, $username = null, $password = null, array } try { - $pdo = new PDOConnection( + $pdo = new Connection( $this->_constructPdoDsn($params), $username, $password, diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php index 5847669456c..a05f5898b22 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDO\Connection as BaseStatement; use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\ParameterType; use PDO; @@ -14,7 +14,7 @@ /** * Sqlsrv Connection implementation. */ -class Connection extends PDOConnection +class Connection extends BaseStatement { /** * {@inheritdoc} diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php index 880f1263da0..bd0fd6a665c 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Driver.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; use Doctrine\DBAL\Driver\AbstractSQLServerDriver; -use Doctrine\DBAL\Driver\AbstractSQLServerDriver\PortWithoutHost; +use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost; use function is_int; use function sprintf; diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php index 8d6521ff56c..7091eb375a3 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Statement.php @@ -2,14 +2,14 @@ namespace Doctrine\DBAL\Driver\PDOSqlsrv; -use Doctrine\DBAL\Driver\PDOStatement; +use Doctrine\DBAL\Driver\PDO\Statement as BaseStatement; use Doctrine\DBAL\ParameterType; use PDO; /** * PDO SQL Server Statement */ -class Statement extends PDOStatement +class Statement extends BaseStatement { /** * {@inheritdoc} diff --git a/lib/Doctrine/DBAL/Driver/PDOStatement.php b/lib/Doctrine/DBAL/Driver/PDOStatement.php index 911f5d49665..97b0407b556 100644 --- a/lib/Doctrine/DBAL/Driver/PDOStatement.php +++ b/lib/Doctrine/DBAL/Driver/PDOStatement.php @@ -2,9 +2,12 @@ namespace Doctrine\DBAL\Driver; +use Doctrine\DBAL\Driver\PDO\Exception; +use Doctrine\DBAL\Driver\Statement as StatementInterface; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use PDO; +use PDOException; use function array_slice; use function assert; @@ -18,8 +21,10 @@ /** * The PDO implementation of the Statement interface. * Used by all PDO-based drivers. + * + * @deprecated Use {@link Statement} instead */ -class PDOStatement extends \PDOStatement implements Statement, Result +class PDOStatement extends \PDOStatement implements StatementInterface, Result { private const PARAM_TYPE_MAP = [ ParameterType::NULL => PDO::PARAM_NULL, @@ -69,8 +74,8 @@ public function setFetchMode($fetchMode, $arg2 = null, $arg3 = null) } return parent::setFetchMode($fetchMode, $arg2, $arg3); - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } @@ -83,8 +88,8 @@ public function bindValue($param, $value, $type = ParameterType::STRING) try { return parent::bindValue($param, $value, $type); - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } @@ -103,8 +108,8 @@ public function bindParam($column, &$variable, $type = ParameterType::STRING, $l try { return parent::bindParam($column, $variable, $type, ...array_slice(func_get_args(), 3)); - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } @@ -117,7 +122,7 @@ public function closeCursor() { try { return parent::closeCursor(); - } catch (\PDOException $exception) { + } catch (PDOException $exception) { // Exceptions not allowed by the interface. // In case driver implementations do not adhere to the interface, silence exceptions here. return true; @@ -131,8 +136,8 @@ public function execute($params = null) { try { return parent::execute($params); - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } @@ -151,8 +156,8 @@ public function fetch($fetchMode = null, $cursorOrientation = PDO::FETCH_ORI_NEX try { return parent::fetch(...$args); - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } @@ -184,8 +189,8 @@ public function fetchAll($fetchMode = null, $fetchArgument = null, $ctorArgs = n assert(is_array($data)); return $data; - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } @@ -198,8 +203,8 @@ public function fetchColumn($columnIndex = 0) { try { return parent::fetchColumn($columnIndex); - } catch (\PDOException $exception) { - throw new PDOException($exception); + } catch (PDOException $exception) { + throw Exception::new($exception); } } diff --git a/lib/Doctrine/DBAL/Driver/Result.php b/lib/Doctrine/DBAL/Driver/Result.php index 65be0f03c49..a52f0563e4b 100644 --- a/lib/Doctrine/DBAL/Driver/Result.php +++ b/lib/Doctrine/DBAL/Driver/Result.php @@ -14,7 +14,7 @@ interface Result * * @return array|false * - * @throws DriverException + * @throws Exception */ public function fetchNumeric(); @@ -23,7 +23,7 @@ public function fetchNumeric(); * * @return array|false * - * @throws DriverException + * @throws Exception */ public function fetchAssociative(); @@ -32,7 +32,7 @@ public function fetchAssociative(); * * @return mixed|false * - * @throws DriverException + * @throws Exception */ public function fetchOne(); @@ -41,7 +41,7 @@ public function fetchOne(); * * @return array> * - * @throws DriverException + * @throws Exception */ public function fetchAllNumeric(): array; @@ -50,7 +50,7 @@ public function fetchAllNumeric(): array; * * @return array> * - * @throws DriverException + * @throws Exception */ public function fetchAllAssociative(): array; @@ -59,7 +59,7 @@ public function fetchAllAssociative(): array; * * @return array * - * @throws DriverException + * @throws Exception */ public function fetchFirstColumn(): array; diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php index c9c3a6f2ef7..25e28e9a0e8 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/SQLAnywhereStatement.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere; -use Doctrine\DBAL\Driver\DriverException; +use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Driver\FetchUtils; use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\Driver\Statement; @@ -350,7 +350,7 @@ public function fetchAssociative() /** * {@inheritdoc} * - * @throws DriverException + * @throws Exception */ public function fetchOne() { @@ -360,7 +360,7 @@ public function fetchOne() /** * @return array> * - * @throws DriverException + * @throws Exception */ public function fetchAllNumeric(): array { @@ -370,7 +370,7 @@ public function fetchAllNumeric(): array /** * @return array> * - * @throws DriverException + * @throws Exception */ public function fetchAllAssociative(): array { @@ -380,7 +380,7 @@ public function fetchAllAssociative(): array /** * @return array * - * @throws DriverException + * @throws Exception */ public function fetchFirstColumn(): array { diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Connection.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Connection.php new file mode 100644 index 00000000000..646842c37d0 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Connection.php @@ -0,0 +1,9 @@ +conn = $conn; @@ -80,7 +83,7 @@ public function requiresQueryForServerVersion() */ public function prepare($sql) { - return new SQLSrvStatement($this->conn, $sql, $this->lastInsertId); + return new Statement($this->conn, $sql, $this->lastInsertId); } /** @@ -120,13 +123,13 @@ public function exec($statement) $stmt = sqlsrv_query($this->conn, $statement); if ($stmt === false) { - throw SQLSrvException::fromSqlSrvErrors(); + throw Error::new(); } $rowsAffected = sqlsrv_rows_affected($stmt); if ($rowsAffected === false) { - throw SQLSrvException::fromSqlSrvErrors(); + throw Error::new(); } return $rowsAffected; @@ -157,7 +160,7 @@ public function lastInsertId($name = null) public function beginTransaction() { if (! sqlsrv_begin_transaction($this->conn)) { - throw SQLSrvException::fromSqlSrvErrors(); + throw Error::new(); } return true; @@ -169,7 +172,7 @@ public function beginTransaction() public function commit() { if (! sqlsrv_commit($this->conn)) { - throw SQLSrvException::fromSqlSrvErrors(); + throw Error::new(); } return true; @@ -181,7 +184,7 @@ public function commit() public function rollBack() { if (! sqlsrv_rollback($this->conn)) { - throw SQLSrvException::fromSqlSrvErrors(); + throw Error::new(); } return true; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php index af70c6852ff..03300800e83 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvException.php @@ -3,13 +3,11 @@ namespace Doctrine\DBAL\Driver\SQLSrv; use Doctrine\DBAL\Driver\AbstractDriverException; - -use function rtrim; -use function sqlsrv_errors; - -use const SQLSRV_ERR_ERRORS; +use Doctrine\DBAL\Driver\SQLSrv\Exception\Error; /** + * @deprecated Use {@link Exception} instead + * * @psalm-immutable */ class SQLSrvException extends AbstractDriverException @@ -21,28 +19,6 @@ class SQLSrvException extends AbstractDriverException */ public static function fromSqlSrvErrors() { - $message = ''; - $sqlState = null; - $errorCode = null; - - foreach ((array) sqlsrv_errors(SQLSRV_ERR_ERRORS) as $error) { - $message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n"; - - if ($sqlState === null) { - $sqlState = $error['SQLSTATE']; - } - - if ($errorCode !== null) { - continue; - } - - $errorCode = $error['code']; - } - - if (! $message) { - $message = 'SQL Server error occurred but no error message was retrieved from driver.'; - } - - return new self(rtrim($message), $sqlState, $errorCode); + return Error::new(); } } diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php index 886faf55bcc..0a0dd78df27 100644 --- a/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/SQLSrvStatement.php @@ -4,7 +4,8 @@ use Doctrine\DBAL\Driver\FetchUtils; use Doctrine\DBAL\Driver\Result; -use Doctrine\DBAL\Driver\Statement; +use Doctrine\DBAL\Driver\SQLSrv\Exception\Error; +use Doctrine\DBAL\Driver\Statement as StatementInterface; use Doctrine\DBAL\Driver\StatementIterator; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; @@ -41,8 +42,10 @@ /** * SQL Server Statement. + * + * @deprecated Use {@link Statement} instead */ -class SQLSrvStatement implements IteratorAggregate, Statement, Result +class SQLSrvStatement implements IteratorAggregate, StatementInterface, Result { /** * The SQLSRV Resource. @@ -255,7 +258,7 @@ public function execute($params = null) } if (! sqlsrv_execute($this->stmt)) { - throw SQLSrvException::fromSqlSrvErrors(); + throw Error::new(); } if ($this->lastInsertId) { @@ -308,7 +311,7 @@ private function prepare() $stmt = sqlsrv_prepare($this->conn, $this->sql, $params); if (! $stmt) { - throw SQLSrvException::fromSqlSrvErrors(); + throw Error::new(); } return $stmt; diff --git a/lib/Doctrine/DBAL/Driver/SQLSrv/Statement.php b/lib/Doctrine/DBAL/Driver/SQLSrv/Statement.php new file mode 100644 index 00000000000..e0958f687d8 --- /dev/null +++ b/lib/Doctrine/DBAL/Driver/SQLSrv/Statement.php @@ -0,0 +1,9 @@ + PDOPgSQLDriver::class, 'pdo_oci' => PDOOCIDriver::class, 'oci8' => OCI8Driver::class, - 'ibm_db2' => DB2Driver::class, + 'ibm_db2' => IBMDB2Driver::class, 'pdo_sqlsrv' => PDOSQLSrvDriver::class, 'mysqli' => MySQLiDriver::class, 'drizzle_pdo_mysql' => DrizzlePDOMySQLDriver::class, diff --git a/lib/Doctrine/DBAL/Exception/DriverException.php b/lib/Doctrine/DBAL/Exception/DriverException.php index 2a3338733db..c0dd5d89d8a 100644 --- a/lib/Doctrine/DBAL/Exception/DriverException.php +++ b/lib/Doctrine/DBAL/Exception/DriverException.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Exception; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; use Exception; /** @@ -15,15 +16,15 @@ class DriverException extends DBALException /** * The previous DBAL driver exception. * - * @var \Doctrine\DBAL\Driver\DriverException + * @var DeprecatedDriverException */ private $driverException; /** - * @param string $message The exception message. - * @param \Doctrine\DBAL\Driver\DriverException $driverException The DBAL driver exception to chain. + * @param string $message The exception message. + * @param DeprecatedDriverException $driverException The DBAL driver exception to chain. */ - public function __construct($message, \Doctrine\DBAL\Driver\DriverException $driverException) + public function __construct($message, DeprecatedDriverException $driverException) { $exception = null; diff --git a/lib/Doctrine/DBAL/Portability/Connection.php b/lib/Doctrine/DBAL/Portability/Connection.php index ad79f98e889..9fb001fcf14 100644 --- a/lib/Doctrine/DBAL/Portability/Connection.php +++ b/lib/Doctrine/DBAL/Portability/Connection.php @@ -4,7 +4,8 @@ use Doctrine\DBAL\Cache\QueryCacheProfile; use Doctrine\DBAL\ColumnCase; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Connection as BaseConnection; +use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection; use PDO; use function func_get_args; @@ -15,7 +16,7 @@ /** * Portability wrapper for a Connection. */ -class Connection extends \Doctrine\DBAL\Connection +class Connection extends BaseConnection { public const PORTABILITY_ALL = 255; public const PORTABILITY_NONE = 0; diff --git a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php index 4f463c0ad3a..301b7ae0184 100644 --- a/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/OracleSchemaManager.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\DriverException; +use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Types\Type; use Throwable; @@ -37,7 +37,7 @@ public function dropDatabase($database) $exception = $exception->getPrevious(); assert($exception instanceof Throwable); - if (! $exception instanceof DriverException) { + if (! $exception instanceof Exception) { throw $exception; } diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index 3fac92d70a6..a04ff08c430 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\DriverException; +use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Types\Type; use PDOException; @@ -35,7 +35,7 @@ public function dropDatabase($database) $exception = $exception->getPrevious(); assert($exception instanceof Throwable); - if (! $exception instanceof DriverException) { + if (! $exception instanceof Exception) { throw $exception; } diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 3d6dfc27f26..bc39b077687 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL; use Doctrine\DBAL\Abstraction\Result; -use Doctrine\DBAL\Driver\DriverException; +use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Driver\Statement as DriverStatement; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; @@ -296,7 +296,7 @@ public function fetchNumeric() } return $this->stmt->fetch(FetchMode::NUMERIC); - } catch (DriverException $e) { + } catch (Exception $e) { throw DBALException::driverException($this->conn->getDriver(), $e); } } @@ -314,7 +314,7 @@ public function fetchAssociative() } return $this->stmt->fetch(FetchMode::ASSOCIATIVE); - } catch (DriverException $e) { + } catch (Exception $e) { throw DBALException::driverException($this->conn->getDriver(), $e); } } @@ -332,7 +332,7 @@ public function fetchOne() } return $this->stmt->fetch(FetchMode::COLUMN); - } catch (DriverException $e) { + } catch (Exception $e) { throw DBALException::driverException($this->conn->getDriver(), $e); } } @@ -350,7 +350,7 @@ public function fetchAllNumeric(): array } return $this->stmt->fetchAll(FetchMode::NUMERIC); - } catch (DriverException $e) { + } catch (Exception $e) { throw DBALException::driverException($this->conn->getDriver(), $e); } } @@ -368,7 +368,7 @@ public function fetchAllAssociative(): array } return $this->stmt->fetchAll(FetchMode::ASSOCIATIVE); - } catch (DriverException $e) { + } catch (Exception $e) { throw DBALException::driverException($this->conn->getDriver(), $e); } } @@ -386,7 +386,7 @@ public function fetchFirstColumn(): array } return $this->stmt->fetchAll(FetchMode::COLUMN); - } catch (DriverException $e) { + } catch (Exception $e) { throw DBALException::driverException($this->conn->getDriver(), $e); } } @@ -410,7 +410,7 @@ public function iterateNumeric(): Traversable yield $row; } } - } catch (DriverException $e) { + } catch (Exception $e) { throw DBALException::driverException($this->conn->getDriver(), $e); } } @@ -434,7 +434,7 @@ public function iterateAssociative(): Traversable yield $row; } } - } catch (DriverException $e) { + } catch (Exception $e) { throw DBALException::driverException($this->conn->getDriver(), $e); } } @@ -458,7 +458,7 @@ public function iterateColumn(): Traversable yield $value; } } - } catch (DriverException $e) { + } catch (Exception $e) { throw DBALException::driverException($this->conn->getDriver(), $e); } } diff --git a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php index c53c9ccf172..3d53f342968 100644 --- a/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php +++ b/lib/Doctrine/DBAL/Tools/Console/Command/ImportCommand.php @@ -2,8 +2,8 @@ namespace Doctrine\DBAL\Tools\Console\Command; -use Doctrine\DBAL\Driver\PDOConnection; -use Doctrine\DBAL\Driver\PDOStatement; +use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection; +use Doctrine\DBAL\Driver\PDO\Statement as PDOStatement; use InvalidArgumentException; use PDOException; use RuntimeException; diff --git a/phpcs.xml.dist b/phpcs.xml.dist index 20aa33d134b..3001de2f6bd 100644 --- a/phpcs.xml.dist +++ b/phpcs.xml.dist @@ -87,6 +87,7 @@ https://github.com/squizlabs/PHP_CodeSniffer/issues/2950 --> lib/Doctrine/DBAL/Driver/IBMDB2/DB2Connection.php + lib/Doctrine/DBAL/Driver/Mysqli/Exception/ConnectionFailed.php lib/Doctrine/DBAL/SQLParserUtils.php lib/Doctrine/DBAL/Tools/Dumper.php @@ -101,7 +102,7 @@ - tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php + tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/StatementTest.php diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php index bd9b8b6b11e..c55fba56fa8 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractSQLServerDriverTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\Driver\AbstractSQLServerDriver\PortWithoutHost; +use Doctrine\DBAL\Driver\AbstractSQLServerDriver\Exception\PortWithoutHost; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLServer2005Platform; use Doctrine\DBAL\Platforms\SQLServer2008Platform; diff --git a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php index e48d3c40b66..33e76c5e53d 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/IBMDB2/DB2DriverTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\DBAL\Driver\IBMDB2; use Doctrine\DBAL\Driver as DriverInterface; -use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; +use Doctrine\DBAL\Driver\IBMDB2\Driver; use Doctrine\Tests\DBAL\Driver\AbstractDB2DriverTest; class DB2DriverTest extends AbstractDB2DriverTest @@ -15,6 +15,6 @@ public function testReturnsName(): void protected function createDriver(): DriverInterface { - return new DB2Driver(); + return new Driver(); } } diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php similarity index 79% rename from tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php rename to tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php index 6cd2396e679..53f3e16710c 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDO/ExceptionTest.php @@ -1,14 +1,15 @@ wrappedException = new \PDOException(self::MESSAGE, self::SQLSTATE); + $this->wrappedException = new PDOException(self::MESSAGE, self::SQLSTATE); $this->wrappedException->errorInfo = [self::SQLSTATE, self::ERROR_CODE]; - $this->exception = new PDOException($this->wrappedException); + $this->exception = new Exception($this->wrappedException); } public function testReturnsCode(): void diff --git a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php index 5e3d24583f7..1607207cc47 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/PDOPgSql/DriverTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\DBAL\Driver\PDOPgSql; use Doctrine\DBAL\Driver as DriverInterface; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDO\Connection; use Doctrine\DBAL\Driver\PDOPgSql\Driver; use Doctrine\Tests\DBAL\Driver\AbstractPostgreSQLDriverTest; use Doctrine\Tests\TestUtil; @@ -89,7 +89,7 @@ private function skipWhenNotUsingPdoPgsql(): void /** * @param array $driverOptions */ - private function connect(array $driverOptions): PDOConnection + private function connect(array $driverOptions): Connection { $params = TestUtil::getConnectionParams(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index b3330b7c093..785d0ac33d2 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -5,10 +5,10 @@ use DateTime; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; +use Doctrine\DBAL\Driver\IBMDB2\Driver as IBMDB2Driver; use Doctrine\DBAL\Driver\Mysqli\Driver as MySQLiDriver; use Doctrine\DBAL\Driver\OCI8\Driver as Oci8Driver; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDO\Connection as PDOConnection; use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver; use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; use Doctrine\DBAL\FetchMode; @@ -258,7 +258,7 @@ public function testFetchAllWithMissingTypes(callable $fetch): void } if ( - $this->connection->getDriver() instanceof DB2Driver + $this->connection->getDriver() instanceof IBMDB2Driver ) { $this->markTestSkipped( 'ibm_ibm2 may or may not report the error depending on the PHP version and the connection state' diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/ConnectionTest.php index 1ffc5a7b9bb..d042ec55020 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/ConnectionTest.php @@ -2,8 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2; -use Doctrine\DBAL\Driver\IBMDB2\DB2Connection; -use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; +use Doctrine\DBAL\Driver\IBMDB2\Connection; +use Doctrine\DBAL\Driver\IBMDB2\Driver; use Doctrine\DBAL\Driver\IBMDB2\Exception\ConnectionFailed; use Doctrine\DBAL\Driver\IBMDB2\Exception\PrepareFailed; use Doctrine\Tests\DbalFunctionalTestCase; @@ -11,6 +11,7 @@ use function db2_close; use function extension_loaded; +use function get_parent_class; class ConnectionTest extends DbalFunctionalTestCase { @@ -22,7 +23,7 @@ protected function setUp(): void parent::setUp(); - if ($this->connection->getDriver() instanceof DB2Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -37,14 +38,14 @@ protected function tearDown(): void public function testConnectionFailure(): void { $this->expectException(ConnectionFailed::class); - new DB2Connection(['dbname' => 'garbage'], '', ''); + new Connection(['dbname' => 'garbage'], '', ''); } public function testPrepareFailure(): void { $driverConnection = $this->connection->getWrappedConnection(); - $re = new ReflectionProperty($driverConnection, 'conn'); + $re = new ReflectionProperty(get_parent_class($driverConnection), 'conn'); $re->setAccessible(true); $conn = $re->getValue($driverConnection); db2_close($conn); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DriverTest.php similarity index 74% rename from tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php rename to tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DriverTest.php index 214251b76ee..daf31b4d2ed 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2DriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DriverTest.php @@ -2,13 +2,13 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2; -use Doctrine\DBAL\Driver; -use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; +use Doctrine\DBAL\Driver as DriverInterface; +use Doctrine\DBAL\Driver\IBMDB2\Driver; use Doctrine\Tests\DBAL\Functional\Driver\AbstractDriverTest; use function extension_loaded; -class DB2DriverTest extends AbstractDriverTest +class DriverTest extends AbstractDriverTest { protected function setUp(): void { @@ -18,7 +18,7 @@ protected function setUp(): void parent::setUp(); - if ($this->connection->getDriver() instanceof DB2Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } @@ -35,8 +35,8 @@ public function testReturnsDatabaseNameWithoutDatabaseNameParameter(): void $this->markTestSkipped('IBM DB2 does not support connecting without database name.'); } - protected function createDriver(): Driver + protected function createDriver(): DriverInterface { - return new DB2Driver(); + return new Driver(); } } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/StatementTest.php similarity index 86% rename from tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php rename to tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/StatementTest.php index 2d504933060..eb235185003 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/DB2StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/IBMDB2/StatementTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\IBMDB2; -use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; +use Doctrine\DBAL\Driver\IBMDB2\Driver; use Doctrine\DBAL\Driver\IBMDB2\Exception\StatementError; use Doctrine\Tests\DbalFunctionalTestCase; @@ -14,7 +14,7 @@ use const E_NOTICE; use const E_WARNING; -class DB2StatementTest extends DbalFunctionalTestCase +class StatementTest extends DbalFunctionalTestCase { protected function setUp(): void { @@ -24,7 +24,7 @@ protected function setUp(): void parent::setUp(); - if ($this->connection->getDriver() instanceof DB2Driver) { + if ($this->connection->getDriver() instanceof Driver) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php index fc7e5e9d389..baba579d76f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/Mysqli/ConnectionTest.php @@ -2,8 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\Mysqli; +use Doctrine\DBAL\Driver\Mysqli\Connection; use Doctrine\DBAL\Driver\Mysqli\Driver; -use Doctrine\DBAL\Driver\Mysqli\MysqliConnection; use Doctrine\DBAL\Driver\Mysqli\MysqliException; use Doctrine\Tests\DbalFunctionalTestCase; use Doctrine\Tests\TestUtil; @@ -39,7 +39,7 @@ public function testDriverOptions(): void $driverOptions = [MYSQLI_OPT_CONNECT_TIMEOUT => 1]; $connection = $this->getConnection($driverOptions); - self::assertInstanceOf(MysqliConnection::class, $connection); + self::assertInstanceOf(Connection::class, $connection); } public function testUnsupportedDriverOption(): void @@ -58,11 +58,11 @@ public function testPing(): void /** * @param mixed[] $driverOptions */ - private function getConnection(array $driverOptions): MysqliConnection + private function getConnection(array $driverOptions): Connection { $params = TestUtil::getConnectionParams(); - return new MysqliConnection( + return new Connection( $params, $params['user'] ?? '', $params['password'] ?? '', diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php similarity index 91% rename from tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php rename to tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php index eb6b767dd88..cd551e41b12 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/OCI8ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/OCI8/ConnectionTest.php @@ -2,16 +2,16 @@ namespace Doctrine\Tests\DBAL\Functional\Driver\OCI8; +use Doctrine\DBAL\Driver\OCI8\Connection; use Doctrine\DBAL\Driver\OCI8\Driver; -use Doctrine\DBAL\Driver\OCI8\OCI8Connection; use Doctrine\DBAL\Schema\Table; use Doctrine\Tests\DbalFunctionalTestCase; use function extension_loaded; -class OCI8ConnectionTest extends DbalFunctionalTestCase +class ConnectionTest extends DbalFunctionalTestCase { - /** @var OCI8Connection */ + /** @var Connection */ protected $driverConnection; protected function setUp(): void diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php similarity index 83% rename from tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php rename to tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php index f0104e5abd6..602e4b541ce 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDO/ConnectionTest.php @@ -1,9 +1,9 @@ driverConnection = $this->connection->getWrappedConnection(); - if ($this->driverConnection instanceof PDOConnection) { + if ($this->driverConnection instanceof Connection) { return; } @@ -54,9 +54,9 @@ public function testDoesNotRequireQueryForServerVersion(): void public function testThrowsWrappedExceptionOnConstruct(): void { - $this->expectException(PDOException::class); + $this->expectException(Exception::class); - new PDOConnection('foo'); + new Connection('foo'); } /** @@ -64,7 +64,7 @@ public function testThrowsWrappedExceptionOnConstruct(): void */ public function testThrowsWrappedExceptionOnExec(): void { - $this->expectException(PDOException::class); + $this->expectException(Exception::class); $this->driverConnection->exec('foo'); } @@ -94,14 +94,14 @@ public function testThrowsWrappedExceptionOnPrepare(): void // so that PDO actually communicates with the database server to check the query. $this->driverConnection->setAttribute(PDO::ATTR_EMULATE_PREPARES, false); - $this->expectException(PDOException::class); + $this->expectException(Exception::class); $this->driverConnection->prepare('foo'); } public function testThrowsWrappedExceptionOnQuery(): void { - $this->expectException(PDOException::class); + $this->expectException(Exception::class); $this->driverConnection->query('foo'); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/ConnectionTest.php similarity index 92% rename from tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php rename to tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/ConnectionTest.php index 3dbeb6edee1..6259c4c5a29 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgsqlConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Driver/PDOPgSql/ConnectionTest.php @@ -1,6 +1,6 @@ connection->getWrappedConnection() instanceof PDOConnection) { + if (! $this->connection->getWrappedConnection() instanceof Connection) { $this->markTestSkipped('PDO-only test'); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 83e50b16165..ca63bc0dc6d 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; use Doctrine\DBAL\DBALException; -use Doctrine\DBAL\Driver\PDOConnection; +use Doctrine\DBAL\Driver\PDO\Connection; use Doctrine\DBAL\ParameterType; use Doctrine\Tests\DbalFunctionalTestCase; use PDO; @@ -173,10 +173,10 @@ public static function booleanTypeConversionWithoutPdoTypeProvider(): iterable ]; } - private function getWrappedConnection(): PDOConnection + private function getWrappedConnection(): Connection { $connection = $this->connection->getWrappedConnection(); - self::assertInstanceOf(PDOConnection::class, $connection); + self::assertInstanceOf(Connection::class, $connection); return $connection; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php b/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php index ff8a503b5a3..70217b09ede 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Types/BinaryTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Functional\Types; -use Doctrine\DBAL\Driver\IBMDB2\DB2Driver; +use Doctrine\DBAL\Driver\IBMDB2\Driver; use Doctrine\DBAL\Driver\PDOOracle\Driver as PDOOracleDriver; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Table; @@ -46,7 +46,7 @@ public function testInsertAndSelect(): void $value2 = random_bytes(64); /** @see https://bugs.php.net/bug.php?id=76322 */ - if ($this->connection->getDriver() instanceof DB2Driver) { + if ($this->connection->getDriver() instanceof Driver) { $value1 = str_replace("\x00", "\xFF", $value1); $value2 = str_replace("\x00", "\xFF", $value2); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php index 5a39a71bef5..aac223c39ff 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/WriteTest.php @@ -3,7 +3,7 @@ namespace Doctrine\Tests\DBAL\Functional; use DateTime; -use Doctrine\DBAL\Driver\DriverException; +use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; @@ -347,13 +347,13 @@ public function testDeleteWhereIsNull(): void * * @return string|false * - * @throws DriverException + * @throws Exception */ private function lastInsertId(?string $name = null) { try { return $this->connection->lastInsertId($name); - } catch (DriverException $e) { + } catch (Exception $e) { if ($e->getCode() === 'IM001') { $this->markTestSkipped($e->getMessage()); } diff --git a/tests/Doctrine/Tests/DBAL/UtilTest.php b/tests/Doctrine/Tests/DBAL/UtilTest.php index 13211764a27..d07b9ec5068 100644 --- a/tests/Doctrine/Tests/DBAL/UtilTest.php +++ b/tests/Doctrine/Tests/DBAL/UtilTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\DBAL; -use Doctrine\DBAL\Driver\OCI8\OCI8Statement; +use Doctrine\DBAL\Driver\OCI8\Statement; use Doctrine\Tests\DbalTestCase; class UtilTest extends DbalTestCase @@ -73,7 +73,7 @@ public static function dataConvertPositionalToNamedParameters(): iterable */ public function testConvertPositionalToNamedParameters(string $inputSQL, string $expectedOutputSQL, array $expectedOutputParamsMap): void { - [$statement, $params] = OCI8Statement::convertPositionalToNamedPlaceholders($inputSQL); + [$statement, $params] = Statement::convertPositionalToNamedPlaceholders($inputSQL); self::assertEquals($expectedOutputSQL, $statement); self::assertEquals($expectedOutputParamsMap, $params);