Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 9 additions & 3 deletions lib/Doctrine/DBAL/Driver/AbstractPostgreSQLDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ abstract class AbstractPostgreSQLDriver implements Driver, ExceptionConverterDri
*/
public function convertException($message, DriverException $exception)
{
switch ($exception->getSQLState()) {
$sqlState = $exception->getSQLState();

switch ($sqlState) {
Comment on lines +34 to +36
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like this was not an essential part of the fix. $sqlState is only used by the switch statement anyway. But creating a local variable will do no harm.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@phil-davis, you're right. It was introduced in the original version of this PR (5a7479c) which then had to be reworked. This chunk could have been reverted if noticed earlier.

case '40001':
case '40P01':
return new Exception\DeadlockException($message, $exception);
Expand Down Expand Up @@ -69,9 +71,13 @@ public function convertException($message, DriverException $exception)
case '42P07':
return new Exception\TableExistsException($message, $exception);

case '08006':
return new Exception\ConnectionException($message, $exception);

case '7':
// In some case (mainly connection errors) the PDO exception does not provide a SQLSTATE via its code.
// The exception code is always set to 7 here.
// Prior to fixing https://bugs.php.net/bug.php?id=64705 (PHP 7.3.22 and PHP 7.4.10),
// in some cases (mainly connection errors) the PDO exception wouldn't provide a SQLSTATE via its code.
// The exception code would be always set to 7 here.
// We have to match against the SQLSTATE in the error message in these cases.
if (strpos($exception->getMessage(), 'SQLSTATE[08006]') !== false) {
return new Exception\ConnectionException($message, $exception);
Expand Down