From dbfd10700c782a8794b28dd5de8bf1d09e0c5544 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:24:57 -0700 Subject: [PATCH 01/10] Throw DBALException instead of driver exception from wrapper classes --- src/Connection.php | 24 +++++++++++++++++------- src/Statement.php | 23 ++++++++++++++++++----- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index a6d7349bdc3..2cd1335a487 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -215,7 +215,7 @@ public function getDatabase() { $platform = $this->getDatabasePlatform(); $query = $platform->getDummySelectSQL($platform->getCurrentDatabaseExpression()); - $database = $this->query($query)->fetchOne(); + $database = $this->fetchOne($query); assert(is_string($database) || $database === null); @@ -344,7 +344,7 @@ private function detectDatabasePlatform(): void * * @return string|null * - * @throws Exception + * @throws DBALException */ private function getDatabasePlatformVersion() { @@ -408,7 +408,11 @@ private function getServerVersion() // Automatic platform version detection. if ($connection instanceof ServerInfoAwareConnection) { - return $connection->getServerVersion(); + try { + return $connection->getServerVersion(); + } catch (DriverException $e) { + throw $this->convertException($e); + } } // Unable to detect platform version. @@ -1131,10 +1135,16 @@ public function getTransactionNestingLevel() * @param string|null $seqName Name of the sequence object from which the ID should be returned. * * @return string A string representation of the last inserted ID. + * + * @throws DBALException */ public function lastInsertId($seqName = null) { - return $this->getWrappedConnection()->lastInsertId($seqName); + try { + return $this->getWrappedConnection()->lastInsertId($seqName); + } catch (DriverException $e) { + throw $this->convertException($e); + } } /** @@ -1386,7 +1396,7 @@ public function createSavepoint($savepoint) throw ConnectionException::savepointsNotSupported(); } - $this->getWrappedConnection()->exec($this->platform->createSavePoint($savepoint)); + $this->executeUpdate($this->platform->createSavePoint($savepoint)); } /** @@ -1408,7 +1418,7 @@ public function releaseSavepoint($savepoint) return; } - $this->getWrappedConnection()->exec($this->platform->releaseSavePoint($savepoint)); + $this->executeUpdate($this->platform->releaseSavePoint($savepoint)); } /** @@ -1426,7 +1436,7 @@ public function rollbackSavepoint($savepoint) throw ConnectionException::savepointsNotSupported(); } - $this->getWrappedConnection()->exec($this->platform->rollbackSavePoint($savepoint)); + $this->executeUpdate($this->platform->rollbackSavePoint($savepoint)); } /** diff --git a/src/Statement.php b/src/Statement.php index 4be12c6cc40..7f44ceebbfe 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -95,27 +95,34 @@ public function __construct($sql, Connection $conn) * @param mixed $type Either a PDO binding type or a DBAL mapping type name or instance. * * @return bool TRUE on success, FALSE on failure. + * + * @throws DBALException */ public function bindValue($name, $value, $type = ParameterType::STRING) { $this->params[$name] = $value; $this->types[$name] = $type; + + $bindingType = ParameterType::STRING; + if ($type !== null) { if (is_string($type)) { $type = Type::getType($type); } + $bindingType = $type; + if ($type instanceof Type) { $value = $type->convertToDatabaseValue($value, $this->platform); $bindingType = $type->getBindingType(); - } else { - $bindingType = $type; } + } + try { return $this->stmt->bindValue($name, $value, $bindingType); + } catch (Exception $e) { + throw $this->conn->convertException($e); } - - return $this->stmt->bindValue($name, $value); } /** @@ -130,13 +137,19 @@ public function bindValue($name, $value, $type = ParameterType::STRING) * so that PHP allocates enough memory to hold the returned value. * * @return bool TRUE on success, FALSE on failure. + * + * @throws DBALException */ public function bindParam($name, &$var, $type = ParameterType::STRING, $length = null) { $this->params[$name] = $var; $this->types[$name] = $type; - return $this->stmt->bindParam($name, $var, $type, $length); + try { + return $this->stmt->bindParam($name, $var, $type, $length); + } catch (Exception $e) { + throw $this->conn->convertException($e); + } } /** From 2494d9bcba2c7fffbd6797dcb8c1260ded04b93f Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:36:03 -0700 Subject: [PATCH 02/10] Replace @throws ConnectionException with @throws DBALException for transactions Not only a connection exception is possible (e.g. it may be a connection failure or a failure to detect the platform). --- src/Connection.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/Connection.php b/src/Connection.php index 2cd1335a487..870fc755930 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -1188,7 +1188,7 @@ public function transactional(Closure $func) * * @return void * - * @throws ConnectionException + * @throws DBALException */ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) { @@ -1262,8 +1262,7 @@ public function beginTransaction() /** * @return bool * - * @throws ConnectionException If the commit failed due to no active transaction or - * because the transaction was marked for rollback only. + * @throws DBALException */ public function commit() { @@ -1336,7 +1335,7 @@ private function commitAll(): void * * @return bool * - * @throws ConnectionException If the rollback operation failed. + * @throws DBALException */ public function rollBack() { @@ -1388,7 +1387,7 @@ public function rollBack() * * @return void * - * @throws ConnectionException + * @throws DBALException */ public function createSavepoint($savepoint) { @@ -1406,7 +1405,7 @@ public function createSavepoint($savepoint) * * @return void * - * @throws ConnectionException + * @throws DBALException */ public function releaseSavepoint($savepoint) { @@ -1428,7 +1427,7 @@ public function releaseSavepoint($savepoint) * * @return void * - * @throws ConnectionException + * @throws DBALException */ public function rollbackSavepoint($savepoint) { From 2efcbe2f08586b43d3fd6fa896086a2c54f0b9f1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:30:42 -0700 Subject: [PATCH 03/10] Add missing @throws DBALException --- src/Connection.php | 20 +++++++++++++++++++ .../PrimaryReadReplicaConnection.php | 1 + src/Driver/PDO/Connection.php | 2 ++ src/Event/Listeners/OracleSessionInit.php | 3 +++ src/Platforms/AbstractPlatform.php | 2 ++ src/Platforms/MySqlPlatform.php | 5 +++++ src/Platforms/SqlitePlatform.php | 2 ++ src/Query/QueryBuilder.php | 3 +++ 8 files changed, 38 insertions(+) diff --git a/src/Connection.php b/src/Connection.php index 870fc755930..32839d3bbd3 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -401,6 +401,8 @@ private function getDatabasePlatformVersion() * Returns the database server version if the underlying driver supports it. * * @return string|null + * + * @throws DBALException */ private function getServerVersion() { @@ -626,6 +628,8 @@ public function close() * @param int $level The level to set. * * @return int + * + * @throws DBALException */ public function setTransactionIsolation($level) { @@ -638,6 +642,8 @@ public function setTransactionIsolation($level) * Gets the currently active transaction isolation level. * * @return int The current transaction isolation level. + * + * @throws DBALException */ public function getTransactionIsolation() { @@ -1226,6 +1232,8 @@ protected function _getNestedTransactionSavePointName() /** * @return bool + * + * @throws DBALException */ public function beginTransaction() { @@ -1314,6 +1322,8 @@ public function commit() /** * Commits all current nesting transactions. + * + * @throws DBALException */ private function commitAll(): void { @@ -1442,6 +1452,8 @@ public function rollbackSavepoint($savepoint) * Gets the wrapped driver connection. * * @return DriverConnection + * + * @throws DBALException */ public function getWrappedConnection() { @@ -1513,6 +1525,8 @@ public function isRollbackOnly() * @param string $type The name of the DBAL mapping type. * * @return mixed The converted value. + * + * @throws DBALException */ public function convertToDatabaseValue($value, $type) { @@ -1527,6 +1541,8 @@ public function convertToDatabaseValue($value, $type) * @param string $type The name of the DBAL mapping type. * * @return mixed The converted type. + * + * @throws DBALException */ public function convertToPHPValue($value, $type) { @@ -1540,6 +1556,8 @@ public function convertToPHPValue($value, $type) * @param DriverStatement $stmt The statement to bind the values to. * @param mixed[] $params The map/list of named/positional parameters. * @param int[]|string[] $types The parameter types (PDO binding types or DBAL mapping types). + * + * @throws DBALException */ private function _bindTypedValues(DriverStatement $stmt, array $params, array $types): void { @@ -1581,6 +1599,8 @@ private function _bindTypedValues(DriverStatement $stmt, array $params, array $t * @param int|string|null $type The type to bind (PDO or DBAL). * * @return mixed[] [0] => the (escaped) value, [1] => the binding type. + * + * @throws DBALException */ private function getBindingInfo($value, $type) { diff --git a/src/Connections/PrimaryReadReplicaConnection.php b/src/Connections/PrimaryReadReplicaConnection.php index 2bf961900bd..00ab615d472 100644 --- a/src/Connections/PrimaryReadReplicaConnection.php +++ b/src/Connections/PrimaryReadReplicaConnection.php @@ -98,6 +98,7 @@ class PrimaryReadReplicaConnection extends Connection * * @param mixed[] $params * + * @throws DBALException * @throws InvalidArgumentException */ public function __construct(array $params, Driver $driver, ?Configuration $config = null, ?EventManager $eventManager = null) diff --git a/src/Driver/PDO/Connection.php b/src/Driver/PDO/Connection.php index 7dc1821ed4e..f3c292c9b83 100644 --- a/src/Driver/PDO/Connection.php +++ b/src/Driver/PDO/Connection.php @@ -60,6 +60,8 @@ public function getServerVersion() } /** + * {@inheritDoc} + * * @return Statement */ public function prepare(string $sql): StatementInterface diff --git a/src/Event/Listeners/OracleSessionInit.php b/src/Event/Listeners/OracleSessionInit.php index 67fc78c3b6e..065c1162198 100644 --- a/src/Event/Listeners/OracleSessionInit.php +++ b/src/Event/Listeners/OracleSessionInit.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Event\Listeners; use Doctrine\Common\EventSubscriber; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; @@ -44,6 +45,8 @@ public function __construct(array $oracleSessionVars = []) /** * @return void + * + * @throws DBALException */ public function postConnect(ConnectionEventArgs $args) { diff --git a/src/Platforms/AbstractPlatform.php b/src/Platforms/AbstractPlatform.php index 65dbda3df83..332f10e77be 100644 --- a/src/Platforms/AbstractPlatform.php +++ b/src/Platforms/AbstractPlatform.php @@ -2165,6 +2165,8 @@ public function getColumnDeclarationListSQL(array $fields) * a string that defines the complete column * * @return string DBMS specific SQL code portion that should be used to declare the column. + * + * @throws DBALException */ public function getColumnDeclarationSQL($name, array $field) { diff --git a/src/Platforms/MySqlPlatform.php b/src/Platforms/MySqlPlatform.php index 3b305d91051..ac60b906082 100644 --- a/src/Platforms/MySqlPlatform.php +++ b/src/Platforms/MySqlPlatform.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Platforms; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; @@ -694,6 +695,8 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) /** * @return string[] + * + * @throws DBALException */ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $index) { @@ -733,6 +736,8 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde * @param TableDiff $diff The table diff to gather the SQL for. * * @return string[] + * + * @throws DBALException */ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff) { diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index 14e90545451..3ab4c6c7d22 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -963,6 +963,8 @@ public function getAlterTableSQL(TableDiff $diff) /** * @return string[]|false + * + * @throws DBALException */ private function getSimpleAlterTableSQL(TableDiff $diff) { diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 7b712dbb751..5171f7b9682 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Query; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Result; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\CompositeExpression; @@ -202,6 +203,8 @@ public function getState() * for insert, update and delete statements. * * @return Result|int + * + * @throws DBALException */ public function execute() { From 55475c067cd7d8cba1e52698986ff539db476246 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:34:47 -0700 Subject: [PATCH 04/10] Replace DBALException::invalidTableName() with InvalidTableName --- UPGRADE.md | 4 ++++ src/DBALException.php | 10 ---------- src/Schema/Exception/InvalidTableName.php | 20 ++++++++++++++++++++ src/Schema/Table.php | 5 +++-- 4 files changed, 27 insertions(+), 12 deletions(-) create mode 100644 src/Schema/Exception/InvalidTableName.php diff --git a/UPGRADE.md b/UPGRADE.md index 94d350ef2a6..e2cb4b9e090 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -35,6 +35,10 @@ The following classes have been renamed: 3. The `PDOSqlsrv\Connection` and `PDOSqlsrv\Statement` classes have been made final and no longer extend the corresponding PDO classes. 4. The `SQLSrv\LastInsertId` class has been made final. +## BC BREAK: Changes in wrapper-level exceptions + +1. `DBALException::invalidTableName()` has been replaced with the `InvalidTableName` class. + ## BC BREAK: Changes in driver-level exception handling 1. The `convertException()` method has been removed from the `Driver` interface. The logic of exception conversion has been moved to the `ExceptionConverter` interface. The drivers now must implement the `getExceptionConverter()` method. diff --git a/src/DBALException.php b/src/DBALException.php index c7f18be9acd..8ce51f0479a 100644 --- a/src/DBALException.php +++ b/src/DBALException.php @@ -126,16 +126,6 @@ public static function invalidDriverClass($driverClass) return new self("The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.'); } - /** - * @param string $tableName - * - * @return DBALException - */ - public static function invalidTableName($tableName) - { - return new self('Invalid table name specified: ' . $tableName); - } - /** * @param string $tableName * diff --git a/src/Schema/Exception/InvalidTableName.php b/src/Schema/Exception/InvalidTableName.php new file mode 100644 index 00000000000..440e60785b6 --- /dev/null +++ b/src/Schema/Exception/InvalidTableName.php @@ -0,0 +1,20 @@ +_setName($tableName); From c7da6c7fbf5de51e5f0f886f0d86dace1c0ba156 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:40:25 -0700 Subject: [PATCH 05/10] Throw DBALException instead of driver exception from listeners --- src/Event/Listeners/SQLSessionInit.php | 6 ++++-- tests/Events/SQLSessionInitTest.php | 2 +- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/Event/Listeners/SQLSessionInit.php b/src/Event/Listeners/SQLSessionInit.php index ea63cab43d7..7dc27574026 100644 --- a/src/Event/Listeners/SQLSessionInit.php +++ b/src/Event/Listeners/SQLSessionInit.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Event\Listeners; use Doctrine\Common\EventSubscriber; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; @@ -24,11 +25,12 @@ public function __construct($sql) /** * @return void + * + * @throws DBALException */ public function postConnect(ConnectionEventArgs $args) { - $conn = $args->getConnection(); - $conn->exec($this->sql); + $args->getConnection()->executeUpdate($this->sql); } /** diff --git a/tests/Events/SQLSessionInitTest.php b/tests/Events/SQLSessionInitTest.php index 242a11c00a6..eb5ab0a00ca 100644 --- a/tests/Events/SQLSessionInitTest.php +++ b/tests/Events/SQLSessionInitTest.php @@ -17,7 +17,7 @@ public function testPostConnect(): void { $connectionMock = $this->createMock(Connection::class); $connectionMock->expects(self::once()) - ->method('exec') + ->method('executeUpdate') ->with(self::equalTo("SET SEARCH_PATH TO foo, public, TIMEZONE TO 'Europe/Berlin'")); $eventArgs = new ConnectionEventArgs($connectionMock); From 93e615111d4c6c0e8fc4f8c8cb006dc92e60dbc7 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:41:00 -0700 Subject: [PATCH 06/10] Add missing exception annotation to the query builder --- src/Query/QueryBuilder.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 5171f7b9682..c276637311f 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -1162,6 +1162,8 @@ private function getSQLForSelect() /** * @return string[] + * + * @throws QueryException */ private function getFromClauses() { From 15bec73c4da25fc7fa5a926b5b4d8b334eaa8756 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:41:53 -0700 Subject: [PATCH 07/10] Add missing exception annotation to schema managers --- src/Schema/AbstractSchemaManager.php | 85 ++++++++++++++++++- src/Schema/DB2SchemaManager.php | 3 + src/Schema/OracleSchemaManager.php | 4 + src/Schema/PostgreSqlSchemaManager.php | 9 +- src/Schema/SQLServerSchemaManager.php | 4 + src/Schema/SqliteSchemaManager.php | 5 ++ .../AbstractSchemaSynchronizer.php | 3 + 7 files changed, 105 insertions(+), 8 deletions(-) diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index bf9182e5840..54d87159cad 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -3,7 +3,6 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\ConnectionException; use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs; use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs; @@ -93,6 +92,8 @@ public function tryMethod() * Lists the available databases for this connection. * * @return string[] + * + * @throws DBALException */ public function listDatabases() { @@ -107,6 +108,8 @@ public function listDatabases() * Returns a list of all namespaces in the current database. * * @return string[] + * + * @throws DBALException */ public function listNamespaceNames() { @@ -123,6 +126,8 @@ public function listNamespaceNames() * @param string|null $database * * @return Sequence[] + * + * @throws DBALException */ public function listSequences($database = null) { @@ -151,6 +156,8 @@ public function listSequences($database = null) * @param string|null $database * * @return Column[] + * + * @throws DBALException */ public function listTableColumns($table, $database = null) { @@ -173,6 +180,8 @@ public function listTableColumns($table, $database = null) * @param string $table The name of the table. * * @return Index[] + * + * @throws DBALException */ public function listTableIndexes($table) { @@ -191,6 +200,8 @@ public function listTableIndexes($table) * @param string|string[] $tableNames * * @return bool + * + * @throws DBALException */ public function tablesExist($tableNames) { @@ -203,6 +214,8 @@ public function tablesExist($tableNames) * Returns a list of all tables in the current database. * * @return string[] + * + * @throws DBALException */ public function listTableNames() { @@ -236,6 +249,8 @@ protected function filterAssetNames($assetNames) * Lists the tables for this connection. * * @return Table[] + * + * @throws DBALException */ public function listTables() { @@ -253,6 +268,8 @@ public function listTables() * @param string $tableName * * @return Table + * + * @throws DBALException */ public function listTableDetails($tableName) { @@ -271,6 +288,8 @@ public function listTableDetails($tableName) * Lists the views this connection has. * * @return View[] + * + * @throws DBALException */ public function listViews() { @@ -288,6 +307,8 @@ public function listViews() * @param string|null $database * * @return ForeignKeyConstraint[] + * + * @throws DBALException */ public function listTableForeignKeys($table, $database = null) { @@ -311,6 +332,8 @@ public function listTableForeignKeys($table, $database = null) * @param string $database The name of the database to drop. * * @return void + * + * @throws DBALException */ public function dropDatabase($database) { @@ -323,6 +346,8 @@ public function dropDatabase($database) * @param string $tableName The name of the table to drop. * * @return void + * + * @throws DBALException */ public function dropTable($tableName) { @@ -336,6 +361,8 @@ public function dropTable($tableName) * @param Table|string $table The name of the table. * * @return void + * + * @throws DBALException */ public function dropIndex($index, $table) { @@ -352,6 +379,8 @@ public function dropIndex($index, $table) * @param Table|string $table The name of the table. * * @return void + * + * @throws DBALException */ public function dropConstraint(Constraint $constraint, $table) { @@ -365,6 +394,8 @@ public function dropConstraint(Constraint $constraint, $table) * @param Table|string $table The name of the table with the foreign key. * * @return void + * + * @throws DBALException */ public function dropForeignKey($foreignKey, $table) { @@ -377,6 +408,8 @@ public function dropForeignKey($foreignKey, $table) * @param string $name The name of the sequence to drop. * * @return void + * + * @throws DBALException */ public function dropSequence($name) { @@ -389,6 +422,8 @@ public function dropSequence($name) * @param string $name The name of the view. * * @return void + * + * @throws DBALException */ public function dropView($name) { @@ -403,6 +438,8 @@ public function dropView($name) * @param string $database The name of the database to create. * * @return void + * + * @throws DBALException */ public function createDatabase($database) { @@ -413,6 +450,8 @@ public function createDatabase($database) * Creates a new table. * * @return void + * + * @throws DBALException */ public function createTable(Table $table) { @@ -427,7 +466,7 @@ public function createTable(Table $table) * * @return void * - * @throws ConnectionException If something fails at database level. + * @throws DBALException */ public function createSequence($sequence) { @@ -440,6 +479,8 @@ public function createSequence($sequence) * @param Table|string $table * * @return void + * + * @throws DBALException */ public function createConstraint(Constraint $constraint, $table) { @@ -452,6 +493,8 @@ public function createConstraint(Constraint $constraint, $table) * @param Table|string $table The name of the table on which the index is to be created. * * @return void + * + * @throws DBALException */ public function createIndex(Index $index, $table) { @@ -465,6 +508,8 @@ public function createIndex(Index $index, $table) * @param Table|string $table The name of the table on which the foreign key is to be created. * * @return void + * + * @throws DBALException */ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) { @@ -475,6 +520,8 @@ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) * Creates a new view. * * @return void + * + * @throws DBALException */ public function createView(View $view) { @@ -492,6 +539,8 @@ public function createView(View $view) * @param Table|string $table * * @return void + * + * @throws DBALException */ public function dropAndCreateConstraint(Constraint $constraint, $table) { @@ -505,6 +554,8 @@ public function dropAndCreateConstraint(Constraint $constraint, $table) * @param Table|string $table The name of the table on which the index is to be created. * * @return void + * + * @throws DBALException */ public function dropAndCreateIndex(Index $index, $table) { @@ -519,6 +570,8 @@ public function dropAndCreateIndex(Index $index, $table) * @param Table|string $table The name of the table on which the foreign key is to be created. * * @return void + * + * @throws DBALException */ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) { @@ -531,7 +584,7 @@ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table * * @return void * - * @throws ConnectionException If something fails at database level. + * @throws DBALException */ public function dropAndCreateSequence(Sequence $sequence) { @@ -543,6 +596,8 @@ public function dropAndCreateSequence(Sequence $sequence) * Drops and creates a new table. * * @return void + * + * @throws DBALException */ public function dropAndCreateTable(Table $table) { @@ -556,6 +611,8 @@ public function dropAndCreateTable(Table $table) * @param string $database The name of the database to create. * * @return void + * + * @throws DBALException */ public function dropAndCreateDatabase($database) { @@ -567,6 +624,8 @@ public function dropAndCreateDatabase($database) * Drops and creates a new view. * * @return void + * + * @throws DBALException */ public function dropAndCreateView(View $view) { @@ -580,6 +639,8 @@ public function dropAndCreateView(View $view) * Alters an existing tables schema. * * @return void + * + * @throws DBALException */ public function alterTable(TableDiff $tableDiff) { @@ -597,6 +658,8 @@ public function alterTable(TableDiff $tableDiff) * @param string $newName The new name of the table. * * @return void + * + * @throws DBALException */ public function renameTable($name, $newName) { @@ -700,6 +763,8 @@ protected function _getPortableTriggerDefinition($trigger) * @param mixed[][] $sequences * * @return Sequence[] + * + * @throws DBALException */ protected function _getPortableSequencesList($sequences) { @@ -734,6 +799,8 @@ protected function _getPortableSequenceDefinition($sequence) * @param mixed[][] $tableColumns * * @return Column[] + * + * @throws DBALException */ protected function _getPortableTableColumnList($table, $database, $tableColumns) { @@ -773,6 +840,8 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) * @param mixed[] $tableColumn * * @return Column + * + * @throws DBALException */ abstract protected function _getPortableTableColumnDefinition($tableColumn); @@ -783,6 +852,8 @@ abstract protected function _getPortableTableColumnDefinition($tableColumn); * @param string|null $tableName * * @return Index[] + * + * @throws DBALException */ protected function _getPortableTableIndexesList($tableIndexRows, $tableName = null) { @@ -959,6 +1030,8 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) * @param string[]|string $sql * * @return void + * + * @throws DBALException */ protected function _execSql($sql) { @@ -971,6 +1044,8 @@ protected function _execSql($sql) * Creates a schema instance for the current database. * * @return Schema + * + * @throws DBALException */ public function createSchema() { @@ -995,6 +1070,8 @@ public function createSchema() * Creates the configuration for this schema. * * @return SchemaConfig + * + * @throws DBALException */ public function createSchemaConfig() { @@ -1031,6 +1108,8 @@ public function createSchemaConfig() * returns the name of the currently connected database. * * @return string[] + * + * @throws DBALException */ public function getSchemaSearchPaths() { diff --git a/src/Schema/DB2SchemaManager.php b/src/Schema/DB2SchemaManager.php index e46fa47ec94..eee5ead1f1a 100644 --- a/src/Schema/DB2SchemaManager.php +++ b/src/Schema/DB2SchemaManager.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Schema; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Types\Type; @@ -37,6 +38,8 @@ public function listTableNames() /** * {@inheritdoc} + * + * @throws DBALException */ protected function _getPortableTableColumnDefinition($tableColumn) { diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index 6db4284fa84..27d2f8e8ba3 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -297,6 +297,8 @@ public function createDatabase($database) * @param string $table * * @return bool + * + * @throws DBALException */ public function dropAutoincrement($table) { @@ -347,6 +349,8 @@ private function getQuotedIdentifierName($identifier) * @param string $user The name of the user to kill sessions for. * * @return void + * + * @throws DBALException */ private function killUserSessions($user) { diff --git a/src/Schema/PostgreSqlSchemaManager.php b/src/Schema/PostgreSqlSchemaManager.php index ff2b53785cf..0f23947de53 100644 --- a/src/Schema/PostgreSqlSchemaManager.php +++ b/src/Schema/PostgreSqlSchemaManager.php @@ -2,6 +2,7 @@ namespace Doctrine\DBAL\Schema; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Types\Type; @@ -39,6 +40,8 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager * Gets all the existing schema names. * * @return string[] + * + * @throws DBALException */ public function getSchemaNames() { @@ -46,11 +49,7 @@ public function getSchemaNames() } /** - * Returns an array of schema search paths. - * - * This is a PostgreSQL only function. - * - * @return string[] + * {@inheritDoc} */ public function getSchemaSearchPaths() { diff --git a/src/Schema/SQLServerSchemaManager.php b/src/Schema/SQLServerSchemaManager.php index faa5f5a8167..00f6cb97da5 100644 --- a/src/Schema/SQLServerSchemaManager.php +++ b/src/Schema/SQLServerSchemaManager.php @@ -319,6 +319,8 @@ private function getColumnConstraintSQL($table, $column) * @param string $database The name of the database to close currently active connections for. * * @return void + * + * @throws DBALException */ private function closeActiveDatabaseConnections($database) { @@ -334,6 +336,8 @@ private function closeActiveDatabaseConnections($database) /** * @param string $tableName + * + * @throws DBALException */ public function listTableDetails($tableName): Table { diff --git a/src/Schema/SqliteSchemaManager.php b/src/Schema/SqliteSchemaManager.php index 638dcb9c74c..7667965a8e2 100644 --- a/src/Schema/SqliteSchemaManager.php +++ b/src/Schema/SqliteSchemaManager.php @@ -501,6 +501,9 @@ private function parseColumnCommentFromSQL(string $column, string $sql): ?string return $comment === '' ? null : $comment; } + /** + * @throws DBALException + */ private function getCreateTableSQL(string $table): string { $sql = $this->_conn->fetchOne( @@ -528,6 +531,8 @@ private function getCreateTableSQL(string $table): string } /** + * {@inheritDoc} + * * @param string $tableName */ public function listTableDetails($tableName): Table diff --git a/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php b/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php index 9b1974747e7..1a3cc95bce3 100644 --- a/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php +++ b/src/Schema/Synchronizer/AbstractSchemaSynchronizer.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Schema\Synchronizer; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Throwable; /** @@ -37,6 +38,8 @@ protected function processSqlSafely(array $sql) * @param string[] $sql * * @return void + * + * @throws DBALException */ protected function processSql(array $sql) { From d9f05fa9cf75ba793db00c20c17cd3d65a6bf38c Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:42:32 -0700 Subject: [PATCH 08/10] Add missing exception annotation to the schema classes --- src/Schema/Column.php | 4 ++++ src/Schema/Comparator.php | 6 ++++++ src/Schema/Schema.php | 14 ++++++++++++++ src/Schema/Table.php | 18 ++++++++++++++++++ src/Schema/Visitor/Visitor.php | 5 +++++ 5 files changed, 47 insertions(+) diff --git a/src/Schema/Column.php b/src/Schema/Column.php index 3d1a1994652..6657456a93c 100644 --- a/src/Schema/Column.php +++ b/src/Schema/Column.php @@ -58,6 +58,8 @@ class Column extends AbstractAsset * * @param string $columnName * @param mixed[] $options + * + * @throws SchemaException */ public function __construct($columnName, Type $type, array $options = []) { @@ -70,6 +72,8 @@ public function __construct($columnName, Type $type, array $options = []) * @param mixed[] $options * * @return Column + * + * @throws SchemaException */ public function setOptions(array $options) { diff --git a/src/Schema/Comparator.php b/src/Schema/Comparator.php index ed8f7f510d2..1561c06d8a1 100644 --- a/src/Schema/Comparator.php +++ b/src/Schema/Comparator.php @@ -22,6 +22,8 @@ class Comparator { /** * @return SchemaDiff + * + * @throws SchemaException */ public static function compareSchemas(Schema $fromSchema, Schema $toSchema) { @@ -38,6 +40,8 @@ public static function compareSchemas(Schema $fromSchema, Schema $toSchema) * stored in $toSchema. * * @return SchemaDiff + * + * @throws SchemaException */ public function compare(Schema $fromSchema, Schema $toSchema) { @@ -188,6 +192,8 @@ public function diffSequence(Sequence $sequence1, Sequence $sequence2) * If there are no differences this method returns the boolean false. * * @return TableDiff|false + * + * @throws SchemaException */ public function diffTable(Table $table1, Table $table2) { diff --git a/src/Schema/Schema.php b/src/Schema/Schema.php index ae4c67cc5df..4ac62f9e814 100644 --- a/src/Schema/Schema.php +++ b/src/Schema/Schema.php @@ -58,6 +58,8 @@ class Schema extends AbstractAsset * @param Table[] $tables * @param Sequence[] $sequences * @param string[] $namespaces + * + * @throws SchemaException */ public function __construct( array $tables = [], @@ -316,6 +318,8 @@ public function createNamespace($namespaceName) * @param string $tableName * * @return Table + * + * @throws SchemaException */ public function createTable($tableName) { @@ -336,6 +340,8 @@ public function createTable($tableName) * @param string $newTableName * * @return Schema + * + * @throws SchemaException */ public function renameTable($oldTableName, $newTableName) { @@ -354,6 +360,8 @@ public function renameTable($oldTableName, $newTableName) * @param string $tableName * * @return Schema + * + * @throws SchemaException */ public function dropTable($tableName) { @@ -372,6 +380,8 @@ public function dropTable($tableName) * @param int $initialValue * * @return Sequence + * + * @throws SchemaException */ public function createSequence($sequenceName, $allocationSize = 1, $initialValue = 1) { @@ -422,6 +432,8 @@ public function toDropSql(AbstractPlatform $platform) /** * @return string[] + * + * @throws SchemaException */ public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) { @@ -433,6 +445,8 @@ public function getMigrateToSql(Schema $toSchema, AbstractPlatform $platform) /** * @return string[] + * + * @throws SchemaException */ public function getMigrateFromSql(Schema $fromSchema, AbstractPlatform $platform) { diff --git a/src/Schema/Table.php b/src/Schema/Table.php index b161ff87a15..78ae79f2af0 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -104,6 +104,8 @@ protected function _getMaxIdentifierLength() * @param string|false $indexName * * @return self + * + * @throws SchemaException */ public function setPrimaryKey(array $columnNames, $indexName = false) { @@ -128,6 +130,8 @@ public function setPrimaryKey(array $columnNames, $indexName = false) * @param mixed[] $options * * @return self + * + * @throws SchemaException */ public function addIndex(array $columnNames, $indexName = null, array $flags = [], array $options = []) { @@ -146,6 +150,8 @@ public function addIndex(array $columnNames, $indexName = null, array $flags = [ * Drops the primary key from this table. * * @return void + * + * @throws SchemaException */ public function dropPrimaryKey() { @@ -182,6 +188,8 @@ public function dropIndex($indexName) * @param mixed[] $options * * @return self + * + * @throws SchemaException */ public function addUniqueIndex(array $columnNames, $indexName = null, array $options = []) { @@ -293,6 +301,8 @@ private function _createIndex(array $columnNames, $indexName, $isUnique, $isPrim * @param mixed[] $options * * @return Column + * + * @throws SchemaException */ public function addColumn($columnName, $typeName, array $options = []) { @@ -310,6 +320,8 @@ public function addColumn($columnName, $typeName, array $options = []) * @param mixed[] $options * * @return self + * + * @throws SchemaException */ public function changeColumn($columnName, array $options) { @@ -346,6 +358,8 @@ public function dropColumn($columnName) * @param string|null $name * * @return self + * + * @throws SchemaException */ public function addForeignKeyConstraint($foreignTable, array $localColumnNames, array $foreignColumnNames, array $options = [], $name = null) { @@ -452,6 +466,8 @@ protected function _addIndex(Index $indexCandidate) /** * @return void + * + * @throws SchemaException */ protected function _addForeignKeyConstraint(ForeignKeyConstraint $constraint) { @@ -745,6 +761,8 @@ public function getOptions() /** * @return void + * + * @throws SchemaException */ public function visit(Visitor $visitor) { diff --git a/src/Schema/Visitor/Visitor.php b/src/Schema/Visitor/Visitor.php index 05c842830c5..0b1c87d54b5 100644 --- a/src/Schema/Visitor/Visitor.php +++ b/src/Schema/Visitor/Visitor.php @@ -6,6 +6,7 @@ use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; @@ -16,6 +17,8 @@ interface Visitor { /** * @return void + * + * @throws SchemaException */ public function acceptSchema(Schema $schema); @@ -31,6 +34,8 @@ public function acceptColumn(Table $table, Column $column); /** * @return void + * + * @throws SchemaException */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint); From ee4033d323a7f3708442b8887f08b680bc70caf1 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:45:50 -0700 Subject: [PATCH 09/10] Add missing exception annotation to the console tools --- src/Tools/Console/Command/ReservedWordsCommand.php | 3 +++ src/Tools/Console/Command/RunSqlCommand.php | 3 +++ src/Tools/Console/ConsoleRunner.php | 3 +++ 3 files changed, 9 insertions(+) diff --git a/src/Tools/Console/Command/ReservedWordsCommand.php b/src/Tools/Console/Command/ReservedWordsCommand.php index 9cda438b376..01d11f8be6a 100644 --- a/src/Tools/Console/Command/ReservedWordsCommand.php +++ b/src/Tools/Console/Command/ReservedWordsCommand.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Tools\Console\Command; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\Keywords\DB2Keywords; use Doctrine\DBAL\Platforms\Keywords\MariaDb102Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords; @@ -113,6 +114,8 @@ protected function configure() /** * {@inheritdoc} + * + * @throws DBALException */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/src/Tools/Console/Command/RunSqlCommand.php b/src/Tools/Console/Command/RunSqlCommand.php index d32993a5a33..f1b1483aae5 100644 --- a/src/Tools/Console/Command/RunSqlCommand.php +++ b/src/Tools/Console/Command/RunSqlCommand.php @@ -3,6 +3,7 @@ namespace Doctrine\DBAL\Tools\Console\Command; use Doctrine\DBAL\Connection; +use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Tools\Console\ConnectionProvider; use Doctrine\DBAL\Tools\Dumper; use LogicException; @@ -57,6 +58,8 @@ protected function configure() /** * {@inheritdoc} + * + * @throws DBALException */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/src/Tools/Console/ConsoleRunner.php b/src/Tools/Console/ConsoleRunner.php index 8637afdc6a6..28abadac564 100644 --- a/src/Tools/Console/ConsoleRunner.php +++ b/src/Tools/Console/ConsoleRunner.php @@ -4,6 +4,7 @@ use Doctrine\DBAL\Tools\Console\Command\ReservedWordsCommand; use Doctrine\DBAL\Tools\Console\Command\RunSqlCommand; +use Exception; use PackageVersions\Versions; use Symfony\Component\Console\Application; use Symfony\Component\Console\Command\Command; @@ -19,6 +20,8 @@ class ConsoleRunner * @param Command[] $commands * * @return void + * + * @throws Exception */ public static function run(ConnectionProvider $connectionProvider, $commands = []) { From 06a8fac5ab96997fa1d080b26f50988240e56d27 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 9 Jul 2020 22:46:21 -0700 Subject: [PATCH 10/10] Add missing ConversionException to the Type classes --- src/Types/Type.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Types/Type.php b/src/Types/Type.php index df65acc6848..bb958e61577 100644 --- a/src/Types/Type.php +++ b/src/Types/Type.php @@ -64,6 +64,8 @@ final public function __construct() * @param AbstractPlatform $platform The currently used database platform. * * @return mixed The database representation of the value. + * + * @throws ConversionException */ public function convertToDatabaseValue($value, AbstractPlatform $platform) { @@ -78,6 +80,8 @@ public function convertToDatabaseValue($value, AbstractPlatform $platform) * @param AbstractPlatform $platform The currently used database platform. * * @return mixed The PHP representation of the value. + * + * @throws ConversionException */ public function convertToPHPValue($value, AbstractPlatform $platform) {