diff options
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/PgSQL/Exception.php')
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/PgSQL/Exception.php | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/PgSQL/Exception.php b/vendor/doctrine/dbal/src/Driver/PgSQL/Exception.php new file mode 100644 index 0000000..3036e55 --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/PgSQL/Exception.php | |||
@@ -0,0 +1,31 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\PgSQL; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\AbstractException; | ||
8 | use PgSql\Result as PgSqlResult; | ||
9 | |||
10 | use function pg_result_error_field; | ||
11 | |||
12 | use const PGSQL_DIAG_MESSAGE_PRIMARY; | ||
13 | use const PGSQL_DIAG_SQLSTATE; | ||
14 | |||
15 | /** | ||
16 | * @internal | ||
17 | * | ||
18 | * @psalm-immutable | ||
19 | */ | ||
20 | final class Exception extends AbstractException | ||
21 | { | ||
22 | public static function fromResult(PgSqlResult $result): self | ||
23 | { | ||
24 | $sqlstate = pg_result_error_field($result, PGSQL_DIAG_SQLSTATE); | ||
25 | if ($sqlstate === false) { | ||
26 | $sqlstate = null; | ||
27 | } | ||
28 | |||
29 | return new self((string) pg_result_error_field($result, PGSQL_DIAG_MESSAGE_PRIMARY), $sqlstate); | ||
30 | } | ||
31 | } | ||