summaryrefslogtreecommitdiff
path: root/vendor/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php')
-rw-r--r--vendor/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php85
1 files changed, 85 insertions, 0 deletions
diff --git a/vendor/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php b/vendor/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php
new file mode 100644
index 0000000..5885195
--- /dev/null
+++ b/vendor/doctrine/dbal/src/Driver/API/SQLite/ExceptionConverter.php
@@ -0,0 +1,85 @@
1<?php
2
3declare(strict_types=1);
4
5namespace Doctrine\DBAL\Driver\API\SQLite;
6
7use Doctrine\DBAL\Driver\API\ExceptionConverter as ExceptionConverterInterface;
8use Doctrine\DBAL\Driver\Exception;
9use Doctrine\DBAL\Exception\ConnectionException;
10use Doctrine\DBAL\Exception\DriverException;
11use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException;
12use Doctrine\DBAL\Exception\InvalidFieldNameException;
13use Doctrine\DBAL\Exception\LockWaitTimeoutException;
14use Doctrine\DBAL\Exception\NonUniqueFieldNameException;
15use Doctrine\DBAL\Exception\NotNullConstraintViolationException;
16use Doctrine\DBAL\Exception\ReadOnlyException;
17use Doctrine\DBAL\Exception\SyntaxErrorException;
18use Doctrine\DBAL\Exception\TableExistsException;
19use Doctrine\DBAL\Exception\TableNotFoundException;
20use Doctrine\DBAL\Exception\UniqueConstraintViolationException;
21use Doctrine\DBAL\Query;
22
23use function str_contains;
24
25/** @internal */
26final class ExceptionConverter implements ExceptionConverterInterface
27{
28 /** @link http://www.sqlite.org/c3ref/c_abort.html */
29 public function convert(Exception $exception, ?Query $query): DriverException
30 {
31 if (str_contains($exception->getMessage(), 'database is locked')) {
32 return new LockWaitTimeoutException($exception, $query);
33 }
34
35 if (
36 str_contains($exception->getMessage(), 'must be unique') ||
37 str_contains($exception->getMessage(), 'is not unique') ||
38 str_contains($exception->getMessage(), 'are not unique') ||
39 str_contains($exception->getMessage(), 'UNIQUE constraint failed')
40 ) {
41 return new UniqueConstraintViolationException($exception, $query);
42 }
43
44 if (
45 str_contains($exception->getMessage(), 'may not be NULL') ||
46 str_contains($exception->getMessage(), 'NOT NULL constraint failed')
47 ) {
48 return new NotNullConstraintViolationException($exception, $query);
49 }
50
51 if (str_contains($exception->getMessage(), 'no such table:')) {
52 return new TableNotFoundException($exception, $query);
53 }
54
55 if (str_contains($exception->getMessage(), 'already exists')) {
56 return new TableExistsException($exception, $query);
57 }
58
59 if (str_contains($exception->getMessage(), 'has no column named')) {
60 return new InvalidFieldNameException($exception, $query);
61 }
62
63 if (str_contains($exception->getMessage(), 'ambiguous column name')) {
64 return new NonUniqueFieldNameException($exception, $query);
65 }
66
67 if (str_contains($exception->getMessage(), 'syntax error')) {
68 return new SyntaxErrorException($exception, $query);
69 }
70
71 if (str_contains($exception->getMessage(), 'attempt to write a readonly database')) {
72 return new ReadOnlyException($exception, $query);
73 }
74
75 if (str_contains($exception->getMessage(), 'unable to open database file')) {
76 return new ConnectionException($exception, $query);
77 }
78
79 if (str_contains($exception->getMessage(), 'FOREIGN KEY constraint failed')) {
80 return new ForeignKeyConstraintViolationException($exception, $query);
81 }
82
83 return new DriverException($exception, $query);
84 }
85}