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" 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 }} diff --git a/.travis.yml b/.travis.yml index 4dcfc4e5dd8..c1cfda3648b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -129,9 +129,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 @@ -152,7 +149,7 @@ 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 ./ci/travis/install-sqlsrv-dependencies.sh @@ -160,7 +157,7 @@ jobs: - bash ./ci/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 ./ci/travis/install-sqlsrv-dependencies.sh diff --git a/UPGRADE.md b/UPGRADE.md index c041608d795..64ba7434353 100644 --- a/UPGRADE.md +++ b/UPGRADE.md @@ -449,6 +449,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/ci/travis/install-mssql.sh b/ci/travis/install-mssql.sh index e4ce49b2c4a..d17058e3455 100644 --- a/ci/travis/install-mssql.sh +++ b/ci/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 \ diff --git a/composer.json b/composer.json index 80ec56a4151..4f426568812 100644 --- a/composer.json +++ b/composer.json @@ -40,7 +40,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", "phpstan/phpstan-strict-rules": "^0.12.2", "phpunit/phpunit": "^9.3", "psalm/plugin-phpunit": "^0.10.0", diff --git a/composer.lock b/composer.lock index af007d119ce..39861217bda 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": "24d769e96bdd77bb222036a69d9c5e1a", + "content-hash": "d336c771203e06590d3d78d116932bfd", "packages": [ { "name": "composer/package-versions-deprecated", @@ -560,6 +560,39 @@ ], "time": "2020-06-25T14:57:39+00:00" }, + { + "name": "dnoegel/php-xdg-base-dir", + "version": "v0.1.1", + "source": { + "type": "git", + "url": "https://github.com/dnoegel/php-xdg-base-dir.git", + "reference": "8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/dnoegel/php-xdg-base-dir/zipball/8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd", + "reference": "8f8a6e48c5ecb0f991c2fdcf5f154a47d85f9ffd", + "shasum": "" + }, + "require": { + "php": ">=5.3.2" + }, + "require-dev": { + "phpunit/phpunit": "~7.0|~6.0|~5.0|~4.8.35" + }, + "type": "library", + "autoload": { + "psr-4": { + "XdgBaseDir\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "implementation of xdg base directory specification for php", + "time": "2019-12-04T15:06:13+00:00" + }, { "name": "doctrine/coding-standard", "version": "8.1.0", @@ -1402,20 +1435,20 @@ }, { "name": "phpstan/phpstan", - "version": "0.12.31", + "version": "0.12.42", "source": { "type": "git", "url": "https://github.com/phpstan/phpstan.git", - "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d" + "reference": "7c43b7c2d5ca6554f6231e82e342a710163ac5f4" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpstan/phpstan/zipball/776c8056b401e1b67f277b9e9fb334d1a274671d", - "reference": "776c8056b401e1b67f277b9e9fb334d1a274671d", + "url": "https://api.github.com/repos/phpstan/phpstan/zipball/7c43b7c2d5ca6554f6231e82e342a710163ac5f4", + "reference": "7c43b7c2d5ca6554f6231e82e342a710163ac5f4", "shasum": "" }, "require": { - "php": "^7.1" + "php": "^7.1|^8.0" }, "conflict": { "phpstan/phpstan-shim": "*" @@ -1454,7 +1487,7 @@ "type": "tidelift" } ], - "time": "2020-06-24T20:55:29+00:00" + "time": "2020-09-02T13:14:53+00:00" }, { "name": "phpstan/phpstan-strict-rules", @@ -3424,16 +3457,16 @@ }, { "name": "vimeo/psalm", - "version": "3.14.2", + "version": "3.16", "source": { "type": "git", "url": "https://github.com/vimeo/psalm.git", - "reference": "3538fe1955d47f6ee926c0769d71af6db08aa488" + "reference": "d03e5ef057d6adc656c0ff7e166c50b73b4f48f3" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/vimeo/psalm/zipball/3538fe1955d47f6ee926c0769d71af6db08aa488", - "reference": "3538fe1955d47f6ee926c0769d71af6db08aa488", + "url": "https://api.github.com/repos/vimeo/psalm/zipball/d03e5ef057d6adc656c0ff7e166c50b73b4f48f3", + "reference": "d03e5ef057d6adc656c0ff7e166c50b73b4f48f3", "shasum": "" }, "require": { @@ -3442,9 +3475,11 @@ "composer/package-versions-deprecated": "^1.8.0", "composer/semver": "^1.4 || ^2.0 || ^3.0", "composer/xdebug-handler": "^1.1", + "dnoegel/php-xdg-base-dir": "^0.1.1", "ext-dom": "*", "ext-json": "*", "ext-libxml": "*", + "ext-mbstring": "*", "ext-simplexml": "*", "ext-tokenizer": "*", "felixfbecker/advanced-json-rpc": "^3.0.3", @@ -3470,10 +3505,11 @@ "phpmyadmin/sql-parser": "5.1.0", "phpspec/prophecy": ">=1.9.0", "phpunit/phpunit": "^7.5.16 || ^8.5 || ^9.0", - "psalm/plugin-phpunit": "^0.10", + "psalm/plugin-phpunit": "^0.11", "slevomat/coding-standard": "^5.0", "squizlabs/php_codesniffer": "^3.5", - "symfony/process": "^4.3" + "symfony/process": "^4.3", + "weirdan/prophecy-shim": "^1.0 || ^2.0" }, "suggest": { "ext-igbinary": "^2.0.5" @@ -3517,7 +3553,7 @@ "inspection", "php" ], - "time": "2020-08-22T14:01:26+00:00" + "time": "2020-09-15T13:39:50+00:00" }, { "name": "webmozart/assert", diff --git a/docs/en/reference/types.rst b/docs/en/reference/types.rst index c504002c300..2262b7cc9c7 100644 --- a/docs/en/reference/types.rst +++ b/docs/en/reference/types.rst @@ -157,6 +157,13 @@ or ``null`` if no data is present. This can lead to type inconsistencies when reverse engineering the type from the database. +ascii_string +++++++++++++ + +Similar to the ``string`` type but for binding non-unicode data. This type +should be used with database vendors where a binding type mismatch +can trigger an implicit cast and lead to performance problems. + text ++++ @@ -583,6 +590,9 @@ Please also notice the mapping specific footnotes for additional information. | | | | +----------------------------------------------------------+ | | | | | ``NCHAR(n)`` [4]_ | +-------------------+---------------+--------------------------+---------+----------------------------------------------------------+ +| **ascii_string** | ``string`` | **SQL Server** | | ``VARCHAR(n)`` | +| | | | | ``CHAR(n)`` | ++-------------------+---------------+--------------------------+---------+----------------------------------------------------------+ | **text** | ``string`` | **MySQL** | *all* | ``TINYTEXT`` [16]_ | | | | | +----------------------------------------------------------+ | | | | | ``TEXT`` [17]_ | diff --git a/phpstan.neon.dist b/phpstan.neon.dist index df626f60dce..a984e36e69a 100644 --- a/phpstan.neon.dist +++ b/phpstan.neon.dist @@ -34,24 +34,11 @@ parameters: message: '~^Call to function in_array\(\) with arguments Doctrine\\DBAL\\Schema\\Column, array and true will always evaluate to false\.$~' path: %currentWorkingDirectory%/src/Schema/Table.php - # https://github.com/phpstan/phpstan/issues/3133 - - - message: '~^Cannot cast array\|bool\|string\|null to int\.$~' - path: %currentWorkingDirectory%/src/Tools/Console/Command/RunSqlCommand.php - # Requires a release of https://github.com/JetBrains/phpstorm-stubs/pull/553 - message: '~^Call to function assert\(\) with true will always evaluate to true\.$~' path: %currentWorkingDirectory%/src/Driver/PDO/Connection.php - # Requires a release of https://github.com/JetBrains/phpstorm-stubs/pull/553 - - - message: '~^Strict comparison using !== between int and false will always evaluate to true\.$~' - path: %currentWorkingDirectory%/src/Driver/PDO/Connection.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/src/Abstraction/Result.php b/src/Abstraction/Result.php index 0fd4d09f6eb..93d0e4643e0 100644 --- a/src/Abstraction/Result.php +++ b/src/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/src/Cache/CacheException.php b/src/Cache/CacheException.php index db5680812e2..3db115bdfae 100644 --- a/src/Cache/CacheException.php +++ b/src/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/src/Connection.php b/src/Connection.php index 5c23a2172ee..715ab0f694c 100644 --- a/src/Connection.php +++ b/src/Connection.php @@ -21,7 +21,6 @@ use Doctrine\DBAL\Query\QueryBuilder; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Types\Type; -use Exception; use Throwable; use Traversable; @@ -153,7 +152,7 @@ class Connection * @param Configuration|null $config The configuration, optional. * @param EventManager|null $eventManager The event manager, optional. * - * @throws DBALException + * @throws Exception */ public function __construct( array $params, @@ -166,7 +165,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']; @@ -208,7 +207,7 @@ public function getParams() * The platforms which don't support the concept of a database (e.g. embedded databases) * must always return a string as an indicator of an implicitly selected database. * - * @throws DBALException + * @throws Exception */ public function getDatabase() { @@ -256,7 +255,7 @@ public function getEventManager() * * @return AbstractPlatform * - * @throws DBALException + * @throws Exception */ public function getDatabasePlatform() { @@ -283,7 +282,7 @@ public function getExpressionBuilder() * @return bool TRUE if the connection was successfully established, FALSE if * the connection is already open. * - * @throws DBALException + * @throws Exception */ public function connect() { @@ -316,7 +315,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 { @@ -343,7 +342,7 @@ private function detectDatabasePlatform(): void * * @return string|null * - * @throws DBALException + * @throws Throwable */ private function getDatabasePlatformVersion() { @@ -361,7 +360,7 @@ private function getDatabasePlatformVersion() if ($this->_conn === null) { try { $this->connect(); - } catch (DBALException $originalException) { + } catch (Exception $originalException) { if (! isset($this->params['dbname'])) { throw $originalException; } @@ -373,7 +372,7 @@ private function getDatabasePlatformVersion() try { $this->connect(); - } catch (DBALException $fallbackException) { + } catch (Exception $fallbackException) { // Either the platform does not support database-less connections // or something else went wrong. // Reset connection parameters and rethrow the original exception. @@ -401,7 +400,7 @@ private function getDatabasePlatformVersion() * * @return string|null * - * @throws DBALException + * @throws Exception */ private function getServerVersion() { @@ -477,7 +476,7 @@ public function setAutoCommit($autoCommit) * * @return array|false False is returned if no rows are found. * - * @throws DBALException + * @throws Exception */ public function fetchAssociative(string $query, array $params = [], array $types = []) { @@ -498,7 +497,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 = []) { @@ -519,7 +518,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 = []) { @@ -558,7 +557,7 @@ public function isTransactionActive() * @param mixed[] $values Column values * @param string[] $conditions Key conditions * - * @throws DBALException + * @throws Exception */ private function addIdentifierCondition( array $identifier, @@ -591,8 +590,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 = []) { @@ -628,7 +626,7 @@ public function close() * * @return int * - * @throws DBALException + * @throws Exception */ public function setTransactionIsolation($level) { @@ -642,7 +640,7 @@ public function setTransactionIsolation($level) * * @return int The current transaction isolation level. * - * @throws DBALException + * @throws Exception */ public function getTransactionIsolation() { @@ -665,7 +663,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 = []) { @@ -700,7 +698,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 = []) { @@ -788,7 +786,7 @@ public function quote($value, $type = ParameterType::STRING) * * @return array> * - * @throws DBALException + * @throws Exception */ public function fetchAllNumeric(string $query, array $params = [], array $types = []): array { @@ -808,7 +806,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 { @@ -828,7 +826,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 { @@ -848,7 +846,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 { @@ -873,7 +871,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 { @@ -897,7 +895,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 { @@ -917,7 +915,7 @@ public function iterateColumn(string $query, array $params = [], array $types = * * @param string $sql The SQL statement to prepare. * - * @throws DBALException + * @throws Exception */ public function prepare(string $sql): Statement { @@ -935,7 +933,7 @@ public function prepare(string $sql): Statement * @param int[]|string[] $types The types the previous parameters are in. * @param QueryCacheProfile|null $qcp The query cache profile, optional. * - * @throws DBALException + * @throws Exception */ public function executeQuery( string $sql, @@ -988,7 +986,7 @@ public function executeQuery( * @param QueryCacheProfile $qcp The query cache profile. * * @throws CacheException - * @throws DBALException + * @throws Exception */ public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp): Result { @@ -1046,7 +1044,7 @@ public function executeCacheQuery($sql, $params, $types, QueryCacheProfile $qcp) * * @return int The number of affected rows. * - * @throws DBALException + * @throws Exception */ public function executeStatement($sql, array $params = [], array $types = []) { @@ -1106,7 +1104,7 @@ public function getTransactionNestingLevel() * * @return string A string representation of the last inserted ID. * - * @throws DBALException + * @throws Exception */ public function lastInsertId($name = null) { @@ -1129,7 +1127,6 @@ public function lastInsertId($name = null) * * @return mixed The value returned by $func * - * @throws Exception * @throws Throwable */ public function transactional(Closure $func) @@ -1140,10 +1137,6 @@ public function transactional(Closure $func) $this->commit(); return $res; - } catch (Exception $e) { - $this->rollBack(); - - throw $e; } catch (Throwable $e) { $this->rollBack(); @@ -1158,7 +1151,7 @@ public function transactional(Closure $func) * * @return void * - * @throws DBALException + * @throws Exception */ public function setNestTransactionsWithSavepoints($nestTransactionsWithSavepoints) { @@ -1197,7 +1190,7 @@ protected function _getNestedTransactionSavePointName() /** * @return bool * - * @throws DBALException + * @throws Exception */ public function beginTransaction() { @@ -1234,7 +1227,7 @@ public function beginTransaction() /** * @return bool * - * @throws DBALException + * @throws Exception */ public function commit() { @@ -1287,7 +1280,7 @@ public function commit() /** * Commits all current nesting transactions. * - * @throws DBALException + * @throws Exception */ private function commitAll(): void { @@ -1309,7 +1302,7 @@ private function commitAll(): void * * @return bool * - * @throws DBALException + * @throws Exception */ public function rollBack() { @@ -1361,7 +1354,7 @@ public function rollBack() * * @return void * - * @throws DBALException + * @throws Exception */ public function createSavepoint($savepoint) { @@ -1379,7 +1372,7 @@ public function createSavepoint($savepoint) * * @return void * - * @throws DBALException + * @throws Exception */ public function releaseSavepoint($savepoint) { @@ -1401,7 +1394,7 @@ public function releaseSavepoint($savepoint) * * @return void * - * @throws DBALException + * @throws Exception */ public function rollbackSavepoint($savepoint) { @@ -1417,7 +1410,7 @@ public function rollbackSavepoint($savepoint) * * @return DriverConnection * - * @throws DBALException + * @throws Exception */ public function getWrappedConnection() { @@ -1434,7 +1427,7 @@ public function getWrappedConnection() * * @return AbstractSchemaManager * - * @throws DBALException + * @throws Exception */ public function getSchemaManager() { @@ -1490,7 +1483,7 @@ public function isRollbackOnly() * * @return mixed The converted value. * - * @throws DBALException + * @throws Exception */ public function convertToDatabaseValue($value, $type) { @@ -1506,7 +1499,7 @@ public function convertToDatabaseValue($value, $type) * * @return mixed The converted type. * - * @throws DBALException + * @throws Exception */ public function convertToPHPValue($value, $type) { @@ -1521,7 +1514,7 @@ public function convertToPHPValue($value, $type) * @param mixed[] $params The map/list of named/positional parameters. * @param int[]|string[] $types The parameter types (PDO binding types or DBAL mapping types). * - * @throws DBALException + * @throws Exception */ private function _bindTypedValues(DriverStatement $stmt, array $params, array $types): void { @@ -1564,7 +1557,7 @@ private function _bindTypedValues(DriverStatement $stmt, array $params, array $t * * @return mixed[] [0] => the (escaped) value, [1] => the binding type. * - * @throws DBALException + * @throws Exception */ private function getBindingInfo($value, $type) { @@ -1648,7 +1641,7 @@ final public function convertExceptionDuringQuery( string $sql, array $params = [], array $types = [] - ): DBALException { + ): Exception { $message = "An exception occurred while executing '" . $sql . "'"; if (count($params) > 0) { @@ -1665,7 +1658,7 @@ final public function convertExceptionDuringQuery( /** * @internal */ - final public function convertException(DriverException $e): DBALException + final public function convertException(DriverException $e): Exception { return $this->handleDriverException( $e, @@ -1697,7 +1690,7 @@ private function formatParameters(array $params): string }, $params)) . ']'; } - private function handleDriverException(DriverException $driverException, string $message): DBALException + private function handleDriverException(DriverException $driverException, string $message): Exception { if ($this->exceptionConverter === null) { $this->exceptionConverter = $this->_driver->getExceptionConverter(); diff --git a/src/ConnectionException.php b/src/ConnectionException.php index f1914f5294e..8426ca28891 100644 --- a/src/ConnectionException.php +++ b/src/ConnectionException.php @@ -5,7 +5,7 @@ /** * @psalm-immutable */ -class ConnectionException extends DBALException +class ConnectionException extends Exception { /** * @return ConnectionException diff --git a/src/Connections/PrimaryReadReplicaConnection.php b/src/Connections/PrimaryReadReplicaConnection.php index 00227598cff..8d52d8595ae 100644 --- a/src/Connections/PrimaryReadReplicaConnection.php +++ b/src/Connections/PrimaryReadReplicaConnection.php @@ -5,12 +5,12 @@ use Doctrine\Common\EventManager; 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\Driver\Exception as DriverException; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Statement; use InvalidArgumentException; @@ -95,7 +95,7 @@ class PrimaryReadReplicaConnection extends Connection * * @param mixed[] $params * - * @throws DBALException + * @throws Exception * @throws InvalidArgumentException */ public function __construct( @@ -228,7 +228,7 @@ public function ensureConnectedToReplica(): bool * * @return DriverConnection * - * @throws DBALException + * @throws Exception */ protected function connectTo($connectionName) { diff --git a/src/DBALException.php b/src/DBALException.php index 10cc84333b5..b4d55ae4184 100644 --- a/src/DBALException.php +++ b/src/DBALException.php @@ -4,7 +4,6 @@ use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Types\Type; -use Exception; use function get_class; use function gettype; @@ -14,18 +13,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)); } /** @@ -34,7 +35,7 @@ public static function notSupported($method) 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, @@ -43,7 +44,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, @@ -58,11 +59,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".', @@ -75,12 +76,12 @@ public static function invalidPlatformVersionSpecified($version, $expectedFormat /** * @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 !== null) { - 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', @@ -89,7 +90,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().'); } @@ -97,33 +98,33 @@ 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)); } /** * @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.' ); } @@ -131,39 +132,39 @@ public static function invalidDriverClass($driverClass) /** * @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 ' . @@ -175,23 +176,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/src/Driver/API/PostgreSQL/ExceptionConverter.php b/src/Driver/API/PostgreSQL/ExceptionConverter.php index 0143e776216..462b2982767 100644 --- a/src/Driver/API/PostgreSQL/ExceptionConverter.php +++ b/src/Driver/API/PostgreSQL/ExceptionConverter.php @@ -41,6 +41,9 @@ public function convert(string $message, Exception $exception): DriverException break; + case '08006': + return new ConnectionException($message, $exception); + case '23502': return new NotNullConstraintViolationException($message, $exception); @@ -66,8 +69,8 @@ public function convert(string $message, Exception $exception): DriverException return new TableExistsException($message, $exception); } - // 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. // We have to match against the SQLSTATE in the error message in these cases. if ($exception->getCode() === 7 && strpos($exception->getMessage(), 'SQLSTATE[08006]') !== false) { return new ConnectionException($message, $exception); diff --git a/src/Driver/API/SQLite/ExceptionConverter.php b/src/Driver/API/SQLite/ExceptionConverter.php index 9e6529b9d13..42bba99f4e1 100644 --- a/src/Driver/API/SQLite/ExceptionConverter.php +++ b/src/Driver/API/SQLite/ExceptionConverter.php @@ -8,7 +8,6 @@ use Doctrine\DBAL\Driver\Exception; use Doctrine\DBAL\Exception\ConnectionException; use Doctrine\DBAL\Exception\DriverException; -use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Doctrine\DBAL\Exception\InvalidFieldNameException; use Doctrine\DBAL\Exception\LockWaitTimeoutException; use Doctrine\DBAL\Exception\NonUniqueFieldNameException; @@ -76,10 +75,6 @@ public function convert(string $message, Exception $exception): DriverException return new ConnectionException($message, $exception); } - if (strpos($exception->getMessage(), 'FOREIGN KEY constraint failed') !== false) { - return new ForeignKeyConstraintViolationException($message, $exception); - } - return new DriverException($message, $exception); } } diff --git a/src/Driver/AbstractMySQLDriver.php b/src/Driver/AbstractMySQLDriver.php index 0f82517f1d0..b402a601ce0 100644 --- a/src/Driver/AbstractMySQLDriver.php +++ b/src/Driver/AbstractMySQLDriver.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\API\ExceptionConverter; use Doctrine\DBAL\Driver\API\MySQL; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\MariaDb1027Platform; use Doctrine\DBAL\Platforms\MySQL57Platform; @@ -26,7 +26,7 @@ abstract class AbstractMySQLDriver implements VersionAwarePlatformDriver /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ public function createDatabasePlatformForVersion($version) { @@ -55,7 +55,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 { @@ -66,7 +66,7 @@ private function getOracleMysqlVersionNumber(string $versionString): string $versionParts ) === 0 ) { - throw DBALException::invalidPlatformVersionSpecified( + throw Exception::invalidPlatformVersionSpecified( $versionString, '..' ); @@ -89,7 +89,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 { @@ -100,7 +100,7 @@ private function getMariaDbMysqlVersionNumber(string $versionString): string $versionParts ) === 0 ) { - throw DBALException::invalidPlatformVersionSpecified( + throw Exception::invalidPlatformVersionSpecified( $versionString, '^(?:5\.5\.5-)?(mariadb-)?..' ); diff --git a/src/Driver/AbstractPostgreSQLDriver.php b/src/Driver/AbstractPostgreSQLDriver.php index c7e343e76f6..883f9ae4cc6 100644 --- a/src/Driver/AbstractPostgreSQLDriver.php +++ b/src/Driver/AbstractPostgreSQLDriver.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\API\ExceptionConverter; use Doctrine\DBAL\Driver\API\PostgreSQL; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Platforms\PostgreSQL100Platform; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; @@ -26,7 +26,7 @@ abstract class AbstractPostgreSQLDriver implements VersionAwarePlatformDriver public function createDatabasePlatformForVersion($version) { if (preg_match('/^(?P\d+)(?:\.(?P\d+)(?:\.(?P\d+))?)?/', $version, $versionParts) === 0) { - throw DBALException::invalidPlatformVersionSpecified( + throw Exception::invalidPlatformVersionSpecified( $version, '..' ); diff --git a/src/Driver/Mysqli/Statement.php b/src/Driver/Mysqli/Statement.php index 657a4e56e3c..b3a5ca87465 100644 --- a/src/Driver/Mysqli/Statement.php +++ b/src/Driver/Mysqli/Statement.php @@ -28,6 +28,7 @@ final class Statement implements StatementInterface { /** @var string[] */ protected static $_paramTypeMap = [ + ParameterType::ASCII => 's', ParameterType::STRING => 's', ParameterType::BINARY => 's', ParameterType::BOOLEAN => 'i', diff --git a/src/Driver/PDO/SQLSrv/Statement.php b/src/Driver/PDO/SQLSrv/Statement.php index 12d956bb950..8b8e551fcdb 100644 --- a/src/Driver/PDO/SQLSrv/Statement.php +++ b/src/Driver/PDO/SQLSrv/Statement.php @@ -28,11 +28,20 @@ public function __construct(PDOStatement $statement) */ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null, $driverOptions = null) { - if ( - ($type === ParameterType::LARGE_OBJECT || $type === ParameterType::BINARY) - && $driverOptions === null - ) { - $driverOptions = PDO::SQLSRV_ENCODING_BINARY; + switch ($type) { + case ParameterType::LARGE_OBJECT: + case ParameterType::BINARY: + if ($driverOptions === null) { + $driverOptions = PDO::SQLSRV_ENCODING_BINARY; + } + + break; + + case ParameterType::ASCII: + $type = PDO::PARAM_STR; + $length = 0; + $driverOptions = PDO::SQLSRV_ENCODING_SYSTEM; + break; } return $this->statement->bindParam($param, $variable, $type, $length, $driverOptions); diff --git a/src/Driver/PDO/Statement.php b/src/Driver/PDO/Statement.php index 550984c706a..7107fa2dff5 100644 --- a/src/Driver/PDO/Statement.php +++ b/src/Driver/PDO/Statement.php @@ -20,6 +20,7 @@ final class Statement implements StatementInterface ParameterType::NULL => PDO::PARAM_NULL, ParameterType::INTEGER => PDO::PARAM_INT, ParameterType::STRING => PDO::PARAM_STR, + ParameterType::ASCII => PDO::PARAM_STR, ParameterType::BINARY => PDO::PARAM_LOB, ParameterType::LARGE_OBJECT => PDO::PARAM_LOB, ParameterType::BOOLEAN => PDO::PARAM_BOOL, diff --git a/src/Driver/SQLSrv/Statement.php b/src/Driver/SQLSrv/Statement.php index fc482ab42f0..fe380fa11cd 100644 --- a/src/Driver/SQLSrv/Statement.php +++ b/src/Driver/SQLSrv/Statement.php @@ -182,6 +182,14 @@ private function prepare() ]; break; + case ParameterType::ASCII: + $params[$column - 1] = [ + &$variable, + SQLSRV_PARAM_IN, + SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR), + ]; + break; + default: $params[$column - 1] =& $variable; break; diff --git a/src/DriverManager.php b/src/DriverManager.php index 158a2e2695d..ac65e421adf 100644 --- a/src/DriverManager.php +++ b/src/DriverManager.php @@ -109,7 +109,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) @@ -155,7 +155,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']; @@ -179,7 +179,7 @@ public static function getAvailableDrivers(): array * * @param mixed[] $params The list of parameters. * - * @throws DBALException + * @throws Exception */ private static function _checkParams(array $params): void { @@ -187,21 +187,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']); } } @@ -225,7 +225,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 { @@ -240,7 +240,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); @@ -376,7 +376,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 { @@ -401,7 +401,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/src/Event/Listeners/OracleSessionInit.php b/src/Event/Listeners/OracleSessionInit.php index dba317367c8..d6d1fd9d169 100644 --- a/src/Event/Listeners/OracleSessionInit.php +++ b/src/Event/Listeners/OracleSessionInit.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Event\Listeners; use Doctrine\Common\EventSubscriber; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; use function array_change_key_case; use function array_merge; @@ -46,7 +46,7 @@ public function __construct(array $oracleSessionVars = []) /** * @return void * - * @throws DBALException + * @throws Exception */ public function postConnect(ConnectionEventArgs $args) { diff --git a/src/Event/Listeners/SQLSessionInit.php b/src/Event/Listeners/SQLSessionInit.php index a1fd2a9ac4e..f7a4e9129d3 100644 --- a/src/Event/Listeners/SQLSessionInit.php +++ b/src/Event/Listeners/SQLSessionInit.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Event\Listeners; use Doctrine\Common\EventSubscriber; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Event\ConnectionEventArgs; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; /** * Session init listener for executing a single SQL statement right after a connection is opened. @@ -26,7 +26,7 @@ public function __construct($sql) /** * @return void * - * @throws DBALException + * @throws Exception */ public function postConnect(ConnectionEventArgs $args) { diff --git a/src/Exception.php b/src/Exception.php new file mode 100644 index 00000000000..34442da6a8a --- /dev/null +++ b/src/Exception.php @@ -0,0 +1,10 @@ +getDriver() instanceof Driver\PDO\SQLite\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/src/Internal/DependencyOrderCalculator.php b/src/Internal/DependencyOrderCalculator.php deleted file mode 100644 index 55b70c190ab..00000000000 --- a/src/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/src/Internal/DependencyOrderEdge.php b/src/Internal/DependencyOrderEdge.php deleted file mode 100644 index fa1a0453c46..00000000000 --- a/src/Internal/DependencyOrderEdge.php +++ /dev/null @@ -1,12 +0,0 @@ -getVarcharTypeDeclarationSQL($column); + } + /** * Returns the SQL snippet used to declare a VARCHAR column type. * @@ -284,11 +295,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.'); } /** @@ -299,11 +310,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.'); } /** @@ -339,7 +350,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) { @@ -348,7 +359,7 @@ public function registerDoctrineTypeMapping($dbType, $doctrineType) } if (! Types\Type::hasType($doctrineType)) { - throw DBALException::typeNotFound($doctrineType); + throw Exception::typeNotFound($doctrineType); } $dbType = strtolower($dbType); @@ -370,7 +381,7 @@ public function registerDoctrineTypeMapping($dbType, $doctrineType) * * @return string * - * @throws DBALException + * @throws Exception */ public function getDoctrineTypeMapping($dbType) { @@ -381,7 +392,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.' ); } @@ -580,11 +591,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__); } /** @@ -812,11 +823,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__); } /** @@ -983,11 +994,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__); } /** @@ -998,7 +1009,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) { @@ -1013,7 +1024,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) { @@ -1028,7 +1039,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) { @@ -1043,7 +1054,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) { @@ -1058,7 +1069,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) { @@ -1073,7 +1084,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) { @@ -1088,7 +1099,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) { @@ -1103,7 +1114,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) { @@ -1118,7 +1129,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) { @@ -1133,7 +1144,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) { @@ -1148,7 +1159,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) { @@ -1163,7 +1174,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) { @@ -1178,7 +1189,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) { @@ -1193,7 +1204,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) { @@ -1208,7 +1219,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) { @@ -1223,7 +1234,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) { @@ -1241,11 +1252,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__); } /** @@ -1473,7 +1484,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) @@ -1485,7 +1496,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); @@ -1624,12 +1635,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); @@ -1697,11 +1708,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__); } /** @@ -1709,11 +1720,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__); } /** @@ -1837,11 +1848,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__); } /** @@ -1906,11 +1917,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__); } /** @@ -2191,7 +2202,7 @@ public function getColumnDeclarationListSQL(array $columns) * * @return string DBMS specific SQL code portion that should be used to declare the column. * - * @throws DBALException + * @throws Exception */ public function getColumnDeclarationSQL($name, array $column) { @@ -2710,11 +2721,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__); } /** @@ -2722,11 +2733,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__); } /** @@ -2734,11 +2745,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__); } /** @@ -2746,11 +2757,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__); } /** @@ -2759,31 +2770,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__); } /** @@ -2793,11 +2804,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__); } /** @@ -2815,11 +2826,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__); } /** @@ -2827,11 +2838,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__); } /** @@ -2840,11 +2851,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__); } /** @@ -2852,11 +2863,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__); } /** @@ -2866,11 +2877,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__); } /** @@ -2878,11 +2889,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__); } /** @@ -2892,11 +2903,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__); } /** @@ -2906,11 +2917,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__); } /** @@ -2921,11 +2932,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__); } /** @@ -2948,11 +2959,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__); } /** @@ -2963,11 +2974,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__); } /** @@ -3041,11 +3052,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__); } /** @@ -3137,13 +3148,15 @@ public function supportsForeignKeyConstraints() } /** - * Whether foreign key constraints can be dropped. + * Whether this platform supports onUpdate in foreign key constraints. + * + * @deprecated * - * If false, then getDropForeignKeySQL() throws exception. + * @return bool */ - public function supportsCreateDropForeignKeyConstraints(): bool + public function supportsForeignKeyOnUpdate() { - return true; + return $this->supportsForeignKeyConstraints(); } /** @@ -3174,11 +3187,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__); } /** @@ -3316,7 +3329,7 @@ public function getTimeFormatString() * * @return string * - * @throws DBALException + * @throws Exception */ final public function modifyLimitQuery($query, $limit, $offset = null) { @@ -3327,14 +3340,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() )); @@ -3469,7 +3482,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() { @@ -3481,7 +3494,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. @@ -3495,11 +3508,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/src/Platforms/DB2Platform.php b/src/Platforms/DB2Platform.php index 006587eeb5e..f9e6eaa1c17 100644 --- a/src/Platforms/DB2Platform.php +++ b/src/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; @@ -480,7 +480,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/src/Platforms/MySqlPlatform.php b/src/Platforms/MySqlPlatform.php index e5ef413149e..af8e037d6d7 100644 --- a/src/Platforms/MySqlPlatform.php +++ b/src/Platforms/MySqlPlatform.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; @@ -698,7 +698,7 @@ protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) /** * @return string[] * - * @throws DBALException + * @throws Exception */ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $index) { @@ -739,7 +739,7 @@ private function getPreAlterTableAlterPrimaryKeySQL(TableDiff $diff, Index $inde * * @return string[] * - * @throws DBALException + * @throws Exception */ private function getPreAlterTableAlterIndexForeignKeySQL(TableDiff $diff) { diff --git a/src/Platforms/OraclePlatform.php b/src/Platforms/OraclePlatform.php index ab4f75a39ba..7618d3ca497 100644 --- a/src/Platforms/OraclePlatform.php +++ b/src/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) === 0) { - throw new DBALException('Invalid Oracle identifier'); + throw new Exception('Invalid Oracle identifier'); } } diff --git a/src/Platforms/SQLServer2012Platform.php b/src/Platforms/SQLServer2012Platform.php index efc7fdb7851..6689ff40b9b 100644 --- a/src/Platforms/SQLServer2012Platform.php +++ b/src/Platforms/SQLServer2012Platform.php @@ -616,7 +616,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'"; @@ -647,7 +647,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 @@ -826,7 +826,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) @@ -1235,6 +1235,20 @@ public function getDateTimeTzTypeDeclarationSQL(array $column) return 'DATETIMEOFFSET(6)'; } + /** + * {@inheritDoc} + */ + public function getAsciiStringTypeDeclarationSQL(array $column): string + { + $length = $column['length'] ?? null; + + if (! isset($column['fixed'])) { + return sprintf('VARCHAR(%d)', $length); + } + + return sprintf('CHAR(%d)', $length); + } + /** * {@inheritDoc} */ diff --git a/src/Platforms/SqlitePlatform.php b/src/Platforms/SqlitePlatform.php index 8b19ee92cde..098a8907970 100644 --- a/src/Platforms/SqlitePlatform.php +++ b/src/Platforms/SqlitePlatform.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Constraint; use Doctrine\DBAL\Schema\ForeignKeyConstraint; use Doctrine\DBAL\Schema\Identifier; @@ -696,7 +696,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' ); } @@ -719,7 +719,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' ); } @@ -790,11 +790,6 @@ public function canEmulateSchemas() * {@inheritDoc} */ public function supportsForeignKeyConstraints() - { - return true; - } - - public function supportsCreateDropForeignKeyConstraints(): bool { return false; } @@ -804,7 +799,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.'); } /** @@ -812,10 +807,7 @@ public function getCreatePrimaryKeySQL(Index $index, $table) */ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) { - throw new DBALException( - 'Sqlite platform does not support alter foreign key, ' - . 'the table must be fully recreated using getAlterTableSQL.' - ); + throw new Exception('Sqlite platform does not support alter foreign key.'); } /** @@ -823,10 +815,7 @@ public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) */ public function getDropForeignKeySQL($foreignKey, $table) { - throw new DBALException( - 'Sqlite platform does not support alter foreign key, ' - . 'the table must be fully recreated using getAlterTableSQL.' - ); + throw new Exception('Sqlite platform does not support alter foreign key.'); } /** @@ -834,7 +823,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.'); } /** @@ -874,7 +863,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' ); } @@ -1008,7 +997,7 @@ public function getAlterTableSQL(TableDiff $diff) /** * @return string[]|false * - * @throws DBALException + * @throws Exception */ private function getSimpleAlterTableSQL(TableDiff $diff) { diff --git a/src/Query/QueryBuilder.php b/src/Query/QueryBuilder.php index 922b219a4cd..3ec6d5557a6 100644 --- a/src/Query/QueryBuilder.php +++ b/src/Query/QueryBuilder.php @@ -3,8 +3,8 @@ namespace Doctrine\DBAL\Query; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\Result; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Query\Expression\CompositeExpression; use Doctrine\DBAL\Query\Expression\ExpressionBuilder; @@ -201,7 +201,7 @@ public function getState() * * @return Result|int * - * @throws DBALException + * @throws Exception */ public function execute() { diff --git a/src/Query/QueryException.php b/src/Query/QueryException.php index 76bb9ba7559..58e941e9843 100644 --- a/src/Query/QueryException.php +++ b/src/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/src/Result.php b/src/Result.php index df43cb70d5a..fca81846b58 100644 --- a/src/Result.php +++ b/src/Result.php @@ -29,7 +29,7 @@ public function __construct(DriverResult $result, Connection $connection) /** * {@inheritDoc} * - * @throws DBALException + * @throws Exception */ public function fetchNumeric() { @@ -43,7 +43,7 @@ public function fetchNumeric() /** * {@inheritDoc} * - * @throws DBALException + * @throws Exception */ public function fetchAssociative() { @@ -57,7 +57,7 @@ public function fetchAssociative() /** * {@inheritDoc} * - * @throws DBALException + * @throws Exception */ public function fetchOne() { @@ -71,7 +71,7 @@ public function fetchOne() /** * {@inheritDoc} * - * @throws DBALException + * @throws Exception */ public function fetchAllNumeric(): array { @@ -85,7 +85,7 @@ public function fetchAllNumeric(): array /** * {@inheritDoc} * - * @throws DBALException + * @throws Exception */ public function fetchAllAssociative(): array { @@ -99,7 +99,7 @@ public function fetchAllAssociative(): array /** * {@inheritDoc} * - * @throws DBALException + * @throws Exception */ public function fetchFirstColumn(): array { @@ -113,7 +113,7 @@ public function fetchFirstColumn(): array /** * @return Traversable> * - * @throws DBALException + * @throws Exception */ public function iterateNumeric(): Traversable { @@ -129,7 +129,7 @@ public function iterateNumeric(): Traversable /** * @return Traversable> * - * @throws DBALException + * @throws Exception */ public function iterateAssociative(): Traversable { @@ -145,7 +145,7 @@ public function iterateAssociative(): Traversable /** * @return Traversable * - * @throws DBALException + * @throws Exception */ public function iterateColumn(): Traversable { diff --git a/src/SQLParserUtilsException.php b/src/SQLParserUtilsException.php index 99cdb8d4a66..297b0761b8d 100644 --- a/src/SQLParserUtilsException.php +++ b/src/SQLParserUtilsException.php @@ -9,7 +9,7 @@ * * @psalm-immutable */ -class SQLParserUtilsException extends DBALException +class SQLParserUtilsException extends Exception { /** * @param string $paramName diff --git a/src/Schema/AbstractSchemaManager.php b/src/Schema/AbstractSchemaManager.php index 4e2bfe8cb1b..6b7d162e8d3 100644 --- a/src/Schema/AbstractSchemaManager.php +++ b/src/Schema/AbstractSchemaManager.php @@ -3,10 +3,10 @@ namespace Doctrine\DBAL\Schema; use Doctrine\DBAL\Connection; -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; @@ -93,7 +93,7 @@ public function tryMethod() * * @return string[] * - * @throws DBALException + * @throws Exception */ public function listDatabases() { @@ -109,7 +109,7 @@ public function listDatabases() * * @return string[] * - * @throws DBALException + * @throws Exception */ public function listNamespaceNames() { @@ -127,7 +127,7 @@ public function listNamespaceNames() * * @return Sequence[] * - * @throws DBALException + * @throws Exception */ public function listSequences($database = null) { @@ -157,7 +157,7 @@ public function listSequences($database = null) * * @return Column[] * - * @throws DBALException + * @throws Exception */ public function listTableColumns($table, $database = null) { @@ -181,7 +181,7 @@ public function listTableColumns($table, $database = null) * * @return Index[] * - * @throws DBALException + * @throws Exception */ public function listTableIndexes($table) { @@ -201,7 +201,7 @@ public function listTableIndexes($table) * * @return bool * - * @throws DBALException + * @throws Exception */ public function tablesExist($names) { @@ -215,7 +215,7 @@ public function tablesExist($names) * * @return string[] * - * @throws DBALException + * @throws Exception */ public function listTableNames() { @@ -250,7 +250,7 @@ protected function filterAssetNames($assetNames) * * @return Table[] * - * @throws DBALException + * @throws Exception */ public function listTables() { @@ -269,7 +269,7 @@ public function listTables() * * @return Table * - * @throws DBALException + * @throws Exception */ public function listTableDetails($name) { @@ -290,7 +290,7 @@ public function listTableDetails($name) * * @return View[] * - * @throws DBALException + * @throws Exception */ public function listViews() { @@ -309,7 +309,7 @@ public function listViews() * * @return ForeignKeyConstraint[] * - * @throws DBALException + * @throws Exception */ public function listTableForeignKeys($table, $database = null) { @@ -334,7 +334,7 @@ public function listTableForeignKeys($table, $database = null) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropDatabase($database) { @@ -348,7 +348,7 @@ public function dropDatabase($database) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropTable($name) { @@ -363,7 +363,7 @@ public function dropTable($name) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropIndex($index, $table) { @@ -381,7 +381,7 @@ public function dropIndex($index, $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropConstraint(Constraint $constraint, $table) { @@ -396,7 +396,7 @@ public function dropConstraint(Constraint $constraint, $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropForeignKey($foreignKey, $table) { @@ -410,7 +410,7 @@ public function dropForeignKey($foreignKey, $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropSequence($name) { @@ -424,7 +424,7 @@ public function dropSequence($name) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropView($name) { @@ -440,7 +440,7 @@ public function dropView($name) * * @return void * - * @throws DBALException + * @throws Exception */ public function createDatabase($database) { @@ -452,7 +452,7 @@ public function createDatabase($database) * * @return void * - * @throws DBALException + * @throws Exception */ public function createTable(Table $table) { @@ -467,7 +467,7 @@ public function createTable(Table $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function createSequence($sequence) { @@ -481,7 +481,7 @@ public function createSequence($sequence) * * @return void * - * @throws DBALException + * @throws Exception */ public function createConstraint(Constraint $constraint, $table) { @@ -495,7 +495,7 @@ public function createConstraint(Constraint $constraint, $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function createIndex(Index $index, $table) { @@ -510,7 +510,7 @@ public function createIndex(Index $index, $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) { @@ -522,7 +522,7 @@ public function createForeignKey(ForeignKeyConstraint $foreignKey, $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function createView(View $view) { @@ -541,7 +541,7 @@ public function createView(View $view) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropAndCreateConstraint(Constraint $constraint, $table) { @@ -556,7 +556,7 @@ public function dropAndCreateConstraint(Constraint $constraint, $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropAndCreateIndex(Index $index, $table) { @@ -573,7 +573,7 @@ public function dropAndCreateIndex(Index $index, $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table) { @@ -586,7 +586,7 @@ public function dropAndCreateForeignKey(ForeignKeyConstraint $foreignKey, $table * * @return void * - * @throws DBALException + * @throws Exception */ public function dropAndCreateSequence(Sequence $sequence) { @@ -599,7 +599,7 @@ public function dropAndCreateSequence(Sequence $sequence) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropAndCreateTable(Table $table) { @@ -614,7 +614,7 @@ public function dropAndCreateTable(Table $table) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropAndCreateDatabase($database) { @@ -627,7 +627,7 @@ public function dropAndCreateDatabase($database) * * @return void * - * @throws DBALException + * @throws Exception */ public function dropAndCreateView(View $view) { @@ -642,7 +642,7 @@ public function dropAndCreateView(View $view) * * @return void * - * @throws DBALException + * @throws Exception */ public function alterTable(TableDiff $tableDiff) { @@ -661,7 +661,7 @@ public function alterTable(TableDiff $tableDiff) * * @return void * - * @throws DBALException + * @throws Exception */ public function renameTable($name, $newName) { @@ -767,7 +767,7 @@ protected function _getPortableTriggerDefinition($trigger) * * @return Sequence[] * - * @throws DBALException + * @throws Exception */ protected function _getPortableSequencesList($sequences) { @@ -785,11 +785,11 @@ protected function _getPortableSequencesList($sequences) * * @return Sequence * - * @throws DBALException + * @throws Exception */ protected function _getPortableSequenceDefinition($sequence) { - throw DBALException::notSupported('Sequences'); + throw Exception::notSupported('Sequences'); } /** @@ -803,7 +803,7 @@ protected function _getPortableSequenceDefinition($sequence) * * @return Column[] * - * @throws DBALException + * @throws Exception */ protected function _getPortableTableColumnList($table, $database, $tableColumns) { @@ -844,7 +844,7 @@ protected function _getPortableTableColumnList($table, $database, $tableColumns) * * @return Column * - * @throws DBALException + * @throws Exception */ abstract protected function _getPortableTableColumnDefinition($tableColumn); @@ -856,7 +856,7 @@ abstract protected function _getPortableTableColumnDefinition($tableColumn); * * @return Index[] * - * @throws DBALException + * @throws Exception */ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null) { @@ -1041,7 +1041,7 @@ protected function _getPortableTableForeignKeyDefinition($tableForeignKey) * * @return void * - * @throws DBALException + * @throws Exception */ protected function _execSql($sql) { @@ -1055,7 +1055,7 @@ protected function _execSql($sql) * * @return Schema * - * @throws DBALException + * @throws Exception */ public function createSchema() { @@ -1081,7 +1081,7 @@ public function createSchema() * * @return SchemaConfig * - * @throws DBALException + * @throws Exception */ public function createSchemaConfig() { @@ -1119,7 +1119,7 @@ public function createSchemaConfig() * * @return string[] * - * @throws DBALException + * @throws Exception */ public function getSchemaSearchPaths() { diff --git a/src/Schema/DB2SchemaManager.php b/src/Schema/DB2SchemaManager.php index 4d28566c0f3..acb5da4d72a 100644 --- a/src/Schema/DB2SchemaManager.php +++ b/src/Schema/DB2SchemaManager.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\DB2Platform; use Doctrine\DBAL\Types\Type; @@ -39,7 +39,7 @@ public function listTableNames() /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ protected function _getPortableTableColumnDefinition($tableColumn) { diff --git a/src/Schema/OracleSchemaManager.php b/src/Schema/OracleSchemaManager.php index d1900595e95..757af8bb297 100644 --- a/src/Schema/OracleSchemaManager.php +++ b/src/Schema/OracleSchemaManager.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Types\Type; @@ -265,7 +265,7 @@ public function createDatabase($database) * * @return bool * - * @throws DBALException + * @throws Exception */ public function dropAutoincrement($table) { diff --git a/src/Schema/PostgreSqlSchemaManager.php b/src/Schema/PostgreSqlSchemaManager.php index 215974c1713..014434fcbed 100644 --- a/src/Schema/PostgreSqlSchemaManager.php +++ b/src/Schema/PostgreSqlSchemaManager.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Types\Type; use Doctrine\DBAL\Types\Types; @@ -40,7 +40,7 @@ class PostgreSqlSchemaManager extends AbstractSchemaManager * * @return string[] * - * @throws DBALException + * @throws Exception */ public function getSchemaNames() { diff --git a/src/Schema/SQLServerSchemaManager.php b/src/Schema/SQLServerSchemaManager.php index 1716f274cbe..a33bd45c0f5 100644 --- a/src/Schema/SQLServerSchemaManager.php +++ b/src/Schema/SQLServerSchemaManager.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Types\Type; use PDOException; @@ -229,7 +229,7 @@ public function listTableIndexes($table) } throw $e; - } catch (DBALException $e) { + } catch (Exception $e) { if (strpos($e->getMessage(), 'SQLSTATE [01000, 15472]') === 0) { return []; } @@ -273,11 +273,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]'; } @@ -285,7 +285,7 @@ private function getColumnConstraintSQL($table, $column) /** * @param string $name * - * @throws DBALException + * @throws Exception */ public function listTableDetails($name): Table { diff --git a/src/Schema/SchemaDiff.php b/src/Schema/SchemaDiff.php index fa643aec912..67fb9bb9daa 100644 --- a/src/Schema/SchemaDiff.php +++ b/src/Schema/SchemaDiff.php @@ -2,7 +2,6 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\Internal\DependencyOrderCalculator; use Doctrine\DBAL\Platforms\AbstractPlatform; use function array_merge; @@ -139,16 +138,13 @@ protected function _toSql(AbstractPlatform $platform, $saveMode = false) } $foreignKeySql = []; - $createFlags = AbstractPlatform::CREATE_INDEXES; - - if (! $platform->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/src/Schema/SchemaException.php b/src/Schema/SchemaException.php index 24f2a9f2dd4..d4e22380ef4 100644 --- a/src/Schema/SchemaException.php +++ b/src/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/src/Schema/SqliteSchemaManager.php b/src/Schema/SqliteSchemaManager.php index 772c5bb4eaa..857f90b051a 100644 --- a/src/Schema/SqliteSchemaManager.php +++ b/src/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; @@ -440,7 +440,7 @@ protected function _getPortableTableForeignKeysList($tableForeignKeys) * * @return TableDiff * - * @throws DBALException + * @throws Exception */ private function getTableDiffForAlterForeignKey($table) { @@ -448,7 +448,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) ); } @@ -509,7 +509,7 @@ private function parseColumnCommentFromSQL(string $column, string $sql): ?string } /** - * @throws DBALException + * @throws Exception */ private function getCreateTableSQL(string $table): string { diff --git a/src/Schema/Table.php b/src/Schema/Table.php index 09fa90b02c4..cbe9a253c3f 100644 --- a/src/Schema/Table.php +++ b/src/Schema/Table.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\Exception\InvalidTableName; use Doctrine\DBAL\Schema\Visitor\Visitor; use Doctrine\DBAL\Types\Type; @@ -58,6 +58,7 @@ class Table extends AbstractAsset * @param mixed[] $options * * @throws SchemaException + * @throws Exception */ public function __construct( string $name, @@ -790,14 +791,14 @@ public function getPrimaryKey() * * @return Column[] * - * @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 $this->filterColumns($primaryKey->getColumns()); diff --git a/src/Schema/Visitor/CreateSchemaSqlCollector.php b/src/Schema/Visitor/CreateSchemaSqlCollector.php index c3428ce58ac..b2fab3ae4af 100644 --- a/src/Schema/Visitor/CreateSchemaSqlCollector.php +++ b/src/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/src/Schema/Visitor/DropSchemaSqlCollector.php b/src/Schema/Visitor/DropSchemaSqlCollector.php index a2355ac7de3..9f778109bbe 100644 --- a/src/Schema/Visitor/DropSchemaSqlCollector.php +++ b/src/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/src/Statement.php b/src/Statement.php index 8fd97f21ba4..d7a541a8de3 100644 --- a/src/Statement.php +++ b/src/Statement.php @@ -64,7 +64,7 @@ class Statement * @param string $sql The SQL of the statement. * @param Connection $conn The connection on which the statement should be executed. * - * @throws DBALException + * @throws Exception */ public function __construct($sql, Connection $conn) { @@ -96,7 +96,7 @@ public function __construct($sql, Connection $conn) * * @return bool TRUE on success, FALSE on failure. * - * @throws DBALException + * @throws Exception */ public function bindValue($param, $value, $type = ParameterType::STRING) { @@ -138,7 +138,7 @@ public function bindValue($param, $value, $type = ParameterType::STRING) * * @return bool TRUE on success, FALSE on failure. * - * @throws DBALException + * @throws Exception */ public function bindParam($param, &$variable, $type = ParameterType::STRING, $length = null) { @@ -157,7 +157,7 @@ public function bindParam($param, &$variable, $type = ParameterType::STRING, $le * * @param mixed[]|null $params * - * @throws DBALException + * @throws Exception */ public function execute($params = null): Result { diff --git a/src/Tools/Console/Command/ReservedWordsCommand.php b/src/Tools/Console/Command/ReservedWordsCommand.php index 36abac2cea6..4f290a4b433 100644 --- a/src/Tools/Console/Command/ReservedWordsCommand.php +++ b/src/Tools/Console/Command/ReservedWordsCommand.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL\Tools\Console\Command; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\Keywords\DB2Keywords; use Doctrine\DBAL\Platforms\Keywords\MariaDb102Keywords; use Doctrine\DBAL\Platforms\Keywords\MySQL57Keywords; @@ -115,7 +115,7 @@ protected function configure() /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/src/Tools/Console/Command/RunSqlCommand.php b/src/Tools/Console/Command/RunSqlCommand.php index 6a3cbc02998..a4ba7d3bda4 100644 --- a/src/Tools/Console/Command/RunSqlCommand.php +++ b/src/Tools/Console/Command/RunSqlCommand.php @@ -3,7 +3,7 @@ namespace Doctrine\DBAL\Tools\Console\Command; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Tools\Console\ConnectionProvider; use Doctrine\DBAL\Tools\Dumper; use LogicException; @@ -59,7 +59,7 @@ protected function configure() /** * {@inheritdoc} * - * @throws DBALException + * @throws Exception */ protected function execute(InputInterface $input, OutputInterface $output) { diff --git a/src/Types/AsciiStringType.php b/src/Types/AsciiStringType.php new file mode 100644 index 00000000000..e7975748678 --- /dev/null +++ b/src/Types/AsciiStringType.php @@ -0,0 +1,32 @@ +getAsciiStringTypeDeclarationSQL($column); + } + + /** + * {@inheritdoc} + */ + public function getBindingType() + { + return ParameterType::ASCII; + } + + public function getName(): string + { + return Types::ASCII_STRING; + } +} diff --git a/src/Types/ConversionException.php b/src/Types/ConversionException.php index 55dfedee754..5be4743a5e5 100644 --- a/src/Types/ConversionException.php +++ b/src/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/src/Types/Type.php b/src/Types/Type.php index 48f95ac7b81..2395c12aa4b 100644 --- a/src/Types/Type.php +++ b/src/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; @@ -21,6 +21,7 @@ abstract class Type */ private const BUILTIN_TYPES_MAP = [ Types::ARRAY => ArrayType::class, + Types::ASCII_STRING => AsciiStringType::class, Types::BIGINT => BigIntType::class, Types::BINARY => BinaryType::class, Types::BLOB => BlobType::class, @@ -150,7 +151,7 @@ private static function createTypeRegistry(): TypeRegistry * * @return Type * - * @throws DBALException + * @throws Exception */ public static function getType($name) { @@ -165,7 +166,7 @@ public static function getType($name) * * @return void * - * @throws DBALException + * @throws Exception */ public static function addType($name, $className) { @@ -192,7 +193,7 @@ public static function hasType($name) * * @return void * - * @throws DBALException + * @throws Exception */ public static function overrideType($name, $className) { diff --git a/src/Types/TypeRegistry.php b/src/Types/TypeRegistry.php index 4c2e31ecbcf..fdae6d603c8 100644 --- a/src/Types/TypeRegistry.php +++ b/src/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/src/Types/Types.php b/src/Types/Types.php index 771a01780ba..56bf3f51cf0 100644 --- a/src/Types/Types.php +++ b/src/Types/Types.php @@ -10,6 +10,7 @@ final class Types { public const ARRAY = 'array'; + public const ASCII_STRING = 'ascii_string'; public const BIGINT = 'bigint'; public const BINARY = 'binary'; public const BLOB = 'blob'; diff --git a/src/VersionAwarePlatformDriver.php b/src/VersionAwarePlatformDriver.php index 3dc18a400d3..b3ec8b8432a 100644 --- a/src/VersionAwarePlatformDriver.php +++ b/src/VersionAwarePlatformDriver.php @@ -22,7 +22,7 @@ interface VersionAwarePlatformDriver extends Driver * * @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/ConnectionTest.php b/tests/ConnectionTest.php index db3772dce26..4802d3e1011 100644 --- a/tests/ConnectionTest.php +++ b/tests/ConnectionTest.php @@ -9,12 +9,12 @@ 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\DriverManager; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\InvalidArgumentException; use Doctrine\DBAL\Logging\DebugStack; use Doctrine\DBAL\ParameterType; @@ -158,7 +158,7 @@ public function testEventManagerPassedToPlatform(): void */ public function testDriverExceptionIsWrapped(callable $callback): 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); } @@ -715,8 +715,8 @@ public function testRethrowsOriginalExceptionOnDeterminingPlatformWhenConnecting $driverMock = $this->createMock(VersionAwarePlatformDriver::class); $connection = new Connection(['dbname' => 'foo'], $driverMock); - $originalException = new DBALException('Original exception'); - $fallbackException = new DBALException('Fallback exception'); + $originalException = new \Exception('Original exception'); + $fallbackException = new \Exception('Fallback exception'); $driverMock->method('connect') ->will(self::onConsecutiveCalls( diff --git a/tests/Driver/AbstractDriverTest.php b/tests/Driver/AbstractDriverTest.php index 6305e60747f..834e14a3f68 100644 --- a/tests/Driver/AbstractDriverTest.php +++ b/tests/Driver/AbstractDriverTest.php @@ -3,9 +3,9 @@ namespace Doctrine\DBAL\Tests\Driver; use Doctrine\DBAL\Connection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\API\ExceptionConverter; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\VersionAwarePlatformDriver; @@ -71,7 +71,7 @@ public function testThrowsExceptionOnCreatingDatabasePlatformsForInvalidVersion( self::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/DriverManagerTest.php b/tests/DriverManagerTest.php index 20759093a4a..bc0c66dea32 100644 --- a/tests/DriverManagerTest.php +++ b/tests/DriverManagerTest.php @@ -4,11 +4,11 @@ use Doctrine\DBAL\Connection; use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver; use Doctrine\DBAL\Driver\PDO; use Doctrine\DBAL\Driver\SQLSrv\Driver as SQLSrvDriver; use Doctrine\DBAL\DriverManager; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\AbstractPlatform; use PHPUnit\Framework\TestCase; use stdClass; @@ -21,14 +21,14 @@ class DriverManagerTest extends TestCase { 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']); } @@ -71,7 +71,7 @@ public function testCustomWrapper(): void */ public function testInvalidWrapperClass(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $options = [ 'url' => 'sqlite::memory:', @@ -83,7 +83,7 @@ public function testInvalidWrapperClass(): void public function testInvalidDriverClass(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $options = ['driverClass' => stdClass::class]; @@ -141,7 +141,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/Functional/ExceptionTest.php b/tests/Functional/ExceptionTest.php index b09148cd7cf..9a1a9aabfa4 100644 --- a/tests/Functional/ExceptionTest.php +++ b/tests/Functional/ExceptionTest.php @@ -85,8 +85,8 @@ public function testTableExistsException(): void public function testForeignKeyConstraintViolationExceptionOnInsert(): void { - if ($this->connection->getDatabasePlatform()->getName() === 'sqlite') { - $this->connection->executeStatement('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/Functional/ParameterTypes/AsciiTest.php b/tests/Functional/ParameterTypes/AsciiTest.php new file mode 100644 index 00000000000..70c56540173 --- /dev/null +++ b/tests/Functional/ParameterTypes/AsciiTest.php @@ -0,0 +1,26 @@ +connection->getDriver() instanceof AbstractSQLServerDriver) { + self::markTestSkipped('Driver does not support ascii string binding'); + } + + $statement = $this->connection->prepare('SELECT sql_variant_property(?, \'BaseType\')'); + + $statement->bindValue(1, 'test', ParameterType::ASCII); + $results = $statement->execute()->fetchOne(); + + self::assertEquals('varchar', $results); + } +} diff --git a/tests/Functional/Schema/ForeignKeyTest.php b/tests/Functional/Schema/ForeignKeyTest.php deleted file mode 100644 index c4e4695980e..00000000000 --- a/tests/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->executeStatement($sql); - } - - self::assertCount( - 1, - $this->connection->getSchemaManager()->listTableForeignKeys('referencing_table') - ); - } -} diff --git a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php index f4d79310e6a..78f394b35cf 100644 --- a/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php +++ b/tests/Functional/Schema/SchemaManagerFunctionalTestCase.php @@ -3,8 +3,8 @@ namespace Doctrine\DBAL\Tests\Functional\Schema; use Doctrine\Common\EventManager; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Events; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema\AbstractAsset; use Doctrine\DBAL\Schema\AbstractSchemaManager; use Doctrine\DBAL\Schema\Column; @@ -12,7 +12,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; @@ -39,7 +38,6 @@ use function current; use function end; use function explode; -use function implode; use function in_array; use function sprintf; use function str_replace; @@ -85,7 +83,7 @@ protected function tearDown(): void try { //sql server versions below 2016 do not support 'IF EXISTS' so we have to catch the exception here $this->connection->executeStatement('DROP SCHEMA testschema'); - } catch (DBALException $e) { + } catch (Exception $e) { return; } } @@ -1418,55 +1416,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->executeStatement($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/Functional/Schema/SqliteSchemaManagerTest.php b/tests/Functional/Schema/SqliteSchemaManagerTest.php index df6ef566712..ad1db2311d8 100644 --- a/tests/Functional/Schema/SqliteSchemaManagerTest.php +++ b/tests/Functional/Schema/SqliteSchemaManagerTest.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Tests\Functional\Schema; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Schema; use Doctrine\DBAL\Schema\Table; use Doctrine\DBAL\Types\BlobType; @@ -18,7 +18,7 @@ class SqliteSchemaManagerTest extends SchemaManagerFunctionalTestCase */ public function testListDatabases(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->schemaManager->listDatabases(); } diff --git a/tests/Functional/Ticket/DBAL630Test.php b/tests/Functional/Ticket/DBAL630Test.php index 9aabe8212e0..89ac298e2ef 100644 --- a/tests/Functional/Ticket/DBAL630Test.php +++ b/tests/Functional/Ticket/DBAL630Test.php @@ -2,8 +2,8 @@ namespace Doctrine\DBAL\Tests\Functional\Ticket; -use Doctrine\DBAL\DBALException; use Doctrine\DBAL\Driver\PDO\Connection; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Platforms\PostgreSQL94Platform; use Doctrine\DBAL\Tests\FunctionalTestCase; @@ -25,7 +25,7 @@ protected function setUp(): void try { $this->connection->executeStatement('CREATE TABLE dbal630 (id SERIAL, bool_col BOOLEAN NOT NULL);'); $this->connection->executeStatement('CREATE TABLE dbal630_allow_nulls (id SERIAL, bool_col BOOLEAN);'); - } catch (DBALException $e) { + } catch (Exception $e) { } $this->running = true; diff --git a/tests/Functional/Types/AsciiStringTest.php b/tests/Functional/Types/AsciiStringTest.php new file mode 100644 index 00000000000..832541c50b3 --- /dev/null +++ b/tests/Functional/Types/AsciiStringTest.php @@ -0,0 +1,70 @@ +addColumn('id', 'ascii_string', [ + 'length' => 3, + 'fixed' => true, + ]); + + $table->addColumn('val', 'ascii_string', ['length' => 4]); + $table->setPrimaryKey(['id']); + + $sm = $this->connection->getSchemaManager(); + $sm->dropAndCreateTable($table); + } + + public function testInsertAndSelect(): void + { + $id1 = 'id1'; + $id2 = 'id2'; + + $value1 = 'val1'; + $value2 = 'val2'; + + $this->insert($id1, $value1); + $this->insert($id2, $value2); + + self::assertSame($value1, $this->select($id1)); + self::assertSame($value2, $this->select($id2)); + } + + private function insert(string $id, string $value): void + { + $result = $this->connection->insert('ascii_table', [ + 'id' => $id, + 'val' => $value, + ], [ + ParameterType::ASCII, + ParameterType::ASCII, + ]); + + self::assertSame(1, $result); + } + + private function select(string $id): string + { + $value = $this->connection->fetchOne( + 'SELECT val FROM ascii_table WHERE id = ?', + [$id], + [ParameterType::ASCII] + ); + + self::assertIsString($value); + + return $value; + } +} diff --git a/tests/Internal/DependencyOrderCalculatorTest.php b/tests/Internal/DependencyOrderCalculatorTest.php deleted file mode 100644 index 61d5b8a92e2..00000000000 --- a/tests/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/Platforms/AbstractPlatformTestCase.php b/tests/Platforms/AbstractPlatformTestCase.php index d2a63b83a92..a75f2e8bcf4 100644 --- a/tests/Platforms/AbstractPlatformTestCase.php +++ b/tests/Platforms/AbstractPlatformTestCase.php @@ -3,8 +3,8 @@ namespace Doctrine\DBAL\Tests\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'); } @@ -147,7 +147,7 @@ public function testCreateWithNoColumns(): void { $table = new Table('test'); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $sql = $this->platform->getCreateTableSQL($table); } @@ -242,10 +242,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); @@ -259,6 +255,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(Exception::class); + $this->platform->getCreateForeignKeySQL($fk, 'test'); + } + } + protected function getBitAndComparisonExpressionSql(string $value1, string $value2): string { return '(' . $value1 . ' & ' . $value2 . ')'; @@ -722,7 +730,7 @@ public function testQuotesReservedKeywordInIndexDeclarationSQL(): void $index = new Index('select', ['foo']); if (! $this->supportsInlineIndexDeclaration()) { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); } self::assertSame( @@ -750,7 +758,7 @@ protected function supportsCommentOnStatement(): bool public function testGetCreateSchemaSQL(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getCreateSchemaSQL('schema'); } @@ -784,7 +792,7 @@ public function testUsesSequenceEmulatedIdentityColumns(): void */ public function testReturnsIdentitySequenceName(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getIdentitySequenceName('mytable', 'mycolumn'); } @@ -811,7 +819,7 @@ protected function getBinaryMaxLength(): int public function testReturnsBinaryTypeDeclarationSQL(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getBinaryTypeDeclarationSQL([]); } @@ -1053,9 +1061,9 @@ protected function getQuotedAlterTableRenameIndexInSchemaSQL(): array public function testQuotesDropForeignKeySQL(): void { - if (! $this->platform->supportsCreateDropForeignKeyConstraints()) { - self::markTestSkipped( - sprintf('%s does not support modifying foreign key constraints.', get_class($this->platform)) + if (! $this->platform->supportsForeignKeyConstraints()) { + $this->markTestSkipped( + sprintf('%s does not support foreign key constraints.', get_class($this->platform)) ); } @@ -1219,7 +1227,7 @@ public function testThrowsExceptionOnGeneratingInlineColumnCommentSQLIfUnsupport self::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." ); @@ -1248,7 +1256,7 @@ public function testQuoteStringLiteral(): void public function testReturnsGuidTypeDeclarationSQL(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getGuidTypeDeclarationSQL([]); } @@ -1444,6 +1452,28 @@ public function testZeroOffsetWithoutLimitIsIgnored(): void $this->platform->modifyLimitQuery($query, null, 0) ); } + + /** + * @param array $column + * + * @dataProvider asciiStringSqlDeclarationDataProvider + */ + public function testAsciiSQLDeclaration(string $expectedSql, array $column): void + { + $declarationSql = $this->platform->getAsciiStringTypeDeclarationSQL($column); + self::assertEquals($expectedSql, $declarationSql); + } + + /** + * @return array}> + */ + public function asciiStringSqlDeclarationDataProvider(): array + { + return [ + ['VARCHAR(12)', ['length' => 12]], + ['CHAR(12)', ['length' => 12, 'fixed' => true]], + ]; + } } interface GetCreateTableSqlDispatchEventListener diff --git a/tests/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Platforms/AbstractSQLServerPlatformTestCase.php index 46c6b375263..83ccab1d1b7 100644 --- a/tests/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Platforms/AbstractSQLServerPlatformTestCase.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Tests\Platforms; -use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Platforms\SQLServer2012Platform; use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\ColumnDiff; @@ -47,7 +47,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'';' " . @@ -60,7 +60,7 @@ public function getGenerateAlterTableSql(): array public function testDoesNotSupportRegexp(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $this->platform->getRegexpExpression(); } @@ -488,9 +488,6 @@ public function testModifyLimitQueryWithAggregateFunctionInOrderByClause(): void ); } - /** - * @throws DBALException - */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBaseTable(): void { $querySql = 'SELECT DISTINCT id_0, name_1 ' @@ -511,9 +508,6 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromBas self::assertEquals($alteredSql, $sql); } - /** - * @throws DBALException - */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoinTable(): void { $querySql = 'SELECT DISTINCT id_0, name_1 ' @@ -534,9 +528,6 @@ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnFromJoi self::assertEquals($alteredSql, $sql); } - /** - * @throws DBALException - */ public function testModifyLimitSubqueryWithJoinAndSubqueryOrderedByColumnsFromBothTables(): void { $querySql = 'SELECT DISTINCT id_0, name_1, foo_2 ' @@ -1005,7 +996,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', @@ -1185,7 +1176,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'"]; } /** @@ -1194,8 +1185,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'", ]; } @@ -1244,15 +1235,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'", ]; } @@ -1269,7 +1260,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'"]; } /** @@ -1278,8 +1269,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'", ]; } @@ -1528,7 +1519,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', ]; @@ -1542,11 +1533,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'';' " . @@ -1612,7 +1603,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 diff --git a/tests/Platforms/OraclePlatformTest.php b/tests/Platforms/OraclePlatformTest.php index d92478d5ee7..75b14a21b78 100644 --- a/tests/Platforms/OraclePlatformTest.php +++ b/tests/Platforms/OraclePlatformTest.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Tests\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')); } @@ -976,4 +976,15 @@ public function testQuotesDatabaseNameInListTableColumnsSQL(): void $this->platform->getListTableColumnsSQL('foo_table', "Foo'Bar\\") ); } + + /** + * @return array}> + */ + public function asciiStringSqlDeclarationDataProvider(): array + { + return [ + ['VARCHAR2(12)', ['length' => 12]], + ['CHAR(12)', ['length' => 12, 'fixed' => true]], + ]; + } } diff --git a/tests/Platforms/SqlitePlatformTest.php b/tests/Platforms/SqlitePlatformTest.php index 793fa5f312b..9aedc302c05 100644 --- a/tests/Platforms/SqlitePlatformTest.php +++ b/tests/Platforms/SqlitePlatformTest.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Tests\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/Schema/SchemaDiffTest.php b/tests/Schema/SchemaDiffTest.php index 929c025af6c..5126d265d8c 100644 --- a/tests/Schema/SchemaDiffTest.php +++ b/tests/Schema/SchemaDiffTest.php @@ -54,11 +54,7 @@ private function createPlatform(bool $unsafe) $platform->expects(self::exactly(1)) ->method('getCreateSchemaSQL') ->with('foo_ns') - ->will(self::returnValue('create_schema')); - - $platform->method('supportsCreateDropForeignKeyConstraints') - ->will(self::returnValue(true)); - + ->will($this->returnValue('create_schema')); if ($unsafe) { $platform->expects(self::exactly(1)) ->method('getDropSequenceSql') @@ -108,8 +104,8 @@ private function createPlatform(bool $unsafe) ->will(self::returnValue(true)); $platform->expects(self::exactly(1)) ->method('supportsSequences') - ->will(self::returnValue(true)); - $platform->expects(self::any()) + ->will($this->returnValue(true)); + $platform->expects($this->exactly(2)) ->method('supportsForeignKeyConstraints') ->will(self::returnValue(true)); diff --git a/tests/Schema/TableTest.php b/tests/Schema/TableTest.php index 0e5b3fd6b14..51d2a14f4fe 100644 --- a/tests/Schema/TableTest.php +++ b/tests/Schema/TableTest.php @@ -2,7 +2,7 @@ namespace Doctrine\DBAL\Tests\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 TestCase { public function testCreateWithInvalidTableName(): void { - $this->expectException(DBALException::class); + $this->expectException(Exception::class); new Table(''); } diff --git a/tests/Schema/Visitor/CreateSchemaSqlCollectorTest.php b/tests/Schema/Visitor/CreateSchemaSqlCollectorTest.php index d7e9f2afcbc..a8e7708fb9b 100644 --- a/tests/Schema/Visitor/CreateSchemaSqlCollectorTest.php +++ b/tests/Schema/Visitor/CreateSchemaSqlCollectorTest.php @@ -29,7 +29,7 @@ protected function setUp(): void 'getCreateSchemaSQL', 'getCreateSequenceSQL', 'getCreateTableSQL', - 'supportsCreateDropForeignKeyConstraints', + 'supportsForeignKeyConstraints', 'supportsSchemas', ] ) @@ -74,9 +74,9 @@ public function testAcceptsTable(): void self::assertSame(['foo'], $this->visitor->getQueries()); } - public function testAcceptsForeignKeyDoesNotSupportCreateDropForeignKeyConstraints(): void + public function testAcceptsForeignKeyDoesNotSupportForeignKeyConstraints(): void { - $this->platformMock->method('supportsCreateDropForeignKeyConstraints') + $this->platformMock->method('supportsForeignKeyConstraints') ->willReturn(false); $table = $this->createTableMock(); @@ -87,9 +87,9 @@ public function testAcceptsForeignKeyDoesNotSupportCreateDropForeignKeyConstrain self::assertEmpty($this->visitor->getQueries()); } - public function testAcceptsForeignKeySupportsCreateDropForeignKeyConstraints(): void + public function testAcceptsForeignKeySupportsForeignKeyConstraints(): void { - $this->platformMock->method('supportsCreateDropForeignKeyConstraints') + $this->platformMock->method('supportsForeignKeyConstraints') ->willReturn(true); $table = $this->createTableMock(); @@ -111,8 +111,8 @@ public function testAcceptsSequences(): void public function testResetsQueries(): void { - foreach (['supportsSchemas', 'supportsCreateDropForeignKeyConstraints'] as $method) { - $this->platformMock->expects(self::any()) + foreach (['supportsSchemas', 'supportsForeignKeyConstraints'] as $method) { + $this->platformMock->expects($this->any()) ->method($method) ->will(self::returnValue(true)); } diff --git a/tests/StatementTest.php b/tests/StatementTest.php index da2579ba8b3..b3537faee9a 100644 --- a/tests/StatementTest.php +++ b/tests/StatementTest.php @@ -4,11 +4,11 @@ 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\Driver\Exception as DriverException; use Doctrine\DBAL\Driver\Statement as DriverStatement; +use Doctrine\DBAL\Exception; use Doctrine\DBAL\Logging\SQLLogger; use Doctrine\DBAL\ParameterType; use Doctrine\DBAL\Statement; @@ -141,7 +141,7 @@ public function testExecuteCallsLoggerStopQueryOnException(): void $statement = new Statement('', $this->conn); - $this->expectException(DBALException::class); + $this->expectException(Exception::class); $statement->execute(); } diff --git a/tests/Types/AsciiStringTest.php b/tests/Types/AsciiStringTest.php new file mode 100644 index 00000000000..7cc48c083c6 --- /dev/null +++ b/tests/Types/AsciiStringTest.php @@ -0,0 +1,43 @@ +type = new AsciiStringType(); + } + + public function testReturnCorrectBindingType(): void + { + self::assertEquals($this->type->getBindingType(), ParameterType::ASCII); + } + + public function testDelegateToPlatformForSqlDeclaration(): void + { + $columnDefinitions = [ + [['length' => 12, 'fixed' => true]], + [['length' => 14]], + ]; + + foreach ($columnDefinitions as $column) { + $platform = $this->createMock(AbstractPlatform::class); + $platform->expects(self::once()) + ->method('getAsciiStringTypeDeclarationSQL') + ->with($column); + + $this->type->getSQLDeclaration($column, $platform); + } + } +} diff --git a/tests/Types/TypeRegistryTest.php b/tests/Types/TypeRegistryTest.php index 0790c7520ca..fa6f26e4da7 100644 --- a/tests/Types/TypeRegistryTest.php +++ b/tests/Types/TypeRegistryTest.php @@ -4,7 +4,7 @@ namespace Doctrine\DBAL\Tests\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()); }