Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5890 from maxm86545/pdoexception
PDOException&DriverException
- Loading branch information
Showing
3 changed files
with
52 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Doctrine\DBAL\Driver\PDO; | ||
|
||
use Doctrine\DBAL\Driver\Exception as DriverException; | ||
|
||
/** | ||
* @internal | ||
* | ||
* @psalm-immutable | ||
*/ | ||
final class PDOException extends \PDOException implements DriverException | ||
{ | ||
private ?string $sqlState = null; | ||
|
||
public static function new(\PDOException $previous): self | ||
{ | ||
$exception = new self($previous->message, 0, $previous); | ||
|
||
$exception->errorInfo = $previous->errorInfo; | ||
$exception->code = $previous->code; | ||
$exception->sqlState = $previous->errorInfo[0] ?? null; | ||
|
||
return $exception; | ||
} | ||
|
||
public function getSQLState(): ?string | ||
{ | ||
return $this->sqlState; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters