Subversion-Projekte lars-tiefland.laravel_shop

Revision

Details | Letzte Änderung | Log anzeigen | RSS feed

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