-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
DBAL-990 Attempt platform detection even when the database name is not set #2671
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -425,9 +425,51 @@ private function getDatabasePlatformVersion() | |
|
||
// If not connected, we need to connect now to determine the platform version. | ||
if (null === $this->_conn) { | ||
$this->connect(); | ||
try { | ||
$this->connect(); | ||
} catch (\Exception $originalException) { | ||
if (empty($this->_params['dbname'])) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No I can't because it is possible to instantiate a connection object without this parameter. I even fell into this trap during writing the tests. |
||
throw $originalException; | ||
} | ||
|
||
// The database to connect to might not yet exist. | ||
// Retry detection without database name connection parameter. | ||
$databaseName = $this->_params['dbname']; | ||
$this->_params['dbname'] = null; | ||
|
||
try { | ||
$this->connect(); | ||
} 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. | ||
$this->_params['dbname'] = $databaseName; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this and the identical line below be put into a There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mattjanssen I thought about that but as we need to backport this to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. On this note, the merged fixes don't appear to have made it back to the 2.5 branch. https://github.com/doctrine/dbal/blob/2.5/lib/Doctrine/DBAL/Connection.php#L405-L441 |
||
|
||
throw $originalException; | ||
} | ||
|
||
// Reset connection parameters. | ||
$this->_params['dbname'] = $databaseName; | ||
$serverVersion = $this->getServerVersion(); | ||
|
||
// Close "temporary" connection to allow connecting to the real database again. | ||
$this->close(); | ||
|
||
return $serverVersion; | ||
} | ||
|
||
} | ||
|
||
return $this->getServerVersion(); | ||
} | ||
|
||
/** | ||
* Returns the database server version if the underlying driver supports it. | ||
* | ||
* @return string|null | ||
*/ | ||
private function getServerVersion() | ||
{ | ||
8000 | // Automatic platform version detection. | |
if ($this->_conn instanceof ServerInfoAwareConnection && | ||
! $this->_conn->requiresQueryForServerVersion() | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a more specific exception that we can catch here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Ocramius I do not know what else we could catch here as the driver interface does not specify what to throw in case
$driver->connect()
fails. Any ideas welcome, though.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a good-enough explanation for me