|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* |
|
6
|
|
|
* @copyright 2021 Christoph Wurst <[email protected]> |
|
7
|
|
|
* |
|
8
|
|
|
* @author 2021 Christoph Wurst <[email protected]> |
|
9
|
|
|
* |
|
10
|
|
|
* @license GNU AGPL version 3 or any later version |
|
11
|
|
|
* |
|
12
|
|
|
* This program is free software: you can redistribute it and/or modify |
|
13
|
|
|
* it under the terms of the GNU Affero General Public License as |
|
14
|
|
|
* published by the Free Software Foundation, either version 3 of the |
|
15
|
|
|
* License, or (at your option) any later version. |
|
16
|
|
|
* |
|
17
|
|
|
* This program is distributed in the hope that it will be useful, |
|
18
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
19
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
20
|
|
|
* GNU Affero General Public License for more details. |
|
21
|
|
|
* |
|
22
|
|
|
* You should have received a copy of the GNU Affero General Public License |
|
23
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
24
|
|
|
*/ |
|
25
|
|
|
|
|
26
|
|
|
namespace OCP\DB; |
|
27
|
|
|
|
|
28
|
|
|
use Exception as BaseException; |
|
29
|
|
|
|
|
30
|
|
|
/** |
|
31
|
|
|
* Database exception |
|
32
|
|
|
* |
|
33
|
|
|
* Thrown by Nextcloud's database abstraction layer. This is the base class that |
|
34
|
|
|
* any specific exception will extend. Use this class in your try-catch to catch |
|
35
|
|
|
* *any* error related to the database. Use any of the subclasses in the same |
|
36
|
|
|
* namespace if you are only interested in specific errors. |
|
37
|
|
|
* |
|
38
|
|
|
* @psalm-immutable |
|
39
|
|
|
* @since 21.0.0 |
|
40
|
|
|
*/ |
|
41
|
|
|
class Exception extends BaseException { |
|
42
|
|
|
|
|
43
|
|
|
/** |
|
44
|
|
|
* Nextcloud lost connection to the database |
|
45
|
|
|
* |
|
46
|
|
|
* @since 21.0.0 |
|
47
|
|
|
*/ |
|
48
|
|
|
public const REASON_CONNECTION_LOST = 1; |
|
49
|
|
|
|
|
50
|
|
|
/** |
|
51
|
|
|
* A database constraint was violated |
|
52
|
|
|
* |
|
53
|
|
|
* @since 21.0.0 |
|
54
|
|
|
*/ |
|
55
|
|
|
public const REASON_CONSTRAINT_VIOLATION = 2; |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* A database object (table, column, index) already exists |
|
59
|
|
|
* |
|
60
|
|
|
* @since 21.0.0 |
|
61
|
|
|
*/ |
|
62
|
|
|
public const REASON_DATABASE_OBJECT_EXISTS = 3; |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* A database object (table, column, index) can't be found |
|
66
|
|
|
* |
|
67
|
|
|
* @since 21.0.0 |
|
68
|
|
|
*/ |
|
69
|
|
|
public const REASON_DATABASE_OBJECT_NOT_FOUND = 4; |
|
70
|
|
|
|
|
71
|
|
|
/** |
|
72
|
|
|
* The database ran into a deadlock |
|
73
|
|
|
* |
|
74
|
|
|
* @since 21.0.0 |
|
75
|
|
|
*/ |
|
76
|
|
|
public const REASON_DEADLOCK = 5; |
|
77
|
|
|
|
|
78
|
|
|
/** |
|
79
|
|
|
* The database driver encountered an issue |
|
80
|
|
|
* |
|
81
|
|
|
* @since 21.0.0 |
|
82
|
|
|
*/ |
|
83
|
|
|
public const REASON_DRIVER = 6; |
|
84
|
|
|
|
|
85
|
|
|
/** |
|
86
|
|
|
* A foreign key constraint was violated |
|
87
|
|
|
* |
|
88
|
|
|
* @since 21.0.0 |
|
89
|
|
|
*/ |
|
90
|
|
|
public const REASON_FOREIGN_KEY_VIOLATION = 7; |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* An invalid argument was passed to the database abstraction |
|
94
|
|
|
* |
|
95
|
|
|
* @since 21.0.0 |
|
96
|
|
|
*/ |
|
97
|
|
|
public const REASON_INVALID_ARGUMENT = 8; |
|
98
|
|
|
|
|
99
|
|
|
/** |
|
100
|
|
|
* A field name was invalid |
|
101
|
|
|
* |
|
102
|
|
|
* @since 21.0.0 |
|
103
|
|
|
*/ |
|
104
|
|
|
public const REASON_INVALID_FIELD_NAME = 9; |
|
105
|
|
|
|
|
106
|
|
|
/** |
|
107
|
|
|
* A name in the query was ambiguous |
|
108
|
|
|
* |
|
109
|
|
|
* @since 21.0.0 |
|
110
|
|
|
*/ |
|
111
|
|
|
public const REASON_NON_UNIQUE_FIELD_NAME = 10; |
|
112
|
|
|
|
|
113
|
|
|
/** |
|
114
|
|
|
* A not null contraint was violated |
|
115
|
|
|
* |
|
116
|
|
|
* @since 21.0.0 |
|
117
|
|
|
*/ |
|
118
|
|
|
public const REASON_NOT_NULL_CONSTRAINT_VIOLATION = 11; |
|
119
|
|
|
|
|
120
|
|
|
/** |
|
121
|
|
|
* A generic server error was encountered |
|
122
|
|
|
* |
|
123
|
|
|
* @since 21.0.0 |
|
124
|
|
|
*/ |
|
125
|
|
|
public const REASON_SERVER = 12; |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* A syntax error was reported by the server |
|
129
|
|
|
* |
|
130
|
|
|
* @since 21.0.0 |
|
131
|
|
|
*/ |
|
132
|
|
|
public const REASON_SYNTAX_ERROR = 13; |
|
133
|
|
|
|
|
134
|
|
|
/** |
|
135
|
|
|
* A unique constraint was violated |
|
136
|
|
|
* |
|
137
|
|
|
* @since 21.0.0 |
|
138
|
|
|
*/ |
|
139
|
|
|
public const REASON_UNIQUE_CONSTRAINT_VIOLATION = 14; |
|
140
|
|
|
|
|
141
|
|
|
/** |
|
142
|
|
|
* @return int|null |
|
143
|
|
|
* @psalm-return Exception::REASON_* |
|
144
|
|
|
* @since 21.0.0 |
|
145
|
|
|
*/ |
|
146
|
|
|
public function getReason(): ?int { |
|
147
|
|
|
return null; |
|
148
|
|
|
} |
|
149
|
|
|
} |
|
150
|
|
|
|