1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace SilverStripe\ORM\Connect; |
4
|
|
|
|
5
|
|
|
use BadMethodCallException; |
6
|
|
|
use Exception; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* Utility class required due to bad coupling in framework. |
10
|
|
|
* Not every framework execution should require a working database connection. |
11
|
|
|
* For example, when generating class and config manifests for deployment bundles, |
12
|
|
|
* or when generating code in a silverstripe/graphql schema build. |
13
|
|
|
* |
14
|
|
|
* This class creates the required no-ops to fulfill the contract, |
15
|
|
|
* and create exceptions as required. |
16
|
|
|
* |
17
|
|
|
* It also avoids introducing new third party core dependencies that |
18
|
|
|
* would be required with https://github.com/tractorcow/silverstripe-proxy-db. |
19
|
|
|
* |
20
|
|
|
* @internal |
21
|
|
|
*/ |
22
|
|
|
class NullDatabase extends Database |
23
|
|
|
{ |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* @var string |
27
|
|
|
*/ |
28
|
|
|
protected $errorMessage = 'Using NullDatabase, cannot interact with database'; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @var string |
32
|
|
|
*/ |
33
|
|
|
protected $queryErrorMessage = 'Using NullDatabase, cannot execute query: %s'; |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* @param string $msg |
37
|
|
|
* @return self |
38
|
|
|
*/ |
39
|
|
|
public function setErrorMessage(string $msg) |
40
|
|
|
{ |
41
|
|
|
$this->errorMessage = $msg; |
42
|
|
|
return $this; |
43
|
|
|
} |
44
|
|
|
|
45
|
|
|
/** |
46
|
|
|
* @param string $msg |
47
|
|
|
* @return self |
48
|
|
|
*/ |
49
|
|
|
public function setQueryErrorMessage(string $msg) |
50
|
|
|
{ |
51
|
|
|
$this->queryErrorMessage = $msg; |
52
|
|
|
return $this; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
public function query($sql, $errorLevel = E_USER_ERROR) |
56
|
|
|
{ |
57
|
|
|
throw new \LogicException(sprintf($this->queryErrorMessage, $sql)); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
public function preparedQuery($sql, $parameters, $errorLevel = E_USER_ERROR) |
61
|
|
|
{ |
62
|
|
|
throw new \LogicException(sprintf($this->queryErrorMessage, $sql)); |
63
|
|
|
} |
64
|
|
|
|
65
|
|
|
public function getConnector() |
66
|
|
|
{ |
67
|
|
|
throw new \LogicException($this->errorMessage); |
68
|
|
|
} |
69
|
|
|
|
70
|
|
|
public function getSchemaManager() |
71
|
|
|
{ |
72
|
|
|
throw new \LogicException($this->errorMessage); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
public function getQueryBuilder() |
76
|
|
|
{ |
77
|
|
|
throw new \LogicException($this->errorMessage); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
public function getGeneratedID($table) |
81
|
|
|
{ |
82
|
|
|
// no-op |
83
|
|
|
} |
84
|
|
|
|
85
|
|
|
public function isActive() |
86
|
|
|
{ |
87
|
|
|
return true; |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
public function escapeString($value) |
91
|
|
|
{ |
92
|
|
|
return $value; |
93
|
|
|
} |
94
|
|
|
|
95
|
|
|
public function quoteString($value) |
96
|
|
|
{ |
97
|
|
|
return $value; |
98
|
|
|
} |
99
|
|
|
|
100
|
|
|
public function escapeIdentifier($value, $separator = '.') |
101
|
|
|
{ |
102
|
|
|
return $value; |
103
|
|
|
} |
104
|
|
|
|
105
|
|
|
protected function escapeColumnKeys($fieldValues) |
106
|
|
|
{ |
107
|
|
|
return $fieldValues; |
108
|
|
|
} |
109
|
|
|
|
110
|
|
|
public function manipulate($manipulation) |
111
|
|
|
{ |
112
|
|
|
throw new \LogicException($this->errorMessage); |
113
|
|
|
} |
114
|
|
|
|
115
|
|
|
public function clearAllData() |
116
|
|
|
{ |
117
|
|
|
throw new \LogicException($this->errorMessage); |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
public function clearTable($table) |
121
|
|
|
{ |
122
|
|
|
throw new \LogicException($this->errorMessage); |
123
|
|
|
} |
124
|
|
|
|
125
|
|
|
public function nullCheckClause($field, $isNull) |
126
|
|
|
{ |
127
|
|
|
return ''; |
128
|
|
|
} |
129
|
|
|
|
130
|
|
|
public function comparisonClause( |
131
|
|
|
$field, |
132
|
|
|
$value, |
133
|
|
|
$exact = false, |
134
|
|
|
$negate = false, |
135
|
|
|
$caseSensitive = null, |
136
|
|
|
$parameterised = false |
137
|
|
|
) { |
138
|
|
|
return ''; |
139
|
|
|
} |
140
|
|
|
|
141
|
|
|
public function formattedDatetimeClause($date, $format) |
142
|
|
|
{ |
143
|
|
|
return ''; |
144
|
|
|
} |
145
|
|
|
|
146
|
|
|
public function datetimeIntervalClause($date, $interval) |
147
|
|
|
{ |
148
|
|
|
return ''; |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
public function datetimeDifferenceClause($date1, $date2) |
152
|
|
|
{ |
153
|
|
|
return ''; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
public function concatOperator() |
157
|
|
|
{ |
158
|
|
|
return ''; |
159
|
|
|
} |
160
|
|
|
|
161
|
|
|
public function supportsCollations() |
162
|
|
|
{ |
163
|
|
|
return false; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
public function supportsTimezoneOverride() |
167
|
|
|
{ |
168
|
|
|
return false; |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
public function getVersion() |
172
|
|
|
{ |
173
|
|
|
return ''; |
174
|
|
|
} |
175
|
|
|
|
176
|
|
|
public function getDatabaseServer() |
177
|
|
|
{ |
178
|
|
|
return ''; |
179
|
|
|
} |
180
|
|
|
|
181
|
|
|
public function affectedRows() |
182
|
|
|
{ |
183
|
|
|
return 0; |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
public function searchEngine( |
187
|
|
|
$classesToSearch, |
188
|
|
|
$keywords, |
189
|
|
|
$start, |
190
|
|
|
$pageLength, |
191
|
|
|
$sortBy = "Relevance DESC", |
192
|
|
|
$extraFilter = "", |
193
|
|
|
$booleanSearch = false, |
194
|
|
|
$alternativeFileFilter = "", |
195
|
|
|
$invertedMatch = false |
196
|
|
|
) { |
197
|
|
|
// no-op |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
public function supportsTransactions() |
201
|
|
|
{ |
202
|
|
|
return false; |
203
|
|
|
} |
204
|
|
|
|
205
|
|
|
public function supportsSavepoints() |
206
|
|
|
{ |
207
|
|
|
return false; |
208
|
|
|
} |
209
|
|
|
|
210
|
|
|
|
211
|
|
|
public function supportsTransactionMode(string $mode): bool |
212
|
|
|
{ |
213
|
|
|
return false; |
214
|
|
|
} |
215
|
|
|
|
216
|
|
|
public function withTransaction( |
217
|
|
|
$callback, |
218
|
|
|
$errorCallback = null, |
219
|
|
|
$transactionMode = false, |
220
|
|
|
$errorIfTransactionsUnsupported = false |
221
|
|
|
) { |
222
|
|
|
// no-op |
223
|
|
|
} |
224
|
|
|
|
225
|
|
|
public function supportsExtensions($extensions) |
226
|
|
|
{ |
227
|
|
|
return false; |
228
|
|
|
} |
229
|
|
|
|
230
|
|
|
public function transactionStart($transactionMode = false, $sessionCharacteristics = false) |
231
|
|
|
{ |
232
|
|
|
// no-op |
233
|
|
|
} |
234
|
|
|
|
235
|
|
|
public function transactionSavepoint($savepoint) |
236
|
|
|
{ |
237
|
|
|
// no-op |
238
|
|
|
} |
239
|
|
|
|
240
|
|
|
public function transactionRollback($savepoint = false) |
241
|
|
|
{ |
242
|
|
|
// no-op |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
public function transactionEnd($chain = false) |
246
|
|
|
{ |
247
|
|
|
// no-op |
248
|
|
|
} |
249
|
|
|
|
250
|
|
|
public function transactionDepth() |
251
|
|
|
{ |
252
|
|
|
return 0; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
public function supportsLocks() |
256
|
|
|
{ |
257
|
|
|
return false; |
258
|
|
|
} |
259
|
|
|
|
260
|
|
|
public function canLock($name) |
261
|
|
|
{ |
262
|
|
|
return false; |
263
|
|
|
} |
264
|
|
|
|
265
|
|
|
public function getLock($name, $timeout = 5) |
266
|
|
|
{ |
267
|
|
|
return false; |
268
|
|
|
} |
269
|
|
|
|
270
|
|
|
public function releaseLock($name) |
271
|
|
|
{ |
272
|
|
|
return false; |
273
|
|
|
} |
274
|
|
|
|
275
|
|
|
public function connect($parameters) |
276
|
|
|
{ |
277
|
|
|
// no-op |
278
|
|
|
} |
279
|
|
|
|
280
|
|
|
public function databaseExists($name) |
281
|
|
|
{ |
282
|
|
|
return false; |
283
|
|
|
} |
284
|
|
|
|
285
|
|
|
public function databaseList() |
286
|
|
|
{ |
287
|
|
|
return []; |
288
|
|
|
} |
289
|
|
|
|
290
|
|
|
public function selectDatabase($name, $create = false, $errorLevel = E_USER_ERROR) |
291
|
|
|
{ |
292
|
|
|
// no-op |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
public function dropSelectedDatabase() |
296
|
|
|
{ |
297
|
|
|
// no-op |
298
|
|
|
} |
299
|
|
|
|
300
|
|
|
public function getSelectedDatabase() |
301
|
|
|
{ |
302
|
|
|
// no-op |
303
|
|
|
} |
304
|
|
|
|
305
|
|
|
public function now() |
306
|
|
|
{ |
307
|
|
|
return ''; |
308
|
|
|
} |
309
|
|
|
|
310
|
|
|
public function random() |
311
|
|
|
{ |
312
|
|
|
return ''; |
313
|
|
|
} |
314
|
|
|
} |
315
|
|
|
|