vendor/doctrine/dbal/src/Driver/API/SQLSrv/ExceptionConverter.php line 29

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace Doctrine\DBAL\Driver\API\SQLSrv;
  4. use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
  5. use Doctrine\DBAL\Driver\Exception;
  6. use Doctrine\DBAL\Exception\ConnectionException;
  7. use Doctrine\DBAL\Exception\DatabaseObjectNotFoundException;
  8. use Doctrine\DBAL\Exception\DriverException;
  9. use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
  10. use Doctrine\DBAL\Exception\InvalidFieldNameException;
  11. use Doctrine\DBAL\Exception\NonUniqueFieldNameException;
  12. use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
  13. use Doctrine\DBAL\Exception\SyntaxErrorException;
  14. use Doctrine\DBAL\Exception\TableExistsException;
  15. use Doctrine\DBAL\Exception\TableNotFoundException;
  16. use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
  17. use Doctrine\DBAL\Query;
  18. /**
  19.  * @internal
  20.  *
  21.  * @link https://docs.microsoft.com/en-us/sql/relational-databases/errors-events/database-engine-events-and-errors
  22.  */
  23. final class ExceptionConverter implements ExceptionConverterInterface
  24. {
  25.     public function convert(Exception $exception, ?Query $query): DriverException
  26.     {
  27.         switch ($exception->getCode()) {
  28.             case 102:
  29.                 return new SyntaxErrorException($exception$query);
  30.             case 207:
  31.                 return new InvalidFieldNameException($exception$query);
  32.             case 208:
  33.                 return new TableNotFoundException($exception$query);
  34.             case 209:
  35.                 return new NonUniqueFieldNameException($exception$query);
  36.             case 515:
  37.                 return new NotNullConstraintViolationException($exception$query);
  38.             case 547:
  39.             case 4712:
  40.                 return new ForeignKeyConstraintViolationException($exception$query);
  41.             case 2601:
  42.             case 2627:
  43.                 return new UniqueConstraintViolationException($exception$query);
  44.             case 2714:
  45.                 return new TableExistsException($exception$query);
  46.             case 3701:
  47.             case 15151:
  48.                 return new DatabaseObjectNotFoundException($exception$query);
  49.             case 11001:
  50.             case 18456:
  51.                 return new ConnectionException($exception$query);
  52.         }
  53.         return new DriverException($exception$query);
  54.     }
  55. }