summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Driver/PgSQL/Exception.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/PgSQL/Exception.php')
-rw-r--r--vendor/doctrine/dbal/src/Driver/PgSQL/Exception.php31
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
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Driver\PgSQL;
6
7use Doctrine\DBAL\Driver\AbstractException;
8use PgSql\Result as PgSqlResult;
9
10use function pg_result_error_field;
11
12use const PGSQL_DIAG_MESSAGE_PRIMARY;
13use const PGSQL_DIAG_SQLSTATE;
14
15/**
16 * @internal
17 *
18 * @psalm-immutable
19 */
20final 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}