From 4bc45693dc355d57e9173f50b0ac5c859d4ae972 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Wed, 26 Aug 2020 21:28:13 -0700 Subject: [PATCH 01/18] Update PHPStan to 0.12.40 --- composer.json | 2 +- composer.lock | 20 ++++++++++++-------- phpstan.neon.dist | 11 +---------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/composer.json b/composer.json index 9d04f559217..0c61fc462b0 100644 --- a/composer.json +++ b/composer.json @@ -41,7 +41,7 @@ "doctrine/coding-standard": "^8.1", "jetbrains/phpstorm-stubs": "^2019.1", "nikic/php-parser": "^4.4", - "phpstan/phpstan": "^0.12.31", + "phpstan/phpstan": "^0.12.40", "phpunit/phpunit": "^8.5.5", "psalm/plugin-phpunit": "^0.10.0", "symfony/console": "^2.0.5|^3.0|^4.0|^5.0", diff --git a/composer.lock b/composer.lock index d364e0a6cb5..60d0bcc18c4 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "c7a5a6e253d55b762c8113554a570902", + "content-hash": "0f85745785af604940cdf6c65474abe0", "packages": [ { "name": "doctrine/cache", @@ -1361,20 +1361,20 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.31", + "version": "0.12.40", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d" + "reference": "dce7293ad7b59fc09a9ab9b0b5b44902c092ca17" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/776c8056b401e1b67f277b9e9fb334d1a274671d", - "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/dce7293ad7b59fc09a9ab9b0b5b44902c092ca17", + "reference": "dce7293ad7b59fc09a9ab9b0b5b44902c092ca17", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -1399,6 +1399,10 @@ "MIT" ], "description": "PHPStan - PHP Static Analysis Tool", + "support": { + "issues": "https://github.com/phpstan/phpstan/issues", + "source": "https://github.com/phpstan/phpstan/tree/0.12.40" + }, "funding": [ { "url": "https://github.com/ondrejmirtes", @@ -1413,7 +1417,7 @@ "type": "tidelift" } ], - "time": "2020-06-24T20:55:29+00:00" + "time": "2020-08-26T19:06:20+00:00" }, { "name": "phpunit/php-code-coverage", @@ -3307,5 +3311,5 @@ "platform-overrides": { "php": "7.2.0" }, - "plugin-api-version": "1.1.0" + "plugin-api-version": "2.0.0" } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 15a76e3e972..79a126fea99 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -22,10 +22,6 @@ parameters: message: '~^Call to private method sqliteCreateFunction\(\) of parent class PDO\.$~' path: %currentWorkingDirectory%/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php - # https://github.com/phpstan/phpstan/issues/2857 - # TODO: remove in 4.0.0 - - '~^Parameter #2 \$registeredAliases of static method Doctrine\\DBAL\\Query\\QueryException::nonUniqueAlias\(\) expects array, array given\.\z~' - # legacy variadic-like signature # TODO: remove in 3.0.0 - '~^Method Doctrine\\DBAL(\\.*)?Connection::query\(\) invoked with \d+ parameters?, 0 required\.\z~' @@ -48,11 +44,6 @@ parameters: message: '~^Call to function in_array\(\) with arguments Doctrine\\DBAL\\Schema\\Column, array and true will always evaluate to false\.$~' path: %currentWorkingDirectory%/lib/Doctrine/DBAL/Schema/Table.php - # https://github.com/phpstan/phpstan/issues/3133 - - - message: '~^Cannot cast array\|bool\|string\|null to int\.$~' - path: %currentWorkingDirectory%/lib/Doctrine/DBAL/Tools/Console/Command/RunSqlCommand.php - # False Positive - '~Strict comparison using === between 1 and 2 will always evaluate to false~' @@ -116,7 +107,7 @@ parameters: - %currentWorkingDirectory%/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php - - message: '~Method Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Connection\:\:lastInsertId\(\) should return string but returns string\|false\|null\.~' + message: '~Method Doctrine\\DBAL\\Driver\\PDOSqlsrv\\Connection\:\:lastInsertId\(\) should return string but returns int\|string\|false\|null\.~' paths: - %currentWorkingDirectory%/lib/Doctrine/DBAL/Driver/PDOSqlsrv/Connection.php From 78547c770e4e2e5267801e16ebc02e59c8c39283 Mon Sep 17 00:00:00 2001 From: "piotr.knap" Date: Sat, 29 Aug 2020 21:22:43 +0200 Subject: [PATCH 02/18] use proper case for mssql names Rename - sp_RENAME to sp_rename; - SysObjects to sysobjects; - SysColumns to syscolumns. Fixes issues with case sensitive collation on mssql database. --- .../DBAL/Platforms/SQLServerPlatform.php | 6 +-- .../DBAL/Schema/SQLServerSchemaManager.php | 10 ++--- .../AbstractSQLServerPlatformTestCase.php | 42 +++++++++---------- 3 files changed, 29 insertions(+), 29 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 30a815dc668..cf48dc7e98f 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -574,7 +574,7 @@ public function getAlterTableSQL(TableDiff $diff) $oldColumnName = new Identifier($oldColumnName); - $sql[] = "sp_RENAME '" . + $sql[] = "sp_rename '" . $diff->getName($this)->getQuotedName($this) . '.' . $oldColumnName->getQuotedName($this) . "', '" . $column->getQuotedName($this) . "', 'COLUMN'"; @@ -605,7 +605,7 @@ public function getAlterTableSQL(TableDiff $diff) $newName = $diff->getNewName(); if ($newName !== false) { - $sql[] = "sp_RENAME '" . $diff->getName($this)->getQuotedName($this) . "', '" . $newName->getName() . "'"; + $sql[] = "sp_rename '" . $diff->getName($this)->getQuotedName($this) . "', '" . $newName->getName() . "'"; /** * Rename table's default constraints names @@ -784,7 +784,7 @@ protected function getDropColumnCommentSQL($tableName, $columnName) protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) { return [sprintf( - "EXEC sp_RENAME N'%s.%s', N'%s', N'INDEX'", + "EXEC sp_rename N'%s.%s', N'%s', N'INDEX'", $tableName, $oldIndexName, $index->getQuotedName($this) diff --git a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php index cd2b9d2f96c..d06f1b1d782 100644 --- a/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SQLServerSchemaManager.php @@ -302,11 +302,11 @@ public function alterTable(TableDiff $tableDiff) */ private function getColumnConstraintSQL($table, $column) { - return "SELECT SysObjects.[Name] - FROM SysObjects INNER JOIN (SELECT [Name],[ID] FROM SysObjects WHERE XType = 'U') AS Tab - ON Tab.[ID] = Sysobjects.[Parent_Obj] - INNER JOIN sys.default_constraints DefCons ON DefCons.[object_id] = Sysobjects.[ID] - INNER JOIN SysColumns Col ON Col.[ColID] = DefCons.[parent_column_id] AND Col.[ID] = Tab.[ID] + return "SELECT sysobjects.[Name] + FROM sysobjects INNER JOIN (SELECT [Name],[ID] FROM sysobjects WHERE XType = 'U') AS Tab + ON Tab.[ID] = sysobjects.[Parent_Obj] + INNER JOIN sys.default_constraints DefCons ON DefCons.[object_id] = sysobjects.[ID] + INNER JOIN syscolumns Col ON Col.[ColID] = DefCons.[parent_column_id] AND Col.[ID] = Tab.[ID] WHERE Col.[Name] = " . $this->_conn->quote($column) . ' AND Tab.[Name] = ' . $this->_conn->quote($table) . ' ORDER BY Col.[Name]'; } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 19fb48037aa..6c166ac2dff 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -48,7 +48,7 @@ public function getGenerateAlterTableSql(): array "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_78240498 DEFAULT 'def' FOR baz", 'ALTER TABLE mytable ALTER COLUMN bloo BIT NOT NULL', "ALTER TABLE mytable ADD CONSTRAINT DF_6B2BD609_CECED971 DEFAULT '0' FOR bloo", - "sp_RENAME 'mytable', 'userlist'", + "sp_rename 'mytable', 'userlist'", "DECLARE @sql NVARCHAR(MAX) = N''; " . "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', N''' " . "+ REPLACE(dc.name, '6B2BD609', 'E2B58069') + ''', ''OBJECT'';' " . @@ -984,7 +984,7 @@ public function testGeneratesAlterTableSQLWithColumnComments(): void self::assertEquals( [ // Renamed columns. - "sp_RENAME 'mytable.comment_float_0', 'comment_double_0', 'COLUMN'", + "sp_rename 'mytable.comment_float_0', 'comment_double_0', 'COLUMN'", // Added columns. 'ALTER TABLE mytable ADD added_comment_none INT NOT NULL', @@ -1164,7 +1164,7 @@ public function testReturnsBinaryTypeLongerThanMaxDeclarationSQL(): void */ protected function getAlterTableRenameIndexSQL(): array { - return ["EXEC sp_RENAME N'mytable.idx_foo', N'idx_bar', N'INDEX'"]; + return ["EXEC sp_rename N'mytable.idx_foo', N'idx_bar', N'INDEX'"]; } /** @@ -1173,8 +1173,8 @@ protected function getAlterTableRenameIndexSQL(): array protected function getQuotedAlterTableRenameIndexSQL(): array { return [ - "EXEC sp_RENAME N'[table].[create]', N'[select]', N'INDEX'", - "EXEC sp_RENAME N'[table].[foo]', N'[bar]', N'INDEX'", + "EXEC sp_rename N'[table].[create]', N'[select]', N'INDEX'", + "EXEC sp_rename N'[table].[foo]', N'[bar]', N'INDEX'", ]; } @@ -1223,15 +1223,15 @@ public function testChangeColumnsTypeWithDefaultValue(): void protected function getQuotedAlterTableRenameColumnSQL(): array { return [ - "sp_RENAME 'mytable.unquoted1', 'unquoted', 'COLUMN'", - "sp_RENAME 'mytable.unquoted2', '[where]', 'COLUMN'", - "sp_RENAME 'mytable.unquoted3', '[foo]', 'COLUMN'", - "sp_RENAME 'mytable.[create]', 'reserved_keyword', 'COLUMN'", - "sp_RENAME 'mytable.[table]', '[from]', 'COLUMN'", - "sp_RENAME 'mytable.[select]', '[bar]', 'COLUMN'", - "sp_RENAME 'mytable.quoted1', 'quoted', 'COLUMN'", - "sp_RENAME 'mytable.quoted2', '[and]', 'COLUMN'", - "sp_RENAME 'mytable.quoted3', '[baz]', 'COLUMN'", + "sp_rename 'mytable.unquoted1', 'unquoted', 'COLUMN'", + "sp_rename 'mytable.unquoted2', '[where]', 'COLUMN'", + "sp_rename 'mytable.unquoted3', '[foo]', 'COLUMN'", + "sp_rename 'mytable.[create]', 'reserved_keyword', 'COLUMN'", + "sp_rename 'mytable.[table]', '[from]', 'COLUMN'", + "sp_rename 'mytable.[select]', '[bar]', 'COLUMN'", + "sp_rename 'mytable.quoted1', 'quoted', 'COLUMN'", + "sp_rename 'mytable.quoted2', '[and]', 'COLUMN'", + "sp_rename 'mytable.quoted3', '[baz]', 'COLUMN'", ]; } @@ -1248,7 +1248,7 @@ protected function getQuotedAlterTableChangeColumnLengthSQL(): array */ protected function getAlterTableRenameIndexInSchemaSQL(): array { - return ["EXEC sp_RENAME N'myschema.mytable.idx_foo', N'idx_bar', N'INDEX'"]; + return ["EXEC sp_rename N'myschema.mytable.idx_foo', N'idx_bar', N'INDEX'"]; } /** @@ -1257,8 +1257,8 @@ protected function getAlterTableRenameIndexInSchemaSQL(): array protected function getQuotedAlterTableRenameIndexInSchemaSQL(): array { return [ - "EXEC sp_RENAME N'[schema].[table].[create]', N'[select]', N'INDEX'", - "EXEC sp_RENAME N'[schema].[table].[foo]', N'[bar]', N'INDEX'", + "EXEC sp_rename N'[schema].[table].[create]', N'[select]', N'INDEX'", + "EXEC sp_rename N'[schema].[table].[foo]', N'[bar]', N'INDEX'", ]; } @@ -1507,7 +1507,7 @@ public function testReturnsGuidTypeDeclarationSQL(): void public function getAlterTableRenameColumnSQL(): array { return [ - "sp_RENAME 'foo.bar', 'baz', 'COLUMN'", + "sp_rename 'foo.bar', 'baz', 'COLUMN'", 'ALTER TABLE foo DROP CONSTRAINT DF_8C736521_76FF8CAA', 'ALTER TABLE foo ADD CONSTRAINT DF_8C736521_78240498 DEFAULT 666 FOR baz', ]; @@ -1521,11 +1521,11 @@ protected function getQuotesTableIdentifiersInAlterTableSQL(): array return [ 'ALTER TABLE [foo] DROP CONSTRAINT fk1', 'ALTER TABLE [foo] DROP CONSTRAINT fk2', - "sp_RENAME '[foo].id', 'war', 'COLUMN'", + "sp_rename '[foo].id', 'war', 'COLUMN'", 'ALTER TABLE [foo] ADD bloo INT NOT NULL', 'ALTER TABLE [foo] DROP COLUMN baz', 'ALTER TABLE [foo] ALTER COLUMN bar INT', - "sp_RENAME '[foo]', 'table'", + "sp_rename '[foo]', 'table'", "DECLARE @sql NVARCHAR(MAX) = N''; " . "SELECT @sql += N'EXEC sp_rename N''' + dc.name + ''', " . "N''' + REPLACE(dc.name, '8C736521', 'F6298F46') + ''', ''OBJECT'';' " . @@ -1591,7 +1591,7 @@ protected function getAlterStringToFixedStringSQL(): array */ protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL(): array { - return ["EXEC sp_RENAME N'mytable.idx_foo', N'idx_foo_renamed', N'INDEX'"]; + return ["EXEC sp_rename N'mytable.idx_foo', N'idx_foo_renamed', N'INDEX'"]; } public function testModifyLimitQueryWithTopNSubQueryWithOrderBy(): void From 70e1f95cec4a0b8d90513b680381c338dbcfdb41 Mon Sep 17 00:00:00 2001 From: "piotr.knap" Date: Sat, 29 Aug 2020 21:19:46 +0200 Subject: [PATCH 03/18] Add Travis job with case sensitive mssql database --- .travis.yml | 9 ++++++++- tests/travis/install-mssql-cs.sh | 19 +++++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) create mode 100644 tests/travis/install-mssql-cs.sh diff --git a/.travis.yml b/.travis.yml index 72f3f85c973..201ff5ff982 100644 --- a/.travis.yml +++ b/.travis.yml @@ -219,7 +219,14 @@ jobs: - bash ./tests/travis/install-sqlsrv-dependencies.sh - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - bash ./tests/travis/install-mssql.sh - + - stage: Test + php: 7.4 + env: DB=pdo_sqlsrv + sudo: required + before_script: + - bash ./tests/travis/install-sqlsrv-dependencies.sh + - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh + - bash ./tests/travis/install-mssql-cs.sh - stage: Test if: type = cron php: 7.2 diff --git a/tests/travis/install-mssql-cs.sh b/tests/travis/install-mssql-cs.sh new file mode 100644 index 00000000000..a31c17c0f05 --- /dev/null +++ b/tests/travis/install-mssql-cs.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +set -ex + +echo Setting up Microsoft SQL Server + +sudo docker pull microsoft/mssql-server-linux:2017-latest +sudo docker run \ + -e 'ACCEPT_EULA=Y' \ + -e 'SA_PASSWORD=Doctrine2018' \ + -e 'MSSQL_COLLATION=Latin1_General_100_CS_AS' \ + -p 127.0.0.1:1433:1433 \ + --name mssql \ + -d \ + microsoft/mssql-server-linux:2017-latest + +sudo docker exec -i mssql bash <<< 'until echo quit | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -l 1 -U sa -P Doctrine2018 > /dev/null 2>&1 ; do sleep 1; done' + +echo SQL Server started From 05d55f640cd774c6dea7ef6b1522f50ea6a69d97 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 30 Aug 2020 10:22:13 -0700 Subject: [PATCH 04/18] Parametrize SQL Server installation script, add handling of MSSQL_COLLATION --- .travis.yml | 2 +- tests/travis/install-mssql-cs.sh | 19 ------------------- tests/travis/install-mssql.sh | 1 + 3 files changed, 2 insertions(+), 20 deletions(-) delete mode 100644 tests/travis/install-mssql-cs.sh diff --git a/.travis.yml b/.travis.yml index 201ff5ff982..5af6a54ffbc 100644 --- a/.travis.yml +++ b/.travis.yml @@ -221,7 +221,7 @@ jobs: - bash ./tests/travis/install-mssql.sh - stage: Test php: 7.4 - env: DB=pdo_sqlsrv + env: DB=pdo_sqlsrv MSSQL_COLLATION=Latin1_General_100_CS_AS sudo: required before_script: - bash ./tests/travis/install-sqlsrv-dependencies.sh diff --git a/tests/travis/install-mssql-cs.sh b/tests/travis/install-mssql-cs.sh deleted file mode 100644 index a31c17c0f05..00000000000 --- a/tests/travis/install-mssql-cs.sh +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/env bash - -set -ex - -echo Setting up Microsoft SQL Server - -sudo docker pull microsoft/mssql-server-linux:2017-latest -sudo docker run \ - -e 'ACCEPT_EULA=Y' \ - -e 'SA_PASSWORD=Doctrine2018' \ - -e 'MSSQL_COLLATION=Latin1_General_100_CS_AS' \ - -p 127.0.0.1:1433:1433 \ - --name mssql \ - -d \ - microsoft/mssql-server-linux:2017-latest - -sudo docker exec -i mssql bash <<< 'until echo quit | /opt/mssql-tools/bin/sqlcmd -S 127.0.0.1 -l 1 -U sa -P Doctrine2018 > /dev/null 2>&1 ; do sleep 1; done' - -echo SQL Server started diff --git a/tests/travis/install-mssql.sh b/tests/travis/install-mssql.sh index e4ce49b2c4a..d17058e3455 100644 --- a/tests/travis/install-mssql.sh +++ b/tests/travis/install-mssql.sh @@ -8,6 +8,7 @@ sudo docker pull microsoft/mssql-server-linux:2017-latest sudo docker run \ -e 'ACCEPT_EULA=Y' \ -e 'SA_PASSWORD=Doctrine2018' \ + -e "MSSQL_COLLATION=${MSSQL_COLLATION:-Latin1_General_100_CI_AS}" \ -p 127.0.0.1:1433:1433 \ --name mssql \ -d \ From 354322ec82459b809819d72b1ab50ad23e6ae35b Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 30 Aug 2020 10:22:53 -0700 Subject: [PATCH 05/18] Reuse PHP 7.4 sqlsrv and pdo_sqlsrv builds for case-sensitive collation testing --- .travis.yml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/.travis.yml b/.travis.yml index 5af6a54ffbc..ff2b351183e 100644 --- a/.travis.yml +++ b/.travis.yml @@ -205,20 +205,12 @@ jobs: env: DB=sqlite - stage: Test php: 7.4 - env: DB=sqlsrv + env: DB=sqlsrv MSSQL_COLLATION=Latin1_General_100_CS_AS sudo: required before_script: - bash ./tests/travis/install-sqlsrv-dependencies.sh - bash ./tests/travis/install-mssql-sqlsrv.sh - bash ./tests/travis/install-mssql.sh - - stage: Test - php: 7.4 - env: DB=pdo_sqlsrv - sudo: required - before_script: - - bash ./tests/travis/install-sqlsrv-dependencies.sh - - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - - bash ./tests/travis/install-mssql.sh - stage: Test php: 7.4 env: DB=pdo_sqlsrv MSSQL_COLLATION=Latin1_General_100_CS_AS @@ -226,7 +218,7 @@ jobs: before_script: - bash ./tests/travis/install-sqlsrv-dependencies.sh - bash ./tests/travis/install-mssql-pdo_sqlsrv.sh - - bash ./tests/travis/install-mssql-cs.sh + - bash ./tests/travis/install-mssql.sh - stage: Test if: type = cron php: 7.2 From f27faa31ff02d7bee982172c59bf87a673341016 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sun, 30 Aug 2020 10:19:34 -0700 Subject: [PATCH 06/18] Reuse MySQL 8 build for TLS testing --- .travis.yml | 3 --- 1 file changed, 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index ff2b351183e..82b463431d6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -182,9 +182,6 @@ jobs: - stage: Test php: 7.4 env: DB=mysql.docker IMAGE=mysql:8.0 - - stage: Test - php: 7.4 - env: DB=mysqli.docker IMAGE=mysql:8.0 - stage: Test php: 7.4 env: DB=mysqli-tls.docker IMAGE=mysql:8.0 TLS=yes From 03ca23afc2ee062f5d3e32426ad37c34a4770dcf Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Tue, 1 Sep 2020 18:35:42 -0700 Subject: [PATCH 07/18] Release 2.10.3 --- lib/Doctrine/DBAL/Version.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/Doctrine/DBAL/Version.php b/lib/Doctrine/DBAL/Version.php index f9304d9662e..8036de07f98 100644 --- a/lib/Doctrine/DBAL/Version.php +++ b/lib/Doctrine/DBAL/Version.php @@ -14,7 +14,7 @@ class Version /** * Current Doctrine Version. */ - public const VERSION = '2.10.3-DEV'; + public const VERSION = '2.10.3'; /** * Compares a Doctrine version with the current one. From 7570aeb83efb7efda1714436fe1af5cb9baaaa5d Mon Sep 17 00:00:00 2001 From: Igor Scheller Date: Wed, 2 Sep 2020 18:17:56 +0200 Subject: [PATCH 08/18] SQLite: Fix wrongly detected reference constraint name on schema change If there is no constraint name defined the listTableForeignKeys should not invent a new one as a numerical id has no deeper meaning and makes schema changes adding information that was not there before. Using `null` is an apropriate value as its already in use when handling not existing fk names. --- lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php | 2 +- .../Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 17cb5efac3c..7819863c405 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -149,7 +149,7 @@ public function listTableForeignKeys($table, $database = null) $id = $value['id']; $tableForeignKeys[$key] = array_merge($tableForeignKeys[$key], [ - 'constraint_name' => isset($names[$id]) && $names[$id] !== '' ? $names[$id] : $id, + 'constraint_name' => isset($names[$id]) && $names[$id] !== '' ? $names[$id] : null, 'deferrable' => isset($deferrable[$id]) && strtolower($deferrable[$id]) === 'deferrable', 'deferred' => isset($deferred[$id]) && strtolower($deferred[$id]) === 'deferred', ]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index 6764b1ed173..8f911867bb4 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -101,7 +101,7 @@ public function testListForeignKeysFromExistingDatabase(): void ['parent'], 'user', ['id'], - '1', + null, ['onUpdate' => 'NO ACTION', 'onDelete' => 'CASCADE', 'deferrable' => false, 'deferred' => false] ), new Schema\ForeignKeyConstraint( From 6c2d6292023436041bfbea371a58fbe6f8ca3f67 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 3 Sep 2020 07:02:00 -0700 Subject: [PATCH 09/18] Remove redundant condition --- lib/Doctrine/DBAL/Exception/DriverException.php | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/lib/Doctrine/DBAL/Exception/DriverException.php b/lib/Doctrine/DBAL/Exception/DriverException.php index c0dd5d89d8a..b8953390713 100644 --- a/lib/Doctrine/DBAL/Exception/DriverException.php +++ b/lib/Doctrine/DBAL/Exception/DriverException.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; -use Exception; /** * Base class for all errors detected in the driver. @@ -26,13 +25,7 @@ class DriverException extends DBALException */ public function __construct($message, DeprecatedDriverException $driverException) { - $exception = null; - - if ($driverException instanceof Exception) { - $exception = $driverException; - } - - parent::__construct($message, 0, $exception); + parent::__construct($message, 0, $driverException); $this->driverException = $driverException; } From a2ec3abdd800584e557762e53aa743dac8e9ebed Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 3 Sep 2020 07:02:00 -0700 Subject: [PATCH 10/18] Clean up exception handling in Connection --- lib/Doctrine/DBAL/Connection.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 507a5170d10..6c4dea7fd22 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -20,7 +20,6 @@ use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Types\Type; -use Exception; use Throwable; use Traversable; @@ -406,7 +405,7 @@ private function detectDatabasePlatform(): void * * @return string|null * - * @throws Exception + * @throws Throwable */ private function getDatabasePlatformVersion() { @@ -1470,7 +1469,6 @@ public function lastInsertId($name = null) * * @return mixed The value returned by $func * - * @throws Exception * @throws Throwable */ public function transactional(Closure $func) @@ -1481,10 +1479,6 @@ public function transactional(Closure $func) $this->commit(); return $res; - } catch (Exception $e) { - $this->rollBack(); - - throw $e; } catch (Throwable $e) { $this->rollBack(); From 16d5861f70e5c4f4c62f32c6ab89bb66cd3f34a9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 3 Sep 2020 23:03:05 +0200 Subject: [PATCH 11/18] Reuse global coding standard workflow This is part of an effort to standardize workflows accross repositories. We do not have a way to do it automatically yet, but it is still nice to have one reference repository. --- .github/workflows/coding-standards.yml | 38 ++++++++++++++++++++ .github/workflows/continuous-integration.yml | 33 ----------------- 2 files changed, 38 insertions(+), 33 deletions(-) create mode 100644 .github/workflows/coding-standards.yml diff --git a/.github/workflows/coding-standards.yml b/.github/workflows/coding-standards.yml new file mode 100644 index 00000000000..4e660b208bd --- /dev/null +++ b/.github/workflows/coding-standards.yml @@ -0,0 +1,38 @@ +name: "Coding Standards" + +on: ["pull_request", "push"] + +jobs: + coding-standards: + name: "Coding Standards" + runs-on: "ubuntu-20.04" + + strategy: + matrix: + php-version: + - "7.4" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Install PHP" + uses: "shivammathur/setup-php@v2" + with: + coverage: "none" + php-version: "${{ matrix.php-version }}" + tools: "cs2pr" + + - name: "Cache dependencies installed with Composer" + uses: "actions/cache@v2" + with: + path: "~/.composer/cache" + key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" + restore-keys: "php-${{ matrix.php-version }}-composer-locked-" + + - name: "Install dependencies with Composer" + run: "composer install --no-interaction --no-progress --no-suggest" + + # https://github.com/doctrine/.github/issues/3 + - name: "Run PHP_CodeSniffer" + run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr" diff --git a/.github/workflows/continuous-integration.yml b/.github/workflows/continuous-integration.yml index f8b14b44a5a..1b38ac3651c 100644 --- a/.github/workflows/continuous-integration.yml +++ b/.github/workflows/continuous-integration.yml @@ -69,39 +69,6 @@ jobs: - name: "Run a static analysis with vimeo/psalm" run: "vendor/bin/psalm --show-info=false --stats --output-format=github --threads=4" - coding-standards: - name: "Coding Standards" - runs-on: "ubuntu-latest" - - strategy: - matrix: - php-version: - - "7.4" - - steps: - - name: "Checkout" - uses: "actions/checkout@v2" - - - name: "Install PHP" - uses: "shivammathur/setup-php@v2" - with: - coverage: "none" - php-version: "${{ matrix.php-version }}" - tools: "cs2pr" - - - name: "Cache dependencies installed with composer" - uses: "actions/cache@v1" - with: - path: "~/.composer/cache" - key: "php-${{ matrix.php-version }}-composer-locked-${{ hashFiles('composer.lock') }}" - restore-keys: "php-${{ matrix.php-version }}-composer-locked-" - - - name: "Install dependencies with composer" - run: "composer install --no-interaction --no-progress --no-suggest" - - - name: "Run squizlabs/php_codesniffer" - run: "vendor/bin/phpcs -q --no-colors --report=checkstyle | cs2pr" - phpunit-oci8: name: "PHPUnit on OCI8" runs-on: "ubuntu-latest" From c115e9fbf0503363348289a2a6179611036afb94 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 3 Sep 2020 07:02:00 -0700 Subject: [PATCH 12/18] Remove redundant @throws annotations from test methods --- .../Platforms/AbstractSQLServerPlatformTestCase.php | 9 --------- .../Tests/DBAL/Platforms/SQLServer2012PlatformTest.php | 10 ---------- 2 files changed, 19 deletions(-) diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 6c166ac2dff..fba77a86756 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -469,9 +469,6 @@ public function testModifyLimitQueryWithAggregateFunctionInOrderByClause(): void $this->expectCteWithMaxRowNum($alteredSql, 1, $sql); } - /** - * @throws DBALException - */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable(): void { $querySql = 'SELECT DISTINCT id_0, name_1 ' @@ -493,9 +490,6 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBas $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } - /** - * @throws DBALException - */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable(): void { $querySql = 'SELECT DISTINCT id_0, name_1 ' @@ -517,9 +511,6 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoi $this->expectCteWithMaxRowNum($alteredSql, 5, $sql); } - /** - * @throws DBALException - */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables(): void { $querySql = 'SELECT DISTINCT id_0, name_1, foo_2 ' diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php index 47fe7ec69b3..1c21098b678 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLServer2012PlatformTest.php @@ -2,7 +2,6 @@ namespace Doctrine\Tests\DBAL\Platforms; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Schema\Sequence; @@ -370,9 +369,6 @@ public function testModifyLimitQueryWithComplexOrderByExpression(): void self::assertEquals($sql, $expected); } - /** - * @throws DBALException - */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable(): void { $querySql = 'SELECT DISTINCT id_0, name_1 ' @@ -393,9 +389,6 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBas self::assertEquals($alteredSql, $sql); } - /** - * @throws DBALException - */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable(): void { $querySql = 'SELECT DISTINCT id_0, name_1 ' @@ -416,9 +409,6 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoi self::assertEquals($alteredSql, $sql); } - /** - * @throws DBALException - */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables(): void { $querySql = 'SELECT DISTINCT id_0, name_1, foo_2 ' From ad1e48238b38a8ec10a7f461e7426c7f3985b603 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 3 Sep 2020 07:02:00 -0700 Subject: [PATCH 13/18] Deprecate DBAL\DBALException in favor of DBAL\Exception --- UPGRADE.md | 4 + lib/Doctrine/DBAL/Abstraction/Result.php | 8 +- lib/Doctrine/DBAL/Cache/CacheException.php | 4 +- lib/Doctrine/DBAL/Connection.php | 63 +++--- lib/Doctrine/DBAL/ConnectionException.php | 2 +- lib/Doctrine/DBAL/DBALException.php | 77 +++---- .../DBAL/Driver/AbstractMySQLDriver.php | 12 +- .../DBAL/Driver/AbstractPostgreSQLDriver.php | 4 +- .../DBAL/Driver/AbstractSQLAnywhereDriver.php | 4 +- .../DBAL/Driver/AbstractSQLServerDriver.php | 4 +- lib/Doctrine/DBAL/Driver/Mysqli/Driver.php | 4 +- lib/Doctrine/DBAL/Driver/OCI8/Driver.php | 4 +- lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php | 4 +- lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php | 4 +- lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php | 4 +- lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php | 4 +- .../DBAL/Driver/SQLAnywhere/Driver.php | 6 +- lib/Doctrine/DBAL/DriverManager.php | 22 +- lib/Doctrine/DBAL/Exception.php | 10 + .../DBAL/Exception/DriverException.php | 4 +- .../Exception/InvalidArgumentException.php | 4 +- lib/Doctrine/DBAL/Id/TableGenerator.php | 12 +- .../DBAL/Platforms/AbstractPlatform.php | 192 +++++++++--------- lib/Doctrine/DBAL/Platforms/DB2Platform.php | 4 +- .../DBAL/Platforms/OraclePlatform.php | 6 +- .../DBAL/Platforms/SQLAnywherePlatform.php | 4 +- .../DBAL/Platforms/SqlitePlatform.php | 16 +- lib/Doctrine/DBAL/Query/QueryException.php | 4 +- lib/Doctrine/DBAL/SQLParserUtilsException.php | 2 +- .../DBAL/Schema/AbstractSchemaManager.php | 6 +- lib/Doctrine/DBAL/Schema/SchemaException.php | 4 +- .../DBAL/Schema/SqliteSchemaManager.php | 6 +- lib/Doctrine/DBAL/Schema/Table.php | 14 +- .../DBAL/Sharding/ShardingException.php | 4 +- lib/Doctrine/DBAL/Statement.php | 20 +- .../DBAL/Types/ConversionException.php | 4 +- lib/Doctrine/DBAL/Types/Type.php | 8 +- lib/Doctrine/DBAL/Types/TypeRegistry.php | 22 +- .../DBAL/VersionAwarePlatformDriver.php | 2 +- tests/Doctrine/Tests/DBAL/ConnectionTest.php | 11 +- .../Doctrine/Tests/DBAL/DBALExceptionTest.php | 19 +- .../Tests/DBAL/Driver/AbstractDriverTest.php | 4 +- .../Doctrine/Tests/DBAL/DriverManagerTest.php | 14 +- .../Tests/DBAL/Functional/DataAccessTest.php | 4 +- .../Schema/SqliteSchemaManagerTest.php | 4 +- .../DBAL/Functional/Ticket/DBAL630Test.php | 4 +- .../Platforms/AbstractPlatformTestCase.php | 20 +- .../AbstractSQLServerPlatformTestCase.php | 4 +- .../DBAL/Platforms/OraclePlatformTest.php | 8 +- .../Platforms/SQLAnywherePlatformTest.php | 6 +- .../DBAL/Platforms/SqlitePlatformTest.php | 8 +- .../Doctrine/Tests/DBAL/Schema/TableTest.php | 4 +- tests/Doctrine/Tests/DBAL/StatementTest.php | 9 +- .../Tests/DBAL/Types/TypeRegistryTest.php | 14 +- 54 files changed, 363 insertions(+), 352 deletions(-) create mode 100644 lib/Doctrine/DBAL/Exception.php diff --git a/UPGRADE.md b/UPGRADE.md index 0392cdad627..9eb98d764a3 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -84,6 +84,10 @@ The non-interface methods of driver-level classes have been marked internal: - `OCI8Connection::getExecuteMode()` - `OCI8Statement::convertPositionalToNamedPlaceholders()` +## Deprecated `DBALException` + +The `Doctrine\DBAL\DBALException` class has been deprecated in favor of `Doctrine\DBAL\Exception`. + ## 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: diff --git a/lib/Doctrine/DBAL/Abstraction/Result.php b/lib/Doctrine/DBAL/Abstraction/Result.php index 5e163785405..42ff3419e37 100644 --- a/lib/Doctrine/DBAL/Abstraction/Result.php +++ b/lib/Doctrine/DBAL/Abstraction/Result.php @@ -4,8 +4,8 @@ namespace Doctrine\DBAL\Abstraction; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Result as DriverResult; +use Doctrine\DBAL\Exception; use Traversable; /** @@ -19,7 +19,7 @@ interface Result extends DriverResult * * @return Traversable> * - * @throws DBALException + * @throws Exception */ public function iterateNumeric(): Traversable; @@ -28,7 +28,7 @@ public function iterateNumeric(): Traversable; * * @return Traversable> * - * @throws DBALException + * @throws Exception */ public function iterateAssociative(): Traversable; @@ -37,7 +37,7 @@ public function iterateAssociative(): Traversable; * * @return Traversable * - * @throws DBALException + * @throws Exception */ public function iterateColumn(): Traversable; } diff --git a/lib/Doctrine/DBAL/Cache/CacheException.php b/lib/Doctrine/DBAL/Cache/CacheException.php index db5680812e2..3db115bdfae 100644 --- a/lib/Doctrine/DBAL/Cache/CacheException.php +++ b/lib/Doctrine/DBAL/Cache/CacheException.php @@ -2,12 +2,12 @@ namespace Doctrine\DBAL\Cache; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; /** * @psalm-immutable */ -class CacheException extends DBALException +class CacheException extends Exception { /** * @return CacheException diff --git a/lib/Doctrine/DBAL/Connection.php b/lib/Doctrine/DBAL/Connection.php index 6c4dea7fd22..82ef5d80170 100644 --- a/lib/Doctrine/DBAL/Connection.php +++ b/lib/Doctrine/DBAL/Connection.php @@ -174,7 +174,7 @@ class Connection implements DriverConnection * @param Configuration|null $config The configuration, optional. * @param EventManager|null $eventManager The event manager, optional. * - * @throws DBALException + * @throws Exception */ public function __construct( array $params, @@ -192,7 +192,7 @@ public function __construct( if (isset($params['platform'])) { if (! $params['platform'] instanceof Platforms\AbstractPlatform) { - throw DBALException::invalidPlatformType($params['platform']); + throw Exception::invalidPlatformType($params['platform']); } $this->platform = $params['platform']; @@ -320,7 +320,7 @@ public function getEventManager() * * @return AbstractPlatform * - * @throws DBALException + * @throws Exception */ public function getDatabasePlatform() { @@ -378,7 +378,7 @@ public function connect() * * Evaluates custom platform class and version in order to set the correct platform. * - * @throws DBALException If an invalid platform was specified for this connection. + * @throws Exception If an invalid platform was specified for this connection. */ private function detectDatabasePlatform(): void { @@ -549,7 +549,7 @@ public function setFetchMode($fetchMode) * * @return mixed[]|false False is returned if no rows are found. * - * @throws DBALException + * @throws Exception */ public function fetchAssoc($sql, array $params = [], array $types = []) { @@ -586,7 +586,7 @@ public function fetchArray($sql, array $params = [], array $types = []) * * @return mixed|false False is returned if no rows are found. * - * @throws DBALException + * @throws Exception */ public function fetchColumn($sql, array $params = [], $column = 0, array $types = []) { @@ -603,7 +603,7 @@ public function fetchColumn($sql, array $params = [], $column = 0, array $types * * @return array|false False is returned if no rows are found. * - * @throws DBALException + * @throws Exception */ public function fetchAssociative(string $query, array $params = [], array $types = []) { @@ -630,7 +630,7 @@ public function fetchAssociative(string $query, array $params = [], array $types * * @return array|false False is returned if no rows are found. * - * @throws DBALException + * @throws Exception */ public function fetchNumeric(string $query, array $params = [], array $types = []) { @@ -657,7 +657,7 @@ public function fetchNumeric(string $query, array $params = [], array $types = [ * * @return mixed|false False is returned if no rows are found. * - * @throws DBALException + * @throws Exception */ public function fetchOne(string $query, array $params = [], array $types = []) { @@ -702,7 +702,7 @@ public function isTransactionActive() * @param mixed[] $values Column values * @param string[] $conditions Key conditions * - * @throws DBALException + * @throws Exception */ private function addIdentifierCondition( array $identifier, @@ -735,8 +735,7 @@ private function addIdentifierCondition( * * @return int The number of affected rows. * - * @throws DBALException - * @throws InvalidArgumentException + * @throws Exception */ public function delete($table, array $identifier, array $types = []) { @@ -805,7 +804,7 @@ public function getTransactionIsolation() * * @return int The number of affected rows. * - * @throws DBALException + * @throws Exception */ public function update($table, array $data, array $identifier, array $types = []) { @@ -840,7 +839,7 @@ public function update($table, array $data, array $identifier, array $types = [] * * @return int The number of affected rows. * - * @throws DBALException + * @throws Exception */ public function insert($table, array $data, array $types = []) { @@ -941,7 +940,7 @@ public function fetchAll($sql, array $params = [], $types = []) * * @return array> * - * @throws DBALException + * @throws Exception */ public function fetchAllNumeric(string $query, array $params = [], array $types = []): array { @@ -967,7 +966,7 @@ public function fetchAllNumeric(string $query, array $params = [], array $types * * @return array> * - * @throws DBALException + * @throws Exception */ public function fetchAllAssociative(string $query, array $params = [], array $types = []): array { @@ -993,7 +992,7 @@ public function fetchAllAssociative(string $query, array $params = [], array $ty * * @return array * - * @throws DBALException + * @throws Exception */ public function fetchFirstColumn(string $query, array $params = [], array $types = []): array { @@ -1019,7 +1018,7 @@ public function fetchFirstColumn(string $query, array $params = [], array $types * * @return Traversable> * - * @throws DBALException + * @throws Exception */ public function iterateNumeric(string $query, array $params = [], array $types = []): Traversable { @@ -1048,7 +1047,7 @@ public function iterateNumeric(string $query, array $params = [], array $types = * * @return Traversable> * - * @throws DBALException + * @throws Exception */ public function iterateAssociative(string $query, array $params = [], array $types = []): Traversable { @@ -1076,7 +1075,7 @@ public function iterateAssociative(string $query, array $params = [], array $typ * * @return Traversable * - * @throws DBALException + * @throws Exception */ public function iterateColumn(string $query, array $params = [], array $types = []): Traversable { @@ -1102,7 +1101,7 @@ public function iterateColumn(string $query, array $params = [], array $types = * * @return Statement The prepared statement. * - * @throws DBALException + * @throws Exception */ public function prepare($sql) { @@ -1130,7 +1129,7 @@ public function prepare($sql) * * @return ResultStatement The executed statement. * - * @throws DBALException + * @throws Exception */ public function executeQuery($sql, array $params = [], $types = [], ?QueryCacheProfile $qcp = null) { @@ -1264,7 +1263,7 @@ public function project($sql, array $params, Closure $function) * * @return \Doctrine\DBAL\Driver\Statement * - * @throws DBALException + * @throws Exception */ public function query() { @@ -1306,7 +1305,7 @@ public function query() * * @return int The number of affected rows. * - * @throws DBALException + * @throws Exception */ public function executeUpdate($sql, array $params = [], array $types = []) { @@ -1331,7 +1330,7 @@ public function executeUpdate($sql, array $params = [], array $types = []) * * @return int The number of affected rows. * - * @throws DBALException + * @throws Exception */ public function executeStatement($sql, array $params = [], array $types = []) { @@ -1384,7 +1383,7 @@ public function executeStatement($sql, array $params = [], array $types = []) * * @return int The number of affected rows. * - * @throws DBALException + * @throws Exception */ public function exec($sql) { @@ -2008,14 +2007,14 @@ public function ping() * @param array|array $params * @param array|array $types * - * @throws DBALException + * @throws Exception * * @psalm-return never-return */ public function handleExceptionDuringQuery(Throwable $e, string $sql, array $params = [], array $types = []): void { $this->throw( - DBALException::driverExceptionDuringQuery( + Exception::driverExceptionDuringQuery( $this->_driver, $e, $sql, @@ -2027,14 +2026,14 @@ public function handleExceptionDuringQuery(Throwable $e, string $sql, array $par /** * @internal * - * @throws DBALException + * @throws Exception * * @psalm-return never-return */ public function handleDriverException(Throwable $e): void { $this->throw( - DBALException::driverException( + Exception::driverException( $this->_driver, $e ) @@ -2044,11 +2043,11 @@ public function handleDriverException(Throwable $e): void /** * @internal * - * @throws DBALException + * @throws Exception * * @psalm-return never-return */ - private function throw(DBALException $e): void + private function throw(Exception $e): void { if ($e instanceof ConnectionLost) { $this->close(); diff --git a/lib/Doctrine/DBAL/ConnectionException.php b/lib/Doctrine/DBAL/ConnectionException.php index f1914f5294e..8426ca28891 100644 --- a/lib/Doctrine/DBAL/ConnectionException.php +++ b/lib/Doctrine/DBAL/ConnectionException.php @@ -5,7 +5,7 @@ /** * @psalm-immutable */ -class ConnectionException extends DBALException +class ConnectionException extends Exception { /** * @return ConnectionException diff --git a/lib/Doctrine/DBAL/DBALException.php b/lib/Doctrine/DBAL/DBALException.php index f208a14ae92..b9a33cf1f70 100644 --- a/lib/Doctrine/DBAL/DBALException.php +++ b/lib/Doctrine/DBAL/DBALException.php @@ -7,7 +7,6 @@ use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; -use Exception; use Throwable; use function array_map; @@ -24,18 +23,20 @@ use function sprintf; /** + * @deprecated Use {@link Exception} instead + * * @psalm-immutable */ -class DBALException extends Exception +class DBALException extends \Exception { /** * @param string $method * - * @return DBALException + * @return Exception */ public static function notSupported($method) { - return new self(sprintf("Operation '%s' is not supported by platform.", $method)); + return new Exception(sprintf("Operation '%s' is not supported by platform.", $method)); } /** @@ -43,7 +44,7 @@ public static function notSupported($method) */ public static function invalidPlatformSpecified(): self { - return new self( + return new Exception( "Invalid 'platform' option specified, need to give an instance of " . AbstractPlatform::class . '.' ); } @@ -54,7 +55,7 @@ public static function invalidPlatformSpecified(): self public static function invalidPlatformType($invalidPlatform): self { if (is_object($invalidPlatform)) { - return new self( + return new Exception( sprintf( "Option 'platform' must be a subtype of '%s', instance of '%s' given", AbstractPlatform::class, @@ -63,7 +64,7 @@ public static function invalidPlatformType($invalidPlatform): self ); } - return new self( + return new Exception( sprintf( "Option 'platform' must be an object and subtype of '%s'. Got '%s'", AbstractPlatform::class, @@ -78,11 +79,11 @@ public static function invalidPlatformType($invalidPlatform): self * @param string $version The invalid platform version given. * @param string $expectedFormat The expected platform version format. * - * @return DBALException + * @return Exception */ public static function invalidPlatformVersionSpecified($version, $expectedFormat) { - return new self( + return new Exception( sprintf( 'Invalid platform version "%s" specified. ' . 'The platform version has to be specified in the format: "%s".', @@ -95,11 +96,11 @@ public static function invalidPlatformVersionSpecified($version, $expectedFormat /** * @deprecated Passing a PDO instance in connection parameters is deprecated. * - * @return DBALException + * @return Exception */ public static function invalidPdoInstance() { - return new self( + return new Exception( "The 'pdo' option was used in DriverManager::getConnection() but no " . 'instance of PDO was given.' ); @@ -108,12 +109,12 @@ public static function invalidPdoInstance() /** * @param string|null $url The URL that was provided in the connection parameters (if any). * - * @return DBALException + * @return Exception */ public static function driverRequired($url = null) { if ($url) { - return new self( + return new Exception( sprintf( "The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " . 'is given to DriverManager::getConnection(). Given URL: %s', @@ -122,7 +123,7 @@ public static function driverRequired($url = null) ); } - return new self("The options 'driver' or 'driverClass' are mandatory if no PDO " . + return new Exception("The options 'driver' or 'driverClass' are mandatory if no PDO " . 'instance is given to DriverManager::getConnection().'); } @@ -130,11 +131,11 @@ public static function driverRequired($url = null) * @param string $unknownDriverName * @param string[] $knownDrivers * - * @return DBALException + * @return Exception */ public static function unknownDriver($unknownDriverName, array $knownDrivers) { - return new self("The given 'driver' " . $unknownDriverName . ' is unknown, ' . + return new Exception("The given 'driver' " . $unknownDriverName . ' is unknown, ' . 'Doctrine currently supports only the following drivers: ' . implode(', ', $knownDrivers)); } @@ -144,7 +145,7 @@ public static function unknownDriver($unknownDriverName, array $knownDrivers) * @param string $sql * @param mixed[] $params * - * @return self + * @return Exception */ public static function driverExceptionDuringQuery(Driver $driver, Throwable $driverEx, $sql, array $params = []) { @@ -161,7 +162,7 @@ public static function driverExceptionDuringQuery(Driver $driver, Throwable $dri /** * @deprecated * - * @return self + * @return Exception */ public static function driverException(Driver $driver, Throwable $driverEx) { @@ -169,7 +170,7 @@ public static function driverException(Driver $driver, Throwable $driverEx) } /** - * @return self + * @return Exception */ private static function wrapException(Driver $driver, Throwable $driverEx, string $msg) { @@ -181,7 +182,7 @@ private static function wrapException(Driver $driver, Throwable $driverEx, strin return $driver->convertException($msg, $driverEx); } - return new self($msg, 0, $driverEx); + return new Exception($msg, 0, $driverEx); } /** @@ -213,22 +214,22 @@ private static function formatParameters(array $params) /** * @param string $wrapperClass * - * @return DBALException + * @return Exception */ public static function invalidWrapperClass($wrapperClass) { - return new self("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' . + return new Exception("The given 'wrapperClass' " . $wrapperClass . ' has to be a ' . 'subtype of \Doctrine\DBAL\Connection.'); } /** * @param string $driverClass * - * @return DBALException + * @return Exception */ public static function invalidDriverClass($driverClass) { - return new self( + return new Exception( "The given 'driverClass' " . $driverClass . ' has to implement the ' . Driver::class . ' interface.' ); } @@ -236,49 +237,49 @@ public static function invalidDriverClass($driverClass) /** * @param string $tableName * - * @return DBALException + * @return Exception */ public static function invalidTableName($tableName) { - return new self('Invalid table name specified: ' . $tableName); + return new Exception('Invalid table name specified: ' . $tableName); } /** * @param string $tableName * - * @return DBALException + * @return Exception */ public static function noColumnsSpecifiedForTable($tableName) { - return new self('No columns specified for table ' . $tableName); + return new Exception('No columns specified for table ' . $tableName); } /** - * @return DBALException + * @return Exception */ public static function limitOffsetInvalid() { - return new self('Invalid Offset in Limit Query, it has to be larger than or equal to 0.'); + return new Exception('Invalid Offset in Limit Query, it has to be larger than or equal to 0.'); } /** * @param string $name * - * @return DBALException + * @return Exception */ public static function typeExists($name) { - return new self('Type ' . $name . ' already exists.'); + return new Exception('Type ' . $name . ' already exists.'); } /** * @param string $name * - * @return DBALException + * @return Exception */ public static function unknownColumnType($name) { - return new self('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' . + return new Exception('Unknown column type "' . $name . '" requested. Any Doctrine type that you use has ' . 'to be registered with \Doctrine\DBAL\Types\Type::addType(). You can get a list of all the ' . 'known types with \Doctrine\DBAL\Types\Type::getTypesMap(). If this error occurs during database ' . 'introspection then you might have forgotten to register all database types for a Doctrine Type. Use ' . @@ -290,23 +291,23 @@ public static function unknownColumnType($name) /** * @param string $name * - * @return DBALException + * @return Exception */ public static function typeNotFound($name) { - return new self('Type to be overwritten ' . $name . ' does not exist.'); + return new Exception('Type to be overwritten ' . $name . ' does not exist.'); } public static function typeNotRegistered(Type $type): self { - return new self( + return new Exception( sprintf('Type of the class %s@%s is not registered.', get_class($type), spl_object_hash($type)) ); } public static function typeAlreadyRegistered(Type $type): self { - return new self( + return new Exception( sprintf('Type of the class %s@%s is already registered.', get_class($type), spl_object_hash($type)) ); } diff --git a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php index 7fd77aa5c51..edb33b89a40 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractMySQLDriver.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\ConnectionException; use Doctrine\DBAL\Exception\ConnectionLost; use Doctrine\DBAL\Exception\DeadlockException; @@ -131,7 +131,7 @@ public function convertException($message, DeprecatedDriverException $exception) /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ public function createDatabasePlatformForVersion($version) { @@ -160,7 +160,7 @@ public function createDatabasePlatformForVersion($version) * * @param string $versionString Version string returned by the driver, i.e. '5.7.10' * - * @throws DBALException + * @throws Exception */ private function getOracleMysqlVersionNumber(string $versionString): string { @@ -171,7 +171,7 @@ private function getOracleMysqlVersionNumber(string $versionString): string $versionParts ) ) { - throw DBALException::invalidPlatformVersionSpecified( + throw Exception::invalidPlatformVersionSpecified( $versionString, '..' ); @@ -194,7 +194,7 @@ private function getOracleMysqlVersionNumber(string $versionString): string * * @param string $versionString Version string as returned by mariadb server, i.e. '5.5.5-Mariadb-10.0.8-xenial' * - * @throws DBALException + * @throws Exception */ private function getMariaDbMysqlVersionNumber(string $versionString): string { @@ -205,7 +205,7 @@ private function getMariaDbMysqlVersionNumber(string $versionString): string $versionParts ) ) { - throw DBALException::invalidPlatformVersionSpecified( + throw Exception::invalidPlatformVersionSpecified( $versionString, '^(?:5\.5\.5-)?(mariadb-)?..' ); diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index 2653746eb9b..33b383392ec 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\ConnectionException; use Doctrine\DBAL\Exception\DeadlockException; use Doctrine\DBAL\Exception\DriverException; @@ -102,7 +102,7 @@ public function convertException($message, DeprecatedDriverException $exception) public function createDatabasePlatformForVersion($version) { if (! preg_match('/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $version, $versionParts)) { - throw DBALException::invalidPlatformVersionSpecified( + throw Exception::invalidPlatformVersionSpecified( $version, '..' ); diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php index 668f765e1ca..7fc71870d55 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLAnywhereDriver.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as DeprecatedDriverException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\ConnectionException; use Doctrine\DBAL\Exception\DeadlockException; use Doctrine\DBAL\Exception\DriverException; @@ -103,7 +103,7 @@ public function createDatabasePlatformForVersion($version) $versionParts ) ) { - throw DBALException::invalidPlatformVersionSpecified( + throw Exception::invalidPlatformVersionSpecified( $version, '...' ); diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php index 0d85a938dfb..2550ec5a87f 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLServerDriver.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as TheDriverException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\DriverException; use Doctrine\DBAL\Platforms\SQLServer2005Platform; use Doctrine\DBAL\Platforms\SQLServer2008Platform; @@ -35,7 +35,7 @@ public function createDatabasePlatformForVersion($version) $versionParts ) ) { - throw DBALException::invalidPlatformVersionSpecified( + throw Exception::invalidPlatformVersionSpecified( $version, '...' ); diff --git a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php index 561b51ba0f3..9ac74f27d07 100644 --- a/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php +++ b/lib/Doctrine/DBAL/Driver/Mysqli/Driver.php @@ -2,8 +2,8 @@ namespace Doctrine\DBAL\Driver\Mysqli; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractMySQLDriver; +use Doctrine\DBAL\Exception; class Driver extends AbstractMySQLDriver { @@ -15,7 +15,7 @@ public function connect(array $params, $username = null, $password = null, array try { return new Connection($params, (string) $username, (string) $password, $driverOptions); } catch (MysqliException $e) { - throw DBALException::driverException($this, $e); + throw Exception::driverException($this, $e); } } diff --git a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php index d83c2bdc30f..5f7e3c0a9e8 100644 --- a/lib/Doctrine/DBAL/Driver/OCI8/Driver.php +++ b/lib/Doctrine/DBAL/Driver/OCI8/Driver.php @@ -2,8 +2,8 @@ namespace Doctrine\DBAL\Driver\OCI8; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractOracleDriver; +use Doctrine\DBAL\Exception; use const OCI_NO_AUTO_COMMIT; @@ -27,7 +27,7 @@ public function connect(array $params, $username = null, $password = null, array $params['persistent'] ?? false ); } catch (OCI8Exception $e) { - throw DBALException::driverException($this, $e); + throw Exception::driverException($this, $e); } } diff --git a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php index eec433a9924..25eb2fbdb6f 100644 --- a/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOMySql/Driver.php @@ -2,9 +2,9 @@ namespace Doctrine\DBAL\Driver\PDOMySql; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractMySQLDriver; use Doctrine\DBAL\Driver\PDO; +use Doctrine\DBAL\Exception; use PDOException; /** @@ -27,7 +27,7 @@ public function connect(array $params, $username = null, $password = null, array $driverOptions ); } catch (PDOException $e) { - throw DBALException::driverException($this, $e); + throw Exception::driverException($this, $e); } return $conn; diff --git a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php index 2ea597d16f1..b6792996c71 100644 --- a/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOOracle/Driver.php @@ -2,9 +2,9 @@ namespace Doctrine\DBAL\Driver\PDOOracle; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractOracleDriver; use Doctrine\DBAL\Driver\PDO; +use Doctrine\DBAL\Exception; use PDOException; /** @@ -32,7 +32,7 @@ public function connect(array $params, $username = null, $password = null, array $driverOptions ); } catch (PDOException $e) { - throw DBALException::driverException($this, $e); + throw Exception::driverException($this, $e); } } diff --git a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php index d7a19181c4e..83076aa8c06 100644 --- a/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOPgSql/Driver.php @@ -2,9 +2,9 @@ namespace Doctrine\DBAL\Driver\PDOPgSql; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractPostgreSQLDriver; use Doctrine\DBAL\Driver\PDO; +use Doctrine\DBAL\Exception; use PDOException; use function defined; @@ -48,7 +48,7 @@ public function connect(array $params, $username = null, $password = null, array return $pdo; } catch (PDOException $e) { - throw DBALException::driverException($this, $e); + throw Exception::driverException($this, $e); } } diff --git a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php index 0c3b3900059..fc2b881ffce 100644 --- a/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php +++ b/lib/Doctrine/DBAL/Driver/PDOSqlite/Driver.php @@ -2,9 +2,9 @@ namespace Doctrine\DBAL\Driver\PDOSqlite; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractSQLiteDriver; use Doctrine\DBAL\Driver\PDO; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\SqlitePlatform; use PDOException; @@ -45,7 +45,7 @@ public function connect(array $params, $username = null, $password = null, array $driverOptions ); } catch (PDOException $ex) { - throw DBALException::driverException($this, $ex); + throw Exception::driverException($this, $ex); } foreach ($this->_userDefinedFunctions as $fn => $data) { diff --git a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php index bc29466e1a9..95b59274e9e 100644 --- a/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php +++ b/lib/Doctrine/DBAL/Driver/SQLAnywhere/Driver.php @@ -2,8 +2,8 @@ namespace Doctrine\DBAL\Driver\SQLAnywhere; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\AbstractSQLAnywhereDriver; +use Doctrine\DBAL\Exception; use function array_keys; use function array_map; @@ -17,7 +17,7 @@ class Driver extends AbstractSQLAnywhereDriver /** * {@inheritdoc} * - * @throws DBALException If there was a problem establishing the connection. + * @throws Exception If there was a problem establishing the connection. */ public function connect(array $params, $username = null, $password = null, array $driverOptions = []) { @@ -35,7 +35,7 @@ public function connect(array $params, $username = null, $password = null, array $params['persistent'] ?? false ); } catch (SQLAnywhereException $e) { - throw DBALException::driverException($this, $e); + throw Exception::driverException($this, $e); } } diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 70894eaa4a5..6c21d806580 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -117,7 +117,7 @@ private function __construct() * @param Configuration|null $config The configuration to use. * @param EventManager|null $eventManager The event manager to use. * - * @throws DBALException + * @throws Exception * * @phpstan-param mixed[] $params * @psalm-return ($params is array{wrapperClass:mixed} ? T : Connection) @@ -175,7 +175,7 @@ public static function getConnection( // check for existing pdo object if (isset($params['pdo']) && ! $params['pdo'] instanceof \PDO) { - throw DBALException::invalidPdoInstance(); + throw Exception::invalidPdoInstance(); } if (isset($params['pdo'])) { @@ -192,7 +192,7 @@ public static function getConnection( $wrapperClass = Connection::class; if (isset($params['wrapperClass'])) { if (! is_subclass_of($params['wrapperClass'], $wrapperClass)) { - throw DBALException::invalidWrapperClass($params['wrapperClass']); + throw Exception::invalidWrapperClass($params['wrapperClass']); } $wrapperClass = $params['wrapperClass']; @@ -216,7 +216,7 @@ public static function getAvailableDrivers(): array * * @param mixed[] $params The list of parameters. * - * @throws DBALException + * @throws Exception */ private static function _checkParams(array $params): void { @@ -224,21 +224,21 @@ private static function _checkParams(array $params): void // driver if (! isset($params['driver']) && ! isset($params['driverClass'])) { - throw DBALException::driverRequired(); + throw Exception::driverRequired(); } // check validity of parameters // driver if (isset($params['driver']) && ! isset(self::$_driverMap[$params['driver']])) { - throw DBALException::unknownDriver($params['driver'], array_keys(self::$_driverMap)); + throw Exception::unknownDriver($params['driver'], array_keys(self::$_driverMap)); } if ( isset($params['driverClass']) && ! in_array(Driver::class, class_implements($params['driverClass'], true)) ) { - throw DBALException::invalidDriverClass($params['driverClass']); + throw Exception::invalidDriverClass($params['driverClass']); } } @@ -262,7 +262,7 @@ private static function normalizeDatabaseUrlPath(string $urlPath): string * @return mixed[] A modified list of parameters with info from a database * URL extracted into indidivual parameter parts. * - * @throws DBALException + * @throws Exception */ private static function parseDatabaseUrl(array $params): array { @@ -277,7 +277,7 @@ private static function parseDatabaseUrl(array $params): array $url = parse_url($url); if ($url === false) { - throw new DBALException('Malformed parameter "url".'); + throw new Exception('Malformed parameter "url".'); } $url = array_map('rawurldecode', $url); @@ -417,7 +417,7 @@ private static function parseSqliteDatabaseUrlPath(array $url, array $params): a * * @return mixed[] The resolved connection parameters. * - * @throws DBALException If parsing failed or resolution is not possible. + * @throws Exception If parsing failed or resolution is not possible. */ private static function parseDatabaseUrlScheme(array $url, array $params): array { @@ -442,7 +442,7 @@ private static function parseDatabaseUrlScheme(array $url, array $params): array // If a schemeless connection URL is given, we require a default driver or default custom driver // as connection parameter. if (! isset($params['driverClass']) && ! isset($params['driver'])) { - throw DBALException::driverRequired($params['url']); + throw Exception::driverRequired($params['url']); } return $params; diff --git a/lib/Doctrine/DBAL/Exception.php b/lib/Doctrine/DBAL/Exception.php new file mode 100644 index 00000000000..34442da6a8a --- /dev/null +++ b/lib/Doctrine/DBAL/Exception.php @@ -0,0 +1,10 @@ +getDriver() instanceof Driver\PDOSqlite\Driver) { - throw new DBALException('Cannot use TableGenerator with SQLite.'); + throw new Exception('Cannot use TableGenerator with SQLite.'); } $this->conn = DriverManager::getConnection( @@ -90,7 +90,7 @@ public function __construct(Connection $conn, $generatorTableName = 'sequences') * * @return int * - * @throws DBALException + * @throws Exception */ public function nextValue($sequence) { @@ -134,7 +134,7 @@ public function nextValue($sequence) $rows = $this->conn->executeStatement($sql, [$sequence, $row['sequence_value']]); if ($rows !== 1) { - throw new DBALException('Race-condition detected while updating sequence. Aborting generation'); + throw new Exception('Race-condition detected while updating sequence. Aborting generation'); } } else { $this->conn->insert( @@ -148,7 +148,7 @@ public function nextValue($sequence) } catch (Throwable $e) { $this->conn->rollBack(); - throw new DBALException( + throw new Exception( 'Error occurred while generating ID with TableGenerator, aborted generation: ' . $e->getMessage(), 0, $e diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index b29596681ee..61c6a81d742 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -3,7 +3,6 @@ namespace Doctrine\DBAL\Platforms; use Doctrine\Common\EventManager; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs; use Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs; use Doctrine\DBAL\Event\SchemaAlterTableEventArgs; @@ -13,6 +12,7 @@ use Doctrine\DBAL\Event\SchemaCreateTableEventArgs; use Doctrine\DBAL\Event\SchemaDropTableEventArgs; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; @@ -343,11 +343,11 @@ public function getJsonTypeDeclarationSQL(array $column) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) { - throw DBALException::notSupported('VARCHARs not supported by Platform.'); + throw Exception::notSupported('VARCHARs not supported by Platform.'); } /** @@ -358,11 +358,11 @@ protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) { - throw DBALException::notSupported('BINARY/VARBINARY column types are not supported by this platform.'); + throw Exception::notSupported('BINARY/VARBINARY column types are not supported by this platform.'); } /** @@ -398,7 +398,7 @@ abstract public function getName(); * * @return void * - * @throws DBALException If the type is not found. + * @throws Exception If the type is not found. */ public function registerDoctrineTypeMapping($dbType, $doctrineType) { @@ -407,7 +407,7 @@ public function registerDoctrineTypeMapping($dbType, $doctrineType) } if (! Types\Type::hasType($doctrineType)) { - throw DBALException::typeNotFound($doctrineType); + throw Exception::typeNotFound($doctrineType); } $dbType = strtolower($dbType); @@ -429,7 +429,7 @@ public function registerDoctrineTypeMapping($dbType, $doctrineType) * * @return string * - * @throws DBALException + * @throws Exception */ public function getDoctrineTypeMapping($dbType) { @@ -440,7 +440,7 @@ public function getDoctrineTypeMapping($dbType) $dbType = strtolower($dbType); if (! isset($this->doctrineTypeMapping[$dbType])) { - throw new DBALException( + throw new Exception( 'Unknown database type ' . $dbType . ' requested, ' . static::class . ' may not support it.' ); } @@ -639,11 +639,11 @@ public function getWildcards() * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getRegexpExpression() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -653,11 +653,11 @@ public function getRegexpExpression() * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getGuidExpression() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -885,11 +885,11 @@ public function getLowerExpression($str) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getLocateExpression($str, $substr, $startPos = false) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -1056,11 +1056,11 @@ public function getCosExpression($value) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateDiffExpression($date1, $date2) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -1071,7 +1071,7 @@ public function getDateDiffExpression($date1, $date2) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateAddSecondsExpression($date, $seconds) { @@ -1086,7 +1086,7 @@ public function getDateAddSecondsExpression($date, $seconds) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateSubSecondsExpression($date, $seconds) { @@ -1101,7 +1101,7 @@ public function getDateSubSecondsExpression($date, $seconds) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateAddMinutesExpression($date, $minutes) { @@ -1116,7 +1116,7 @@ public function getDateAddMinutesExpression($date, $minutes) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateSubMinutesExpression($date, $minutes) { @@ -1131,7 +1131,7 @@ public function getDateSubMinutesExpression($date, $minutes) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateAddHourExpression($date, $hours) { @@ -1146,7 +1146,7 @@ public function getDateAddHourExpression($date, $hours) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateSubHourExpression($date, $hours) { @@ -1161,7 +1161,7 @@ public function getDateSubHourExpression($date, $hours) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateAddDaysExpression($date, $days) { @@ -1176,7 +1176,7 @@ public function getDateAddDaysExpression($date, $days) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateSubDaysExpression($date, $days) { @@ -1191,7 +1191,7 @@ public function getDateSubDaysExpression($date, $days) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateAddWeeksExpression($date, $weeks) { @@ -1206,7 +1206,7 @@ public function getDateAddWeeksExpression($date, $weeks) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateSubWeeksExpression($date, $weeks) { @@ -1221,7 +1221,7 @@ public function getDateSubWeeksExpression($date, $weeks) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateAddMonthExpression($date, $months) { @@ -1236,7 +1236,7 @@ public function getDateAddMonthExpression($date, $months) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateSubMonthExpression($date, $months) { @@ -1251,7 +1251,7 @@ public function getDateSubMonthExpression($date, $months) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateAddQuartersExpression($date, $quarters) { @@ -1266,7 +1266,7 @@ public function getDateAddQuartersExpression($date, $quarters) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateSubQuartersExpression($date, $quarters) { @@ -1281,7 +1281,7 @@ public function getDateSubQuartersExpression($date, $quarters) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateAddYearsExpression($date, $years) { @@ -1296,7 +1296,7 @@ public function getDateAddYearsExpression($date, $years) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateSubYearsExpression($date, $years) { @@ -1314,11 +1314,11 @@ public function getDateSubYearsExpression($date, $years) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -1541,7 +1541,7 @@ public function getDropForeignKeySQL($foreignKey, $table) * * @return string[] The sequence of SQL statements. * - * @throws DBALException + * @throws Exception * @throws InvalidArgumentException */ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES) @@ -1553,7 +1553,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE } if (count($table->getColumns()) === 0) { - throw DBALException::noColumnsSpecifiedForTable($table->getName()); + throw Exception::noColumnsSpecifiedForTable($table->getName()); } $tableName = $table->getQuotedName($this); @@ -1682,12 +1682,12 @@ public function getCommentOnColumnSQL($tableName, $columnName, $comment) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getInlineColumnCommentSQL($comment) { if (! $this->supportsInlineColumnComments()) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } return 'COMMENT ' . $this->quoteStringLiteral($comment); @@ -1755,11 +1755,11 @@ public function getCreateTemporaryTableSnippetSQL() * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getCreateSequenceSQL(Sequence $sequence) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -1767,11 +1767,11 @@ public function getCreateSequenceSQL(Sequence $sequence) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getAlterSequenceSQL(Sequence $sequence) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -1895,11 +1895,11 @@ public function getCreatePrimaryKeySQL(Index $index, $table) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getCreateSchemaSQL($schemaName) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -1964,11 +1964,11 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) * * @return string[] * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getAlterTableSQL(TableDiff $diff) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2793,11 +2793,11 @@ protected function _getTransactionIsolationLevelSQL($level) /** * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListDatabasesSQL() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2805,11 +2805,11 @@ public function getListDatabasesSQL() * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListNamespacesSQL() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2817,11 +2817,11 @@ public function getListNamespacesSQL() * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListSequencesSQL($database) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2829,11 +2829,11 @@ public function getListSequencesSQL($database) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListTableConstraintsSQL($table) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2842,31 +2842,31 @@ public function getListTableConstraintsSQL($table) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListTableColumnsSQL($table, $database = null) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListTablesSQL() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListUsersSQL() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2876,11 +2876,11 @@ public function getListUsersSQL() * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListViewsSQL($database) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2898,11 +2898,11 @@ public function getListViewsSQL($database) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListTableIndexesSQL($table, $database = null) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2910,11 +2910,11 @@ public function getListTableIndexesSQL($table, $database = null) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getListTableForeignKeysSQL($table) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2923,11 +2923,11 @@ public function getListTableForeignKeysSQL($table) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getCreateViewSQL($name, $sql) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2935,11 +2935,11 @@ public function getCreateViewSQL($name, $sql) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDropViewSQL($name) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2949,11 +2949,11 @@ public function getDropViewSQL($name) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDropSequenceSQL($sequence) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2961,11 +2961,11 @@ public function getDropSequenceSQL($sequence) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getSequenceNextValSQL($sequence) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2975,11 +2975,11 @@ public function getSequenceNextValSQL($sequence) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getCreateDatabaseSQL($database) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -2989,11 +2989,11 @@ public function getCreateDatabaseSQL($database) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getSetTransactionIsolationSQL($level) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -3004,11 +3004,11 @@ public function getSetTransactionIsolationSQL($level) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateTimeTypeDeclarationSQL(array $column) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -3031,11 +3031,11 @@ public function getDateTimeTzTypeDeclarationSQL(array $column) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDateTypeDeclarationSQL(array $column) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -3046,11 +3046,11 @@ public function getDateTypeDeclarationSQL(array $column) * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getTimeTypeDeclarationSQL(array $column) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -3124,11 +3124,11 @@ public function usesSequenceEmulatedIdentityColumns() * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getIdentitySequenceName($tableName, $columnName) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -3269,11 +3269,11 @@ public function canEmulateSchemas() * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ public function getDefaultSchemaName() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** @@ -3423,7 +3423,7 @@ public function getTimeFormatString() * * @return string * - * @throws DBALException + * @throws Exception */ final public function modifyLimitQuery($query, $limit, $offset = null) { @@ -3434,14 +3434,14 @@ final public function modifyLimitQuery($query, $limit, $offset = null) $offset = (int) $offset; if ($offset < 0) { - throw new DBALException(sprintf( + throw new Exception(sprintf( 'Offset must be a positive integer or zero, %d given', $offset )); } if ($offset > 0 && ! $this->supportsLimitOffset()) { - throw new DBALException(sprintf( + throw new Exception(sprintf( 'Platform %s does not support offset values in limit queries.', $this->getName() )); @@ -3605,7 +3605,7 @@ public function rollbackSavePoint($savepoint) * * @return KeywordList * - * @throws DBALException If no keyword list is specified. + * @throws Exception If no keyword list is specified. */ final public function getReservedKeywordsList() { @@ -3617,7 +3617,7 @@ final public function getReservedKeywordsList() $class = $this->getReservedKeywordsClass(); $keywords = new $class(); if (! $keywords instanceof KeywordList) { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } // Store the instance so it doesn't need to be generated on every request. @@ -3631,11 +3631,11 @@ final public function getReservedKeywordsList() * * @return string * - * @throws DBALException If not supported on this platform. + * @throws Exception If not supported on this platform. */ protected function getReservedKeywordsClass() { - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index d0d58f9a371..3d75866e198 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\ColumnDiff; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; @@ -481,7 +481,7 @@ public function getCurrentTimestampSQL() public function getIndexDeclarationSQL($name, Index $index) { // Index declaration in statements like CREATE TABLE is not supported. - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index e6b97576f2e..9d2e44cbb8d 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Identifier; use Doctrine\DBAL\Schema\Index; @@ -40,12 +40,12 @@ class OraclePlatform extends AbstractPlatform * * @return void * - * @throws DBALException + * @throws Exception */ public static function assertValidIdentifier($identifier) { if (! preg_match('(^(([a-zA-Z]{1}[a-zA-Z0-9_$#]{0,})|("[^"]+"))$)', $identifier)) { - throw new DBALException('Invalid Oracle identifier'); + throw new Exception('Invalid Oracle identifier'); } } diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 006671bc81e..f7921cbde48 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; @@ -691,7 +691,7 @@ public function getGuidTypeDeclarationSQL(array $column) public function getIndexDeclarationSQL($name, Index $index) { // Index declaration in statements like CREATE TABLE is not supported. - throw DBALException::notSupported(__METHOD__); + throw Exception::notSupported(__METHOD__); } /** diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 1f3a099ac95..9317c64a37b 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Constraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint; @@ -697,7 +697,7 @@ protected function getReservedKeywordsClass() protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) { if (! $diff->fromTable instanceof Table) { - throw new DBALException( + throw new Exception( 'Sqlite platform requires for alter table the table diff with reference to original table schema' ); } @@ -720,7 +720,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) { if (! $diff->fromTable instanceof Table) { - throw new DBALException( + throw new Exception( 'Sqlite platform requires for alter table the table diff with reference to original table schema' ); } @@ -805,7 +805,7 @@ public function supportsCreateDropForeignKeyConstraints(): bool */ public function getCreatePrimaryKeySQL(Index $index, $table) { - throw new DBALException('Sqlite platform does not support alter primary key.'); + throw new Exception('Sqlite platform does not support alter primary key.'); } /** @@ -813,7 +813,7 @@ public function getCreatePrimaryKeySQL(Index $index, $table) */ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) { - throw new DBALException( + throw new Exception( 'Sqlite platform does not support alter foreign key, ' . 'the table must be fully recreated using getAlterTableSQL.' ); @@ -824,7 +824,7 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) */ public function getDropForeignKeySQL($foreignKey, $table) { - throw new DBALException( + throw new Exception( 'Sqlite platform does not support alter foreign key, ' . 'the table must be fully recreated using getAlterTableSQL.' ); @@ -835,7 +835,7 @@ public function getDropForeignKeySQL($foreignKey, $table) */ public function getCreateConstraintSQL(Constraint $constraint, $table) { - throw new DBALException('Sqlite platform does not support alter constraint.'); + throw new Exception('Sqlite platform does not support alter constraint.'); } /** @@ -875,7 +875,7 @@ public function getAlterTableSQL(TableDiff $diff) $fromTable = $diff->fromTable; if (! $fromTable instanceof Table) { - throw new DBALException( + throw new Exception( 'Sqlite platform requires for alter table the table diff with reference to original table schema' ); } diff --git a/lib/Doctrine/DBAL/Query/QueryException.php b/lib/Doctrine/DBAL/Query/QueryException.php index 76bb9ba7559..58e941e9843 100644 --- a/lib/Doctrine/DBAL/Query/QueryException.php +++ b/lib/Doctrine/DBAL/Query/QueryException.php @@ -2,14 +2,14 @@ namespace Doctrine\DBAL\Query; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use function implode; /** * @psalm-immutable */ -class QueryException extends DBALException +class QueryException extends Exception { /** * @param string $alias diff --git a/lib/Doctrine/DBAL/SQLParserUtilsException.php b/lib/Doctrine/DBAL/SQLParserUtilsException.php index 99cdb8d4a66..297b0761b8d 100644 --- a/lib/Doctrine/DBAL/SQLParserUtilsException.php +++ b/lib/Doctrine/DBAL/SQLParserUtilsException.php @@ -9,7 +9,7 @@ * * @psalm-immutable */ -class SQLParserUtilsException extends DBALException +class SQLParserUtilsException extends Exception { /** * @param string $paramName diff --git a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php index 2bff61a8e90..35f2c612780 100644 --- a/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/AbstractSchemaManager.php @@ -4,10 +4,10 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\ConnectionException; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Event\SchemaColumnDefinitionEventArgs; use Doctrine\DBAL\Event\SchemaIndexDefinitionEventArgs; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Throwable; @@ -776,11 +776,11 @@ protected function _getPortableSequencesList($sequences) * * @return Sequence * - * @throws DBALException + * @throws Exception */ protected function _getPortableSequenceDefinition($sequence) { - throw DBALException::notSupported('Sequences'); + throw Exception::notSupported('Sequences'); } /** diff --git a/lib/Doctrine/DBAL/Schema/SchemaException.php b/lib/Doctrine/DBAL/Schema/SchemaException.php index 6317679de0a..64f4b250a8a 100644 --- a/lib/Doctrine/DBAL/Schema/SchemaException.php +++ b/lib/Doctrine/DBAL/Schema/SchemaException.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use function implode; use function sprintf; @@ -10,7 +10,7 @@ /** * @psalm-immutable */ -class SchemaException extends DBALException +class SchemaException extends Exception { public const TABLE_DOESNT_EXIST = 10; public const TABLE_ALREADY_EXISTS = 20; diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index eb85f32c2ed..de7b1375032 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -2,8 +2,8 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Types\StringType; use Doctrine\DBAL\Types\TextType; use Doctrine\DBAL\Types\Type; @@ -455,7 +455,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) * * @return TableDiff * - * @throws DBALException + * @throws Exception */ private function getTableDiffForAlterForeignKey($table) { @@ -463,7 +463,7 @@ private function getTableDiffForAlterForeignKey($table) $tableDetails = $this->tryMethod('listTableDetails', $table); if ($tableDetails === false) { - throw new DBALException( + throw new Exception( sprintf('Sqlite schema manager requires to modify foreign keys table definition "%s".', $table) ); } diff --git a/lib/Doctrine/DBAL/Schema/Table.php b/lib/Doctrine/DBAL/Schema/Table.php index 4d8b362a0d0..909b349107b 100644 --- a/lib/Doctrine/DBAL/Schema/Table.php +++ b/lib/Doctrine/DBAL/Schema/Table.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Visitor\Visitor; use Doctrine\DBAL\Types\Type; @@ -51,7 +51,7 @@ class Table extends AbstractAsset * @param int $idGeneratorType * @param mixed[] $options * - * @throws DBALException + * @throws Exception */ public function __construct( $name, @@ -62,7 +62,7 @@ public function __construct( array $options = [] ) { if (strlen($name) === 0) { - throw DBALException::invalidTableName($name); + throw Exception::invalidTableName($name); } $this->_setName($name); @@ -316,11 +316,11 @@ public function addColumn($name, $typeName, array $options = []) * * @return void * - * @throws DBALException + * @throws Exception */ public function renameColumn($oldName, $name) { - throw new DBALException('Table#renameColumn() was removed, because it drops and recreates ' . + throw new Exception('Table#renameColumn() was removed, because it drops and recreates ' . 'the column instead. There is no fix available, because a schema diff cannot reliably detect if a ' . 'column was renamed or one column was created and another one dropped.'); } @@ -727,14 +727,14 @@ public function getPrimaryKey() * * @return string[] * - * @throws DBALException + * @throws Exception */ public function getPrimaryKeyColumns() { $primaryKey = $this->getPrimaryKey(); if ($primaryKey === null) { - throw new DBALException('Table ' . $this->getName() . ' has no primary key.'); + throw new Exception('Table ' . $this->getName() . ' has no primary key.'); } return $primaryKey->getColumns(); diff --git a/lib/Doctrine/DBAL/Sharding/ShardingException.php b/lib/Doctrine/DBAL/Sharding/ShardingException.php index 2df764a6ff2..d3363a126cd 100644 --- a/lib/Doctrine/DBAL/Sharding/ShardingException.php +++ b/lib/Doctrine/DBAL/Sharding/ShardingException.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Sharding; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; /** * Sharding related Exceptions @@ -11,7 +11,7 @@ * * @psalm-immutable */ -class ShardingException extends DBALException +class ShardingException extends Exception { /** * @return ShardingException diff --git a/lib/Doctrine/DBAL/Statement.php b/lib/Doctrine/DBAL/Statement.php index 080c48e2061..0e47e09303c 100644 --- a/lib/Doctrine/DBAL/Statement.php +++ b/lib/Doctrine/DBAL/Statement.php @@ -143,7 +143,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le * * @return bool TRUE on success, FALSE on failure. * - * @throws DBALException + * @throws Exception */ public function execute($params = null) { @@ -280,7 +280,7 @@ public function fetchColumn($columnIndex = 0) /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ public function fetchNumeric() { @@ -298,7 +298,7 @@ public function fetchNumeric() /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ public function fetchAssociative() { @@ -316,7 +316,7 @@ public function fetchAssociative() /** * {@inheritDoc} * - * @throws DBALException + * @throws Exception */ public function fetchOne() { @@ -334,7 +334,7 @@ public function fetchOne() /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ public function fetchAllNumeric(): array { @@ -352,7 +352,7 @@ public function fetchAllNumeric(): array /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ public function fetchAllAssociative(): array { @@ -370,7 +370,7 @@ public function fetchAllAssociative(): array /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ public function fetchFirstColumn(): array { @@ -390,7 +390,7 @@ public function fetchFirstColumn(): array * * @return Traversable> * - * @throws DBALException + * @throws Exception */ public function iterateNumeric(): Traversable { @@ -414,7 +414,7 @@ public function iterateNumeric(): Traversable * * @return Traversable> * - * @throws DBALException + * @throws Exception */ public function iterateAssociative(): Traversable { @@ -438,7 +438,7 @@ public function iterateAssociative(): Traversable * * @return Traversable * - * @throws DBALException + * @throws Exception */ public function iterateColumn(): Traversable { diff --git a/lib/Doctrine/DBAL/Types/ConversionException.php b/lib/Doctrine/DBAL/Types/ConversionException.php index 55dfedee754..5be4743a5e5 100644 --- a/lib/Doctrine/DBAL/Types/ConversionException.php +++ b/lib/Doctrine/DBAL/Types/ConversionException.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Types; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Throwable; use function get_class; @@ -19,7 +19,7 @@ * * @psalm-immutable */ -class ConversionException extends DBALException +class ConversionException extends Exception { /** * Thrown when a Database to Doctrine Type Conversion fails. diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index b0344062537..f75a4905673 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Types; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; @@ -225,7 +225,7 @@ private static function createTypeRegistry(): TypeRegistry * * @return Type * - * @throws DBALException + * @throws Exception */ public static function getType($name) { @@ -240,7 +240,7 @@ public static function getType($name) * * @return void * - * @throws DBALException + * @throws Exception */ public static function addType($name, $className) { @@ -267,7 +267,7 @@ public static function hasType($name) * * @return void * - * @throws DBALException + * @throws Exception */ public static function overrideType($name, $className) { diff --git a/lib/Doctrine/DBAL/Types/TypeRegistry.php b/lib/Doctrine/DBAL/Types/TypeRegistry.php index 4c2e31ecbcf..fdae6d603c8 100644 --- a/lib/Doctrine/DBAL/Types/TypeRegistry.php +++ b/lib/Doctrine/DBAL/Types/TypeRegistry.php @@ -4,7 +4,7 @@ namespace Doctrine\DBAL\Types; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use function array_search; use function in_array; @@ -31,12 +31,12 @@ public function __construct(array $instances = []) /** * Finds a type by the given name. * - * @throws DBALException + * @throws Exception */ public function get(string $name): Type { if (! isset($this->instances[$name])) { - throw DBALException::unknownColumnType($name); + throw Exception::unknownColumnType($name); } return $this->instances[$name]; @@ -45,14 +45,14 @@ public function get(string $name): Type /** * Finds a name for the given type. * - * @throws DBALException + * @throws Exception */ public function lookupName(Type $type): string { $name = $this->findTypeName($type); if ($name === null) { - throw DBALException::typeNotRegistered($type); + throw Exception::typeNotRegistered($type); } return $name; @@ -69,16 +69,16 @@ public function has(string $name): bool /** * Registers a custom type to the type map. * - * @throws DBALException + * @throws Exception */ public function register(string $name, Type $type): void { if (isset($this->instances[$name])) { - throw DBALException::typeExists($name); + throw Exception::typeExists($name); } if ($this->findTypeName($type) !== null) { - throw DBALException::typeAlreadyRegistered($type); + throw Exception::typeAlreadyRegistered($type); } $this->instances[$name] = $type; @@ -87,16 +87,16 @@ public function register(string $name, Type $type): void /** * Overrides an already defined type to use a different implementation. * - * @throws DBALException + * @throws Exception */ public function override(string $name, Type $type): void { if (! isset($this->instances[$name])) { - throw DBALException::typeNotFound($name); + throw Exception::typeNotFound($name); } if (! in_array($this->findTypeName($type), [$name, null], true)) { - throw DBALException::typeAlreadyRegistered($type); + throw Exception::typeAlreadyRegistered($type); } $this->instances[$name] = $type; diff --git a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php index a4864d0b287..8bdae926442 100644 --- a/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php +++ b/lib/Doctrine/DBAL/VersionAwarePlatformDriver.php @@ -22,7 +22,7 @@ interface VersionAwarePlatformDriver * * @return AbstractPlatform * - * @throws DBALException If the given version string could not be evaluated. + * @throws Exception If the given version string could not be evaluated. */ public function createDatabasePlatformForVersion($version); } diff --git a/tests/Doctrine/Tests/DBAL/ConnectionTest.php b/tests/Doctrine/Tests/DBAL/ConnectionTest.php index 1bbb900f598..8bcf1b817fe 100644 --- a/tests/Doctrine/Tests/DBAL/ConnectionTest.php +++ b/tests/Doctrine/Tests/DBAL/ConnectionTest.php @@ -9,13 +9,13 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; use Doctrine\DBAL\ConnectionException; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\Connection as DriverConnection; use Doctrine\DBAL\Driver\ServerInfoAwareConnection; use Doctrine\DBAL\Driver\Statement; use Doctrine\DBAL\DriverManager; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Logging\DebugStack; @@ -23,7 +23,6 @@ use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\Tests\DbalTestCase; -use Exception; use PHPUnit\Framework\MockObject\MockObject; use stdClass; @@ -183,7 +182,7 @@ public function testEventManagerPassedToPlatform(): void */ public function testDriverExceptionIsWrapped(string $method): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage(<<createMock(Driver::class); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); new Connection($connectionParams, $driver); } @@ -843,8 +842,8 @@ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnecting $driverMock = $this->createMock(FutureVersionAwarePlatformDriver::class); $connection = new Connection(['dbname' => 'foo'], $driverMock); - $originalException = new Exception('Original exception'); - $fallbackException = new Exception('Fallback exception'); + $originalException = new \Exception('Original exception'); + $fallbackException = new \Exception('Fallback exception'); $driverMock->method('connect') ->will(self::onConsecutiveCalls( diff --git a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php index 8fa510e8d0a..5f7f137225d 100644 --- a/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/DBALExceptionTest.php @@ -2,12 +2,11 @@ namespace Doctrine\Tests\DBAL; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as InnerDriverException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\DriverException; use Doctrine\Tests\DbalTestCase; -use Exception; use stdClass; use function chr; @@ -19,7 +18,7 @@ class DBALExceptionTest extends DbalTestCase public function testDriverExceptionDuringQueryAcceptsBinaryData(): void { $driver = $this->createMock(Driver::class); - $e = DBALException::driverExceptionDuringQuery($driver, new Exception(), '', ['ABC', chr(128)]); + $e = Exception::driverExceptionDuringQuery($driver, new \Exception(), '', ['ABC', chr(128)]); self::assertStringContainsString('with params ["ABC", "\x80"]', $e->getMessage()); } @@ -27,9 +26,9 @@ public function testDriverExceptionDuringQueryAcceptsResource(): void { $driver = $this->createMock(Driver::class); - $e = DBALException::driverExceptionDuringQuery( + $e = Exception::driverExceptionDuringQuery( $driver, - new Exception(), + new \Exception(), 'INSERT INTO file (`content`) VALUES (?)', [1 => fopen(__FILE__, 'r')] ); @@ -44,16 +43,16 @@ public function testAvoidOverWrappingOnDriverException(): void $inner = $this->createMock(InnerDriverException::class); $ex = new DriverException('', $inner); - $e = DBALException::driverExceptionDuringQuery($driver, $ex, ''); + $e = Exception::driverExceptionDuringQuery($driver, $ex, ''); self::assertSame($ex, $e); } public function testDriverRequiredWithUrl(): void { $url = 'mysql://localhost'; - $exception = DBALException::driverRequired($url); + $exception = Exception::driverRequired($url); - self::assertInstanceOf(DBALException::class, $exception); + self::assertInstanceOf(Exception::class, $exception); self::assertSame( sprintf( "The options 'driver' or 'driverClass' are mandatory if a connection URL without scheme " . @@ -66,7 +65,7 @@ public function testDriverRequiredWithUrl(): void public function testInvalidPlatformTypeObject(): void { - $exception = DBALException::invalidPlatformType(new stdClass()); + $exception = Exception::invalidPlatformType(new stdClass()); self::assertSame( "Option 'platform' must be a subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform', " @@ -77,7 +76,7 @@ public function testInvalidPlatformTypeObject(): void public function testInvalidPlatformTypeScalar(): void { - $exception = DBALException::invalidPlatformType('some string'); + $exception = Exception::invalidPlatformType('some string'); self::assertSame( "Option 'platform' must be an object and subtype of 'Doctrine\DBAL\Platforms\AbstractPlatform'. " diff --git a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php index 29a8441f646..078875a4086 100644 --- a/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php +++ b/tests/Doctrine/Tests/DBAL/Driver/AbstractDriverTest.php @@ -3,10 +3,10 @@ namespace Doctrine\Tests\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DriverException as DriverExceptionInterface; use Doctrine\DBAL\Driver\ExceptionConverterDriver; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\ConnectionException; use Doctrine\DBAL\Exception\ConstraintViolationException; use Doctrine\DBAL\Exception\DatabaseObjectExistsException; @@ -138,7 +138,7 @@ public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion( $this->markTestSkipped('This test is only intended for version aware platform drivers.'); } - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->driver->createDatabasePlatformForVersion('foo'); } diff --git a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php index 03117de7f32..e6544de56f5 100644 --- a/tests/Doctrine/Tests/DBAL/DriverManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/DriverManagerTest.php @@ -4,13 +4,13 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\DrizzlePDOMySql\Driver as DrizzlePDOMySqlDriver; use Doctrine\DBAL\Driver\PDO\MySQL\Driver as PDOMySQLDriver; use Doctrine\DBAL\Driver\PDO\SQLite\Driver as PDOSQLiteDriver; use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Sharding\PoolingShardConnection; use Doctrine\DBAL\Sharding\ShardChoser\MultiTenantShardChoser; @@ -30,7 +30,7 @@ class DriverManagerTest extends DbalTestCase */ public function testInvalidPdoInstance(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); DriverManager::getConnection(['pdo' => 'test']); } @@ -61,14 +61,14 @@ public function testPdoInstanceSetErrorMode(): void public function testCheckParams(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); DriverManager::getConnection([]); } public function testInvalidDriver(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); DriverManager::getConnection(['driver' => 'invalid_driver']); } @@ -111,7 +111,7 @@ public function testCustomWrapper(): void */ public function testInvalidWrapperClass(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $options = [ 'pdo' => new PDO('sqlite::memory:'), @@ -123,7 +123,7 @@ public function testInvalidWrapperClass(): void public function testInvalidDriverClass(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $options = ['driverClass' => stdClass::class]; @@ -227,7 +227,7 @@ public function testDatabaseUrl($url, $expected): void $options = is_array($url) ? $url : ['url' => $url]; if ($expected === false) { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); } $conn = DriverManager::getConnection($options); diff --git a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php index 6984f7a471d..ef68b5be62f 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/DataAccessTest.php @@ -4,13 +4,13 @@ use DateTime; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; 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\PDO\Connection as PDOConnection; use Doctrine\DBAL\Driver\PDO\OCI\Driver as PDOOCIDriver; use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\SqlitePlatform; @@ -267,7 +267,7 @@ public function testFetchAllWithMissingTypes(callable $fetch): void $datetime = new DateTime($datetimeString); $sql = 'SELECT test_int, test_datetime FROM fetch_table WHERE test_int = ? AND test_datetime = ?'; - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $fetch($this->connection, $sql, [1, $datetime]); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index 53914d48c6d..d94a8f8dabe 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -2,8 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Schema; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Connection; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BlobType; @@ -19,7 +19,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase */ public function testListDatabases(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->schemaManager->listDatabases(); } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php index 0abb50bdf92..77cd108b595 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Ticket/DBAL630Test.php @@ -2,8 +2,8 @@ namespace Doctrine\Tests\DBAL\Functional\Ticket; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\PDO\Connection; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; use Doctrine\Tests\DbalFunctionalTestCase; use PDO; @@ -28,7 +28,7 @@ protected function setUp(): void try { $this->connection->exec('CREATE TABLE dbal630 (id SERIAL, bool_col BOOLEAN NOT NULL);'); $this->connection->exec('CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);'); - } catch (DBALException $e) { + } catch (Exception $e) { } $this->running = true; diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index c59d966c265..b098f617ece 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -3,8 +3,8 @@ namespace Doctrine\Tests\DBAL\Platforms; use Doctrine\Common\EventManager; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\Keywords\KeywordList; use Doctrine\DBAL\Schema\Column; @@ -90,7 +90,7 @@ public function testGetInvalidForeignKeyReferentialActionSQL(): void public function testGetUnknownDoctrineMappingType(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getDoctrineTypeMapping('foobar'); } @@ -102,7 +102,7 @@ public function testRegisterDoctrineMappingType(): void public function testRegisterUnknownDoctrineMappingType(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->registerDoctrineTypeMapping('foo', 'bar'); } @@ -151,7 +151,7 @@ public function testCreateWithNoColumns(): void { $table = new Table('test'); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $sql = $this->platform->getCreateTableSQL($table); } @@ -724,7 +724,7 @@ public function testQuotesReservedKeywordInIndexDeclarationSQL(): void $index = new Index('select', ['foo']); if (! $this->supportsInlineIndexDeclaration()) { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); } self::assertSame( @@ -752,7 +752,7 @@ protected function supportsCommentOnStatement(): bool public function testGetCreateSchemaSQL(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getCreateSchemaSQL('schema'); } @@ -783,7 +783,7 @@ public function testUsesSequenceEmulatedIdentityColumns(): void public function testReturnsIdentitySequenceName(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getIdentitySequenceName('mytable', 'mycolumn'); } @@ -810,7 +810,7 @@ protected function getBinaryMaxLength(): int public function testReturnsBinaryTypeDeclarationSQL(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getBinaryTypeDeclarationSQL([]); } @@ -1218,7 +1218,7 @@ public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupport $this->markTestSkipped(sprintf('%s supports inline column comments.', get_class($this->platform))); } - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->expectExceptionMessage( "Operation '" . AbstractPlatform::class . "::getInlineColumnCommentSQL' is not supported by platform." ); @@ -1247,7 +1247,7 @@ public function testQuoteStringLiteral(): void public function testReturnsGuidTypeDeclarationSQL(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getGuidTypeDeclarationSQL([]); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index fba77a86756..ddb7df84a00 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\SQLServerPlatform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; @@ -61,7 +61,7 @@ public function getGenerateAlterTableSql(): array public function testDoesNotSupportRegexp(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getRegexpExpression(); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 22e02ee405d..333a6e26bae 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Schema\Column; @@ -74,7 +74,7 @@ public static function dataInvalidIdentifiers(): iterable */ public function testInvalidIdentifiers(string $identifier): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $platform = $this->createPlatform(); $platform->assertValidIdentifier($identifier); @@ -120,7 +120,7 @@ public function getGenerateAlterTableSql(): array public function testRLike(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); self::assertEquals('RLIKE', $this->platform->getRegexpExpression()); } @@ -156,7 +156,7 @@ public function testGeneratesTransactionsCommands(): void public function testCreateDatabaseThrowsException(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); self::assertEquals('CREATE DATABASE foobar', $this->platform->getCreateDatabaseSQL('foobar')); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 6e0ae423063..5f3bd50e2ac 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\LockMode; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SQLAnywherePlatform; @@ -522,7 +522,7 @@ public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL(): void public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getIndexDeclarationSQL('index', new Index('index', [])); } @@ -712,7 +712,7 @@ public function testGeneratesSQLSnippets(): void public function testDoesNotSupportRegexp(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getRegexpExpression(); } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index 83e25717ed6..1bf0fd63ef5 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\Column; @@ -256,14 +256,14 @@ public function getGenerateUniqueIndexSql(): string public function testGeneratesForeignKeyCreationSql(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); parent::testGeneratesForeignKeyCreationSql(); } public function testGeneratesConstraintCreationSql(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); parent::testGeneratesConstraintCreationSql(); } @@ -345,7 +345,7 @@ public function testAlterTableAddColumns(): void */ public function testAlterTableAddComplexColumns(TableDiff $diff): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getAlterTableSQL($diff); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php index 25a50ba999e..c596fecfc9c 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/TableTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/TableTest.php @@ -2,7 +2,7 @@ namespace Doctrine\Tests\DBAL\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Schema\Column; @@ -20,7 +20,7 @@ class TableTest extends DbalTestCase { public function testCreateWithInvalidTableName(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); new Table(''); } diff --git a/tests/Doctrine/Tests/DBAL/StatementTest.php b/tests/Doctrine/Tests/DBAL/StatementTest.php index 5cacf902cc6..e40c0d15378 100644 --- a/tests/Doctrine/Tests/DBAL/StatementTest.php +++ b/tests/Doctrine/Tests/DBAL/StatementTest.php @@ -4,15 +4,14 @@ use Doctrine\DBAL\Configuration; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\Connection as DriverConnection; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\FetchMode; use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; use Doctrine\Tests\DbalTestCase; -use Exception; use PDOStatement; use PHPUnit\Framework\MockObject\MockObject; @@ -133,7 +132,7 @@ public function testExecuteCallsLoggerStopQueryOnException(): void $this->conn->expects($this->any()) ->method('handleExceptionDuringQuery') - ->will($this->throwException(new DBALException())); + ->will($this->throwException(new Exception())); $logger->expects($this->once()) ->method('startQuery'); @@ -143,11 +142,11 @@ public function testExecuteCallsLoggerStopQueryOnException(): void $this->pdoStatement->expects($this->once()) ->method('execute') - ->will($this->throwException(new Exception('Mock test exception'))); + ->will($this->throwException(new \Exception('Mock test exception'))); $statement = new Statement('', $this->conn); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $statement->execute(); } diff --git a/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php b/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php index 98b0fd99a40..1cd7dca4fe1 100644 --- a/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php +++ b/tests/Doctrine/Tests/DBAL/Types/TypeRegistryTest.php @@ -4,7 +4,7 @@ namespace Doctrine\Tests\DBAL\Types; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Types\BinaryType; use Doctrine\DBAL\Types\BlobType; use Doctrine\DBAL\Types\StringType; @@ -42,7 +42,7 @@ public function testGet(): void self::assertSame($this->testType, $this->registry->get(self::TEST_TYPE_NAME)); self::assertSame($this->otherTestType, $this->registry->get(self::OTHER_TEST_TYPE_NAME)); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->registry->get('unknown'); } @@ -65,7 +65,7 @@ public function testLookupName(): void $this->registry->lookupName($this->otherTestType) ); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->registry->lookupName(new TextType()); } @@ -90,7 +90,7 @@ public function testRegisterWithAlradyRegisteredName(): void { $this->registry->register('some', new TextType()); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->registry->register('some', new TextType()); } @@ -100,7 +100,7 @@ public function testRegisterWithAlreadyRegisteredInstance(): void $this->registry->register('some', $newType); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->registry->register('other', $newType); } @@ -132,13 +132,13 @@ public function testOverrideWithAlreadyRegisteredInstance(): void $this->registry->register('first', $newType); $this->registry->register('second', new StringType()); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->registry->override('second', $newType); } public function testOverrideWithUnknownType(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->registry->override('unknown', new TextType()); } From 34f3ceddf01e6030dd5332928409020309bc7187 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 10 Sep 2020 15:02:36 -0700 Subject: [PATCH 14/18] Handle both ways of PDO reporting failed connection --- .../DBAL/Driver/AbstractPostgreSQLDriver.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php index 9e293298133..1a33b6609fe 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php @@ -31,7 +31,9 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri */ public function convertException($message, DriverException $exception) { - switch ($exception->getSQLState()) { + $sqlState = $exception->getSQLState(); + + switch ($sqlState) { case '40001': case '40P01': return new Exception\DeadlockException($message, $exception); @@ -69,9 +71,13 @@ public function convertException($message, DriverException $exception) case '42P07': return new Exception\TableExistsException($message, $exception); + case '08006': + return new Exception\ConnectionException($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. + // Prior to fixing https://bugs.php.net/bug.php?id=64705 (PHP 7.3.22 and PHP 7.4.10), + // in some cases (mainly connection errors) the PDO exception wouldn't provide a SQLSTATE via its code. + // The exception code would be 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); From 3caa55c72abec675aa15cdf01de261be7cb58043 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 5 Sep 2020 08:31:30 -0700 Subject: [PATCH 15/18] Revert "Use proper check in acceptForeignKey()" This reverts commit f0c1af4b1a08076fdd2e4c7ec22c0b805e246e0e. --- .../Visitor/CreateSchemaSqlCollector.php | 2 +- .../DBAL/Functional/Schema/ForeignKeyTest.php | 37 ------------------- .../Visitor/CreateSchemaSqlCollectorTest.php | 8 ++-- 3 files changed, 5 insertions(+), 42 deletions(-) delete mode 100644 tests/Doctrine/Tests/DBAL/Functional/Schema/ForeignKeyTest.php diff --git a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php index c3428ce58ac..b2fab3ae4af 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/CreateSchemaSqlCollector.php @@ -56,7 +56,7 @@ public function acceptTable(Table $table) */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { - if (! $this->platform->supportsCreateDropForeignKeyConstraints()) { + if (! $this->platform->supportsForeignKeyConstraints()) { return; } diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/ForeignKeyTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/ForeignKeyTest.php deleted file mode 100644 index c0c82286e36..00000000000 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/ForeignKeyTest.php +++ /dev/null @@ -1,37 +0,0 @@ -createTable('referenced_table'); - $referencedTable->addColumn('id', 'integer'); - $referencedTable->setPrimaryKey(['id']); - - $referencingTable = $schema->createTable('referencing_table'); - $referencingTable->addColumn('referenced_id', 'integer'); - $referencingTable->addForeignKeyConstraint( - $referencedTable, - ['referenced_id'], - ['id'] - ); - - foreach ($schema->toSql($this->connection->getDatabasePlatform()) as $sql) { - $this->connection->exec($sql); - } - - self::assertCount( - 1, - $this->connection->getSchemaManager()->listTableForeignKeys('referencing_table') - ); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php index ae7ba2a1efc..2610f756e0f 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -29,7 +29,7 @@ protected function setUp(): void 'getCreateSchemaSQL', 'getCreateSequenceSQL', 'getCreateTableSQL', - 'supportsCreateDropForeignKeyConstraints', + 'supportsForeignKeyConstraints', 'supportsSchemas', ] ) @@ -76,11 +76,11 @@ public function testAcceptsTable(): void public function testAcceptsForeignKey(): void { $this->platformMock->expects($this->at(0)) - ->method('supportsCreateDropForeignKeyConstraints') + ->method('supportsForeignKeyConstraints') ->will($this->returnValue(false)); $this->platformMock->expects($this->at(1)) - ->method('supportsCreateDropForeignKeyConstraints') + ->method('supportsForeignKeyConstraints') ->will($this->returnValue(true)); $table = $this->createTableMock(); @@ -106,7 +106,7 @@ public function testAcceptsSequences(): void public function testResetsQueries(): void { - foreach (['supportsSchemas', 'supportsCreateDropForeignKeyConstraints'] as $method) { + foreach (['supportsSchemas', 'supportsForeignKeyConstraints'] as $method) { $this->platformMock->expects($this->any()) ->method($method) ->will($this->returnValue(true)); From baec4b8ea8aabe7b9c58b403d706465c897f4be9 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Sat, 5 Sep 2020 08:29:48 -0700 Subject: [PATCH 16/18] Revert "Add full support for foreign key constraints for SQLite" This reverts commit 85a983c3f8d6447c4441832477def1c28d57bee9. --- .../DBAL/Driver/AbstractSQLiteDriver.php | 4 - .../Internal/DependencyOrderCalculator.php | 131 ------------------ .../DBAL/Internal/DependencyOrderEdge.php | 12 -- .../DBAL/Internal/DependencyOrderNode.php | 18 --- .../DBAL/Platforms/AbstractPlatform.php | 10 -- .../DBAL/Platforms/SqlitePlatform.php | 15 +- lib/Doctrine/DBAL/Schema/SchemaDiff.php | 49 +------ .../Schema/Visitor/DropSchemaSqlCollector.php | 4 - phpstan.neon.dist | 3 - .../Tests/DBAL/Functional/ExceptionTest.php | 4 +- .../SchemaManagerFunctionalTestCase.php | 51 ------- .../DependencyOrderCalculatorTest.php | 56 -------- .../Platforms/AbstractPlatformTestCase.php | 20 ++- .../Tests/DBAL/Schema/SchemaDiffTest.php | 6 +- 14 files changed, 25 insertions(+), 358 deletions(-) delete mode 100644 lib/Doctrine/DBAL/Internal/DependencyOrderCalculator.php delete mode 100644 lib/Doctrine/DBAL/Internal/DependencyOrderEdge.php delete mode 100644 lib/Doctrine/DBAL/Internal/DependencyOrderNode.php delete mode 100644 tests/Doctrine/Tests/DBAL/Internal/DependencyOrderCalculatorTest.php diff --git a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php index f0ff91a1255..0d2c72e09fe 100644 --- a/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php +++ b/lib/Doctrine/DBAL/Driver/AbstractSQLiteDriver.php @@ -70,10 +70,6 @@ public function convertException($message, DriverException $exception) return new Exception\ConnectionException($message, $exception); } - if (strpos($exception->getMessage(), 'FOREIGN KEY constraint failed') !== false) { - return new Exception\ForeignKeyConstraintViolationException($message, $exception); - } - return new Exception\DriverException($message, $exception); } diff --git a/lib/Doctrine/DBAL/Internal/DependencyOrderCalculator.php b/lib/Doctrine/DBAL/Internal/DependencyOrderCalculator.php deleted file mode 100644 index 55b70c190ab..00000000000 --- a/lib/Doctrine/DBAL/Internal/DependencyOrderCalculator.php +++ /dev/null @@ -1,131 +0,0 @@ - - */ - private $nodeList = []; - - /** - * Volatile variable holding calculated nodes during sorting process. - * - * @var array - */ - private $sortedNodeList = []; - - /** - * Checks for node (vertex) existence in graph. - */ - public function hasNode(string $hash): bool - { - return isset($this->nodeList[$hash]); - } - - /** - * Adds a new node (vertex) to the graph, assigning its hash and value. - * - * @param object $node - */ - public function addNode(string $hash, $node): void - { - $vertex = new DependencyOrderNode(); - - $vertex->hash = $hash; - $vertex->state = self::NOT_VISITED; - $vertex->value = $node; - - $this->nodeList[$hash] = $vertex; - } - - /** - * Adds a new dependency (edge) to the graph using their hashes. - */ - public function addDependency(string $fromHash, string $toHash): void - { - $vertex = $this->nodeList[$fromHash]; - $edge = new DependencyOrderEdge(); - - $edge->from = $fromHash; - $edge->to = $toHash; - - $vertex->dependencyList[$toHash] = $edge; - } - - /** - * Return a valid order list of all current nodes. - * The desired topological sorting is the reverse post order of these searches. - * - * {@internal Highly performance-sensitive method.} - * - * @return array - */ - public function sort(): array - { - foreach ($this->nodeList as $vertex) { - if ($vertex->state !== self::NOT_VISITED) { - continue; - } - - $this->visit($vertex); - } - - $sortedList = $this->sortedNodeList; - - $this->nodeList = []; - $this->sortedNodeList = []; - - return array_reverse($sortedList); - } - - /** - * Visit a given node definition for reordering. - * - * {@internal Highly performance-sensitive method.} - */ - private function visit(DependencyOrderNode $vertex): void - { - $vertex->state = self::IN_PROGRESS; - - foreach ($vertex->dependencyList as $edge) { - $adjacentVertex = $this->nodeList[$edge->to]; - - switch ($adjacentVertex->state) { - case self::VISITED: - case self::IN_PROGRESS: - // Do nothing, since node was already visited or is - // currently visited - break; - - case self::NOT_VISITED: - $this->visit($adjacentVertex); - } - } - - if ($vertex->state === self::VISITED) { - return; - } - - $vertex->state = self::VISITED; - - $this->sortedNodeList[] = $vertex->value; - } -} diff --git a/lib/Doctrine/DBAL/Internal/DependencyOrderEdge.php b/lib/Doctrine/DBAL/Internal/DependencyOrderEdge.php deleted file mode 100644 index fa1a0453c46..00000000000 --- a/lib/Doctrine/DBAL/Internal/DependencyOrderEdge.php +++ /dev/null @@ -1,12 +0,0 @@ -supportsCreateDropForeignKeyConstraints()) { - $createFlags |= AbstractPlatform::CREATE_FOREIGNKEYS; - } - - foreach ($this->getNewTablesSortedByDependencies() as $table) { - $sql = array_merge($sql, $platform->getCreateTableSQL($table, $createFlags)); + foreach ($this->newTables as $table) { + $sql = array_merge( + $sql, + $platform->getCreateTableSQL($table, AbstractPlatform::CREATE_INDEXES) + ); - if (! $platform->supportsCreateDropForeignKeyConstraints()) { + if (! $platform->supportsForeignKeyConstraints()) { continue; } @@ -171,37 +167,4 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false) return $sql; } - - /** - * Sorts tables by dependencies so that they are created in the right order. - * - * This is necessary when one table depends on another while creating foreign key - * constraints directly during CREATE TABLE. - * - * @return array - */ - private function getNewTablesSortedByDependencies() - { - $calculator = new DependencyOrderCalculator(); - $newTables = []; - - foreach ($this->newTables as $table) { - $newTables[$table->getName()] = true; - $calculator->addNode($table->getName(), $table); - } - - foreach ($this->newTables as $table) { - foreach ($table->getForeignKeys() as $foreignKey) { - $foreignTableName = $foreignKey->getForeignTableName(); - - if (! isset($newTables[$foreignTableName])) { - continue; - } - - $calculator->addDependency($foreignTableName, $table->getName()); - } - } - - return $calculator->sort(); - } } diff --git a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php index a2355ac7de3..9f778109bbe 100644 --- a/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php +++ b/lib/Doctrine/DBAL/Schema/Visitor/DropSchemaSqlCollector.php @@ -48,10 +48,6 @@ public function acceptTable(Table $table) */ public function acceptForeignKey(Table $localTable, ForeignKeyConstraint $fkConstraint) { - if (! $this->platform->supportsCreateDropForeignKeyConstraints()) { - return; - } - if (strlen($fkConstraint->getName()) === 0) { throw SchemaException::namedForeignKeyRequired($localTable, $fkConstraint); } diff --git a/phpstan.neon.dist b/phpstan.neon.dist index 79a126fea99..ba1a1b9558a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -44,9 +44,6 @@ parameters: message: '~^Call to function in_array\(\) with arguments Doctrine\\DBAL\\Schema\\Column, array and true will always evaluate to false\.$~' path: %currentWorkingDirectory%/lib/Doctrine/DBAL/Schema/Table.php - # False Positive - - '~Strict comparison using === between 1 and 2 will always evaluate to false~' - # Needs Generics - '~Method Doctrine\\DBAL\\Schema\\SchemaDiff::getNewTablesSortedByDependencies\(\) should return array but returns array.~' diff --git a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php index 8cd319697a1..b72356347e1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/ExceptionTest.php @@ -79,8 +79,8 @@ public function testTableExistsException(): void public function testForeignKeyConstraintViolationExceptionOnInsert(): void { - if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') { - $this->connection->exec('PRAGMA foreign_keys=ON'); + if (! $this->connection->getDatabasePlatform()->supportsForeignKeyConstraints()) { + $this->markTestSkipped('Only fails on platforms with foreign key constraints.'); } $this->setUpForeignKeyConstraintViolationExceptionTest(); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php index 11754dc2fc6..d4e5c3ed2d1 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -14,7 +14,6 @@ use Doctrine\DBAL\Schema\Comparator; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Index; -use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaDiff; use Doctrine\DBAL\Schema\Sequence; use Doctrine\DBAL\Schema\Table; @@ -41,7 +40,6 @@ use function current; use function end; use function explode; -use function implode; use function in_array; use function sprintf; use function str_replace; @@ -1567,55 +1565,6 @@ public function testCommentInTable(): void $table = $this->schemaManager->listTableDetails('table_with_comment'); self::assertSame('Foo with control characters \'\\', $table->getComment()); } - - public function testSchemaDiffForeignKeys(): void - { - $schemaManager = $this->connection->getSchemaManager(); - $platform = $this->connection->getDatabasePlatform(); - - $table1 = new Table('child'); - $table1->addColumn('id', 'integer', ['autoincrement' => true]); - $table1->addColumn('parent_id', 'integer'); - $table1->setPrimaryKey(['id']); - $table1->addForeignKeyConstraint('parent', ['parent_id'], ['id']); - - $table2 = new Table('parent'); - $table2->addColumn('id', 'integer', ['autoincrement' => true]); - $table2->setPrimaryKey(['id']); - - $diff = new SchemaDiff([$table1, $table2]); - $sqls = $diff->toSql($platform); - - foreach ($sqls as $sql) { - $this->connection->exec($sql); - } - - $schema = new Schema([ - $schemaManager->listTableDetails('child'), - $schemaManager->listTableDetails('parent'), - ]); - - $this->assertCount(1, $schema->getTable('child')->getForeignKeys()); - - $offlineSchema = new Schema([$table1, $table2]); - - $diff = Comparator::compareSchemas($offlineSchema, $schema); - - foreach ($diff->changedTables as $table) { - if ( - count($table->changedForeignKeys) <= 0 - && count($table->addedForeignKeys) <= 0 - && count($table->removedForeignKeys) <= 0 - ) { - continue; - } - - $this->fail( - 'No changes on foreigh keys should be detected, but we have: ' . - implode(', ', $diff->toSql($platform)) - ); - } - } } interface ListTableColumnsDispatchEventListener diff --git a/tests/Doctrine/Tests/DBAL/Internal/DependencyOrderCalculatorTest.php b/tests/Doctrine/Tests/DBAL/Internal/DependencyOrderCalculatorTest.php deleted file mode 100644 index 2c6227a0be6..00000000000 --- a/tests/Doctrine/Tests/DBAL/Internal/DependencyOrderCalculatorTest.php +++ /dev/null @@ -1,56 +0,0 @@ -calculator = new DependencyOrderCalculator(); - } - - public function testCommitOrdering1(): void - { - $table1 = new Table('table1'); - $table2 = new Table('table2'); - $table3 = new Table('table3'); - $table4 = new Table('table4'); - $table5 = new Table('table5'); - - $this->assertFalse($this->calculator->hasNode($table1->getName())); - - $this->calculator->addNode($table1->getName(), $table1); - $this->calculator->addNode($table2->getName(), $table2); - $this->calculator->addNode($table3->getName(), $table3); - $this->calculator->addNode($table4->getName(), $table4); - $this->calculator->addNode($table5->getName(), $table5); - - $this->assertTrue($this->calculator->hasNode($table1->getName())); - - $this->calculator->addDependency($table1->getName(), $table2->getName()); - $this->calculator->addDependency($table2->getName(), $table3->getName()); - $this->calculator->addDependency($table3->getName(), $table4->getName()); - $this->calculator->addDependency($table5->getName(), $table1->getName()); - - $sorted = $this->calculator->sort(); - - // There is only 1 valid ordering for this constellation - $correctOrder = [$table5, $table1, $table2, $table3, $table4]; - - $this->assertSame($correctOrder, $sorted); - } -} diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index c59d966c265..eef443b8ef2 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -244,10 +244,6 @@ abstract protected function getGenerateForeignKeySql(): string; public function testGeneratesConstraintCreationSql(): void { - if (! $this->platform->supportsCreateDropForeignKeyConstraints()) { - $this->markTestSkipped('Platform does not support creating or dropping foreign key constraints.'); - } - $idx = new Index('constraint_name', ['test'], true, false); $sql = $this->platform->getCreateConstraintSQL($idx, 'test'); self::assertEquals($this->getGenerateConstraintUniqueIndexSql(), $sql); @@ -261,6 +257,18 @@ public function testGeneratesConstraintCreationSql(): void self::assertEquals($this->getGenerateConstraintForeignKeySql($fk), $sql); } + public function testGeneratesForeignKeySqlOnlyWhenSupportingForeignKeys(): void + { + $fk = new ForeignKeyConstraint(['fk_name'], 'foreign', ['id'], 'constraint_fk'); + + if ($this->platform->supportsForeignKeyConstraints()) { + self::assertIsString($this->platform->getCreateForeignKeySQL($fk, 'test')); + } else { + $this->expectException(DBALException::class); + $this->platform->getCreateForeignKeySQL($fk, 'test'); + } + } + protected function getBitAndComparisonExpressionSql(string $value1, string $value2): string { return '(' . $value1 . ' & ' . $value2 . ')'; @@ -1052,9 +1060,9 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL(): array public function testQuotesDropForeignKeySQL(): void { - if (! $this->platform->supportsCreateDropForeignKeyConstraints()) { + if (! $this->platform->supportsForeignKeyConstraints()) { $this->markTestSkipped( - sprintf('%s does not support modifying foreign key constraints.', get_class($this->platform)) + sprintf('%s does not support foreign key constraints.', get_class($this->platform)) ); } diff --git a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php index 73e12d993ab..414d779438e 100644 --- a/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php +++ b/tests/Doctrine/Tests/DBAL/Schema/SchemaDiffTest.php @@ -55,10 +55,6 @@ private function createPlatform(bool $unsafe) ->method('getCreateSchemaSQL') ->with('foo_ns') ->will($this->returnValue('create_schema')); - - $platform->method('supportsCreateDropForeignKeyConstraints') - ->will($this->returnValue(true)); - if ($unsafe) { $platform->expects($this->exactly(1)) ->method('getDropSequenceSql') @@ -109,7 +105,7 @@ private function createPlatform(bool $unsafe) $platform->expects($this->exactly(1)) ->method('supportsSequences') ->will($this->returnValue(true)); - $platform->expects($this->any()) + $platform->expects($this->exactly(2)) ->method('supportsForeignKeyConstraints') ->will($this->returnValue(true)); From 912db7a28be30512a8dc631e06e5be3fb7906a37 Mon Sep 17 00:00:00 2001 From: Sergei Morozov Date: Thu, 10 Sep 2020 08:41:31 -0700 Subject: [PATCH 17/18] Revert "SQLite: Fix wrongly detected reference constraint name on schema change" This reverts commit 7570aeb83efb7efda1714436fe1af5cb9baaaa5d. --- lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php | 2 +- .../Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php index 7819863c405..17cb5efac3c 100644 --- a/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php +++ b/lib/Doctrine/DBAL/Schema/SqliteSchemaManager.php @@ -149,7 +149,7 @@ public function listTableForeignKeys($table, $database = null) $id = $value['id']; $tableForeignKeys[$key] = array_merge($tableForeignKeys[$key], [ - 'constraint_name' => isset($names[$id]) && $names[$id] !== '' ? $names[$id] : null, + 'constraint_name' => isset($names[$id]) && $names[$id] !== '' ? $names[$id] : $id, 'deferrable' => isset($deferrable[$id]) && strtolower($deferrable[$id]) === 'deferrable', 'deferred' => isset($deferred[$id]) && strtolower($deferred[$id]) === 'deferred', ]); diff --git a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php index 8f911867bb4..6764b1ed173 100644 --- a/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Doctrine/Tests/DBAL/Functional/Schema/SqliteSchemaManagerTest.php @@ -101,7 +101,7 @@ public function testListForeignKeysFromExistingDatabase(): void ['parent'], 'user', ['id'], - null, + '1', ['onUpdate' => 'NO ACTION', 'onDelete' => 'CASCADE', 'deferrable' => false, 'deferred' => false] ), new Schema\ForeignKeyConstraint( From d333f7c0e0f5eacdf3baa903b1c18badcd49c9fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9goire=20Paris?= Date: Thu, 3 Sep 2020 22:17:14 +0200 Subject: [PATCH 18/18] Setup automatic release workflow --- .../workflows/release-on-milestone-closed.yml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 .github/workflows/release-on-milestone-closed.yml diff --git a/.github/workflows/release-on-milestone-closed.yml b/.github/workflows/release-on-milestone-closed.yml new file mode 100644 index 00000000000..0a8bf324d97 --- /dev/null +++ b/.github/workflows/release-on-milestone-closed.yml @@ -0,0 +1,45 @@ +name: "Automatic Releases" + +on: + milestone: + types: + - "closed" + +jobs: + release: + name: "Git tag, release & create merge-up PR" + runs-on: "ubuntu-20.04" + + steps: + - name: "Checkout" + uses: "actions/checkout@v2" + + - name: "Release" + uses: "laminas/automatic-releases@1.0.1" + with: + command-name: "laminas:automatic-releases:release" + env: + "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} + "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} + "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} + "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + + - name: "Create Merge-Up Pull Request" + uses: "laminas/automatic-releases@1.0.1" + with: + command-name: "laminas:automatic-releases:create-merge-up-pull-request" + env: + "GITHUB_TOKEN": ${{ secrets.GITHUB_TOKEN }} + "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} + "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} + "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }} + + - name: "Create and/or Switch to new Release Branch" + uses: "laminas/automatic-releases@v1" + with: + command-name: "laminas:automatic-releases:switch-default-branch-to-next-minor" + env: + "GITHUB_TOKEN": ${{ secrets.ORGANIZATION_ADMIN_TOKEN }} + "SIGNING_SECRET_KEY": ${{ secrets.SIGNING_SECRET_KEY }} + "GIT_AUTHOR_NAME": ${{ secrets.GIT_AUTHOR_NAME }} + "GIT_AUTHOR_EMAIL": ${{ secrets.GIT_AUTHOR_EMAIL }}