diff options
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 | } | ||
