diff options
author | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
---|---|---|
committer | polo <ordipolo@gmx.fr> | 2024-08-13 23:45:21 +0200 |
commit | bf6655a534a6775d30cafa67bd801276bda1d98d (patch) | |
tree | c6381e3f6c81c33eab72508f410b165ba05f7e9c /vendor/doctrine/dbal/src/Driver/SQLSrv/Exception | |
parent | 94d67a4b51f8e62e7d518cce26a526ae1ec48278 (diff) | |
download | AppliGestionPHP-bf6655a534a6775d30cafa67bd801276bda1d98d.zip |
VERSION 0.2 doctrine ORM et entités
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/SQLSrv/Exception')
-rw-r--r-- | vendor/doctrine/dbal/src/Driver/SQLSrv/Exception/Error.php | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/SQLSrv/Exception/Error.php b/vendor/doctrine/dbal/src/Driver/SQLSrv/Exception/Error.php new file mode 100644 index 0000000..f39d5fc --- /dev/null +++ b/vendor/doctrine/dbal/src/Driver/SQLSrv/Exception/Error.php | |||
@@ -0,0 +1,44 @@ | |||
1 | <?php | ||
2 | |||
3 | declare(strict_types=1); | ||
4 | |||
5 | namespace Doctrine\DBAL\Driver\SQLSrv\Exception; | ||
6 | |||
7 | use Doctrine\DBAL\Driver\AbstractException; | ||
8 | |||
9 | use function rtrim; | ||
10 | use function sqlsrv_errors; | ||
11 | |||
12 | use const SQLSRV_ERR_ERRORS; | ||
13 | |||
14 | /** | ||
15 | * @internal | ||
16 | * | ||
17 | * @psalm-immutable | ||
18 | */ | ||
19 | final class Error extends AbstractException | ||
20 | { | ||
21 | public static function new(): self | ||
22 | { | ||
23 | $message = ''; | ||
24 | $sqlState = null; | ||
25 | $code = 0; | ||
26 | |||
27 | foreach ((array) sqlsrv_errors(SQLSRV_ERR_ERRORS) as $error) { | ||
28 | $message .= 'SQLSTATE [' . $error['SQLSTATE'] . ', ' . $error['code'] . ']: ' . $error['message'] . "\n"; | ||
29 | $sqlState ??= $error['SQLSTATE']; | ||
30 | |||
31 | if ($code !== 0) { | ||
32 | continue; | ||
33 | } | ||
34 | |||
35 | $code = $error['code']; | ||
36 | } | ||
37 | |||
38 | if ($message === '') { | ||
39 | $message = 'SQL Server error occurred but no error message was retrieved from driver.'; | ||
40 | } | ||
41 | |||
42 | return new self(rtrim($message), $sqlState, $code); | ||
43 | } | ||
44 | } | ||