Skip to content

Commit

Permalink
Merge pull request #5709 from morozov/remove-platform-detection-fallback
Browse files Browse the repository at this point in the history
Remove platform detection fallback
  • Loading branch information
morozov authored Oct 2, 2022
2 parents 2cee457 + e04c9c2 commit 1a9de6b
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 45 deletions.
5 changes: 5 additions & 0 deletions UPGRADE.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,11 @@ awareness about deprecated code.

# Upgrade to 4.0

## BC BREAK: removed fallback connection used to determine the database platform.

When determining the database platform, if an attempt to connect using the provided configuration fails,
the wrapper connection will no longer fall back to a configuration without the database name.

## BC BREAK: removed support for driver name aliases.

Driver name aliases are no longer supported.
Expand Down
46 changes: 1 addition & 45 deletions src/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -259,57 +259,13 @@ protected function connect(): DriverConnection
*/
public function getServerVersion(): string
{
$connection = $this->getServerVersionConnection();

try {
return $connection->getServerVersion();
return $this->connect()->getServerVersion();
} catch (Driver\Exception $e) {
throw $this->convertException($e);
}
}

/**
* Returns the driver-level connection for server version detection.
*
* @throws Exception
*/
private function getServerVersionConnection(): DriverConnection
{
try {
return $this->connect();
} catch (Exception $e) {
if (! isset($this->params['dbname'])) {
throw $e;
}

Deprecation::trigger(
'doctrine/dbal',
'https://github.com/doctrine/dbal/pull/5707',
'Relying on a fallback connection used to determine the database platform while connecting'
. ' to a non-existing database is deprecated. Either use an existing database name in'
. ' connection parameters or omit the database name if the platform'
. ' and the server configuration allow that.',
);

// The database to connect to might not yet exist.
// Retry detection without database name connection parameter.
$params = $this->params;

unset($this->params['dbname']);

try {
return $this->connect();
} catch (Exception) {
// Either the platform does not support database-less connections
// or something else went wrong.
throw $e;
} finally {
$this->close();
$this->params = $params;
}
}
}

/**
* Returns the current auto-commit mode for this connection.
*
Expand Down

0 comments on commit 1a9de6b

Please sign in to comment.