1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Doctrine\DBAL\Platforms; |
4
|
|
|
|
5
|
|
|
use Doctrine\Common\EventManager; |
6
|
|
|
use Doctrine\DBAL\DBALException; |
7
|
|
|
use Doctrine\DBAL\Event\SchemaAlterTableAddColumnEventArgs; |
8
|
|
|
use Doctrine\DBAL\Event\SchemaAlterTableChangeColumnEventArgs; |
9
|
|
|
use Doctrine\DBAL\Event\SchemaAlterTableEventArgs; |
10
|
|
|
use Doctrine\DBAL\Event\SchemaAlterTableRemoveColumnEventArgs; |
11
|
|
|
use Doctrine\DBAL\Event\SchemaAlterTableRenameColumnEventArgs; |
12
|
|
|
use Doctrine\DBAL\Event\SchemaCreateTableColumnEventArgs; |
13
|
|
|
use Doctrine\DBAL\Event\SchemaCreateTableEventArgs; |
14
|
|
|
use Doctrine\DBAL\Event\SchemaDropTableEventArgs; |
15
|
|
|
use Doctrine\DBAL\Events; |
16
|
|
|
use Doctrine\DBAL\Platforms\Keywords\KeywordList; |
17
|
|
|
use Doctrine\DBAL\Schema\Column; |
18
|
|
|
use Doctrine\DBAL\Schema\ColumnDiff; |
19
|
|
|
use Doctrine\DBAL\Schema\Constraint; |
20
|
|
|
use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
21
|
|
|
use Doctrine\DBAL\Schema\Identifier; |
22
|
|
|
use Doctrine\DBAL\Schema\Index; |
23
|
|
|
use Doctrine\DBAL\Schema\Sequence; |
24
|
|
|
use Doctrine\DBAL\Schema\Table; |
25
|
|
|
use Doctrine\DBAL\Schema\TableDiff; |
26
|
|
|
use Doctrine\DBAL\TransactionIsolationLevel; |
27
|
|
|
use Doctrine\DBAL\Types; |
28
|
|
|
use Doctrine\DBAL\Types\Type; |
29
|
|
|
use InvalidArgumentException; |
30
|
|
|
use UnexpectedValueException; |
31
|
|
|
use function addcslashes; |
32
|
|
|
use function array_map; |
33
|
|
|
use function array_merge; |
34
|
|
|
use function array_unique; |
35
|
|
|
use function array_values; |
36
|
|
|
use function assert; |
37
|
|
|
use function count; |
38
|
|
|
use function explode; |
39
|
|
|
use function func_get_arg; |
40
|
|
|
use function func_get_args; |
41
|
|
|
use function func_num_args; |
42
|
|
|
use function implode; |
43
|
|
|
use function in_array; |
44
|
|
|
use function is_array; |
45
|
|
|
use function is_bool; |
46
|
|
|
use function is_int; |
47
|
|
|
use function is_string; |
48
|
|
|
use function preg_quote; |
49
|
|
|
use function preg_replace; |
50
|
|
|
use function sprintf; |
51
|
|
|
use function str_replace; |
52
|
|
|
use function strlen; |
53
|
|
|
use function strpos; |
54
|
|
|
use function strtolower; |
55
|
|
|
use function strtoupper; |
56
|
|
|
use function trigger_error; |
57
|
|
|
use const E_USER_DEPRECATED; |
58
|
|
|
|
59
|
|
|
/** |
60
|
|
|
* Base class for all DatabasePlatforms. The DatabasePlatforms are the central |
61
|
|
|
* point of abstraction of platform-specific behaviors, features and SQL dialects. |
62
|
|
|
* They are a passive source of information. |
63
|
|
|
* |
64
|
|
|
* @todo Remove any unnecessary methods. |
65
|
|
|
*/ |
66
|
|
|
abstract class AbstractPlatform |
67
|
|
|
{ |
68
|
|
|
public const CREATE_INDEXES = 1; |
69
|
|
|
|
70
|
|
|
public const CREATE_FOREIGNKEYS = 2; |
71
|
|
|
|
72
|
|
|
/** |
73
|
|
|
* @deprecated Use DateIntervalUnit::INTERVAL_UNIT_SECOND. |
74
|
|
|
*/ |
75
|
|
|
public const DATE_INTERVAL_UNIT_SECOND = DateIntervalUnit::SECOND; |
76
|
|
|
|
77
|
|
|
/** |
78
|
|
|
* @deprecated Use DateIntervalUnit::MINUTE. |
79
|
|
|
*/ |
80
|
|
|
public const DATE_INTERVAL_UNIT_MINUTE = DateIntervalUnit::MINUTE; |
81
|
|
|
|
82
|
|
|
/** |
83
|
|
|
* @deprecated Use DateIntervalUnit::HOUR. |
84
|
|
|
*/ |
85
|
|
|
public const DATE_INTERVAL_UNIT_HOUR = DateIntervalUnit::HOUR; |
86
|
|
|
|
87
|
|
|
/** |
88
|
|
|
* @deprecated Use DateIntervalUnit::DAY. |
89
|
|
|
*/ |
90
|
|
|
public const DATE_INTERVAL_UNIT_DAY = DateIntervalUnit::DAY; |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* @deprecated Use DateIntervalUnit::WEEK. |
94
|
|
|
*/ |
95
|
|
|
public const DATE_INTERVAL_UNIT_WEEK = DateIntervalUnit::WEEK; |
96
|
|
|
|
97
|
|
|
/** |
98
|
|
|
* @deprecated Use DateIntervalUnit::MONTH. |
99
|
|
|
*/ |
100
|
|
|
public const DATE_INTERVAL_UNIT_MONTH = DateIntervalUnit::MONTH; |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @deprecated Use DateIntervalUnit::QUARTER. |
104
|
|
|
*/ |
105
|
|
|
public const DATE_INTERVAL_UNIT_QUARTER = DateIntervalUnit::QUARTER; |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* @deprecated Use DateIntervalUnit::QUARTER. |
109
|
|
|
*/ |
110
|
|
|
public const DATE_INTERVAL_UNIT_YEAR = DateIntervalUnit::YEAR; |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* @deprecated Use TrimMode::UNSPECIFIED. |
114
|
|
|
*/ |
115
|
|
|
public const TRIM_UNSPECIFIED = TrimMode::UNSPECIFIED; |
116
|
|
|
|
117
|
|
|
/** |
118
|
|
|
* @deprecated Use TrimMode::LEADING. |
119
|
|
|
*/ |
120
|
|
|
public const TRIM_LEADING = TrimMode::LEADING; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @deprecated Use TrimMode::TRAILING. |
124
|
|
|
*/ |
125
|
|
|
public const TRIM_TRAILING = TrimMode::TRAILING; |
126
|
|
|
|
127
|
|
|
/** |
128
|
|
|
* @deprecated Use TrimMode::BOTH. |
129
|
|
|
*/ |
130
|
|
|
public const TRIM_BOTH = TrimMode::BOTH; |
131
|
|
|
|
132
|
|
|
/** @var string[]|null */ |
133
|
|
|
protected $doctrineTypeMapping = null; |
134
|
|
|
|
135
|
|
|
/** |
136
|
|
|
* Contains a list of all columns that should generate parseable column comments for type-detection |
137
|
|
|
* in reverse engineering scenarios. |
138
|
|
|
* |
139
|
|
|
* @var string[]|null |
140
|
|
|
*/ |
141
|
|
|
protected $doctrineTypeComments = null; |
142
|
|
|
|
143
|
|
|
/** @var EventManager|null */ |
144
|
|
|
protected $_eventManager; |
145
|
|
|
|
146
|
|
|
/** |
147
|
|
|
* Holds the KeywordList instance for the current platform. |
148
|
|
|
* |
149
|
|
|
* @var KeywordList|null |
150
|
|
|
*/ |
151
|
|
|
protected $_keywords; |
152
|
|
|
|
153
|
42320 |
|
public function __construct() |
154
|
|
|
{ |
155
|
42320 |
|
} |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Sets the EventManager used by the Platform. |
159
|
|
|
* |
160
|
|
|
* @return void |
161
|
|
|
*/ |
162
|
1268 |
|
public function setEventManager(EventManager $eventManager) |
163
|
|
|
{ |
164
|
1268 |
|
$this->_eventManager = $eventManager; |
165
|
1268 |
|
} |
166
|
|
|
|
167
|
|
|
/** |
168
|
|
|
* Gets the EventManager used by the Platform. |
169
|
|
|
* |
170
|
|
|
* @return EventManager|null |
171
|
|
|
*/ |
172
|
1716 |
|
public function getEventManager() |
173
|
|
|
{ |
174
|
1716 |
|
return $this->_eventManager; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* Returns the SQL snippet that declares a boolean column. |
179
|
|
|
* |
180
|
|
|
* @param mixed[] $columnDef |
181
|
|
|
* |
182
|
|
|
* @return string |
183
|
|
|
*/ |
184
|
|
|
abstract public function getBooleanTypeDeclarationSQL(array $columnDef); |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* Returns the SQL snippet that declares a 4 byte integer column. |
188
|
|
|
* |
189
|
|
|
* @param mixed[] $columnDef |
190
|
|
|
* |
191
|
|
|
* @return string |
192
|
|
|
*/ |
193
|
|
|
abstract public function getIntegerTypeDeclarationSQL(array $columnDef); |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Returns the SQL snippet that declares an 8 byte integer column. |
197
|
|
|
* |
198
|
|
|
* @param mixed[] $columnDef |
199
|
|
|
* |
200
|
|
|
* @return string |
201
|
|
|
*/ |
202
|
|
|
abstract public function getBigIntTypeDeclarationSQL(array $columnDef); |
203
|
|
|
|
204
|
|
|
/** |
205
|
|
|
* Returns the SQL snippet that declares a 2 byte integer column. |
206
|
|
|
* |
207
|
|
|
* @param mixed[] $columnDef |
208
|
|
|
* |
209
|
|
|
* @return string |
210
|
|
|
*/ |
211
|
|
|
abstract public function getSmallIntTypeDeclarationSQL(array $columnDef); |
212
|
|
|
|
213
|
|
|
/** |
214
|
|
|
* Returns the SQL snippet that declares common properties of an integer column. |
215
|
|
|
* |
216
|
|
|
* @param mixed[] $columnDef |
217
|
|
|
* |
218
|
|
|
* @return string |
219
|
|
|
*/ |
220
|
|
|
abstract protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef); |
221
|
|
|
|
222
|
|
|
/** |
223
|
|
|
* Lazy load Doctrine Type Mappings. |
224
|
|
|
* |
225
|
|
|
* @return void |
226
|
|
|
*/ |
227
|
|
|
abstract protected function initializeDoctrineTypeMappings(); |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* Initializes Doctrine Type Mappings with the platform defaults |
231
|
|
|
* and with all additional type mappings. |
232
|
|
|
* |
233
|
|
|
* @return void |
234
|
|
|
*/ |
235
|
1266 |
|
private function initializeAllDoctrineTypeMappings() |
236
|
|
|
{ |
237
|
1266 |
|
$this->initializeDoctrineTypeMappings(); |
238
|
|
|
|
239
|
1266 |
|
foreach (Type::getTypesMap() as $typeName => $className) { |
240
|
1266 |
|
foreach (Type::getType($typeName)->getMappedDatabaseTypes($this) as $dbType) { |
241
|
684 |
|
$this->doctrineTypeMapping[$dbType] = $typeName; |
242
|
|
|
} |
243
|
|
|
} |
244
|
1266 |
|
} |
245
|
|
|
|
246
|
|
|
/** |
247
|
|
|
* Returns the SQL snippet used to declare a VARCHAR column type. |
248
|
|
|
* |
249
|
|
|
* @param mixed[] $field |
250
|
|
|
* |
251
|
|
|
* @return string |
252
|
|
|
*/ |
253
|
5143 |
|
public function getVarcharTypeDeclarationSQL(array $field) |
254
|
|
|
{ |
255
|
5143 |
|
if (! isset($field['length'])) { |
256
|
985 |
|
$field['length'] = $this->getVarcharDefaultLength(); |
257
|
|
|
} |
258
|
|
|
|
259
|
5143 |
|
$fixed = $field['fixed'] ?? false; |
260
|
|
|
|
261
|
5143 |
|
$maxLength = $fixed |
262
|
760 |
|
? $this->getCharMaxLength() |
263
|
5143 |
|
: $this->getVarcharMaxLength(); |
264
|
|
|
|
265
|
5143 |
|
if ($field['length'] > $maxLength) { |
266
|
|
|
return $this->getClobTypeDeclarationSQL($field); |
267
|
|
|
} |
268
|
|
|
|
269
|
5143 |
|
return $this->getVarcharTypeDeclarationSQLSnippet($field['length'], $fixed); |
270
|
|
|
} |
271
|
|
|
|
272
|
|
|
/** |
273
|
|
|
* Returns the SQL snippet used to declare a BINARY/VARBINARY column type. |
274
|
|
|
* |
275
|
|
|
* @param mixed[] $field The column definition. |
276
|
|
|
* |
277
|
|
|
* @return string |
278
|
|
|
*/ |
279
|
417 |
|
public function getBinaryTypeDeclarationSQL(array $field) |
280
|
|
|
{ |
281
|
417 |
|
if (! isset($field['length'])) { |
282
|
241 |
|
$field['length'] = $this->getBinaryDefaultLength(); |
283
|
|
|
} |
284
|
|
|
|
285
|
417 |
|
$fixed = $field['fixed'] ?? false; |
286
|
|
|
|
287
|
417 |
|
$maxLength = $this->getBinaryMaxLength(); |
288
|
|
|
|
289
|
417 |
|
if ($field['length'] > $maxLength) { |
290
|
226 |
|
if ($maxLength > 0) { |
291
|
154 |
|
@trigger_error(sprintf( |
292
|
7 |
|
'Binary field length %d is greater than supported by the platform (%d). Reduce the field length or use a BLOB field instead.', |
293
|
154 |
|
$field['length'], |
294
|
154 |
|
$maxLength |
295
|
154 |
|
), E_USER_DEPRECATED); |
296
|
|
|
} |
297
|
|
|
|
298
|
226 |
|
return $this->getBlobTypeDeclarationSQL($field); |
299
|
|
|
} |
300
|
|
|
|
301
|
257 |
|
return $this->getBinaryTypeDeclarationSQLSnippet($field['length'], $fixed); |
302
|
|
|
} |
303
|
|
|
|
304
|
|
|
/** |
305
|
|
|
* Returns the SQL snippet to declare a GUID/UUID field. |
306
|
|
|
* |
307
|
|
|
* By default this maps directly to a CHAR(36) and only maps to more |
308
|
|
|
* special datatypes when the underlying databases support this datatype. |
309
|
|
|
* |
310
|
|
|
* @param mixed[] $field |
311
|
|
|
* |
312
|
|
|
* @return string |
313
|
|
|
*/ |
314
|
144 |
|
public function getGuidTypeDeclarationSQL(array $field) |
315
|
|
|
{ |
316
|
144 |
|
$field['length'] = 36; |
317
|
144 |
|
$field['fixed'] = true; |
318
|
|
|
|
319
|
144 |
|
return $this->getVarcharTypeDeclarationSQL($field); |
320
|
|
|
} |
321
|
|
|
|
322
|
|
|
/** |
323
|
|
|
* Returns the SQL snippet to declare a JSON field. |
324
|
|
|
* |
325
|
|
|
* By default this maps directly to a CLOB and only maps to more |
326
|
|
|
* special datatypes when the underlying databases support this datatype. |
327
|
|
|
* |
328
|
|
|
* @param mixed[] $field |
329
|
|
|
* |
330
|
|
|
* @return string |
331
|
|
|
*/ |
332
|
289 |
|
public function getJsonTypeDeclarationSQL(array $field) |
333
|
|
|
{ |
334
|
289 |
|
return $this->getClobTypeDeclarationSQL($field); |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
/** |
338
|
|
|
* @param int|false $length |
339
|
|
|
* @param bool $fixed |
340
|
|
|
* |
341
|
|
|
* @return string |
342
|
|
|
* |
343
|
|
|
* @throws DBALException If not supported on this platform. |
344
|
|
|
*/ |
345
|
|
|
protected function getVarcharTypeDeclarationSQLSnippet($length, $fixed) |
|
|
|
|
346
|
|
|
{ |
347
|
|
|
throw DBALException::notSupported('VARCHARs not supported by Platform.'); |
348
|
|
|
} |
349
|
|
|
|
350
|
|
|
/** |
351
|
|
|
* Returns the SQL snippet used to declare a BINARY/VARBINARY column type. |
352
|
|
|
* |
353
|
|
|
* @param int|false $length The length of the column. |
354
|
|
|
* @param bool $fixed Whether the column length is fixed. |
355
|
|
|
* |
356
|
|
|
* @return string |
357
|
|
|
* |
358
|
|
|
* @throws DBALException If not supported on this platform. |
359
|
|
|
*/ |
360
|
|
|
protected function getBinaryTypeDeclarationSQLSnippet($length, $fixed) |
|
|
|
|
361
|
|
|
{ |
362
|
|
|
throw DBALException::notSupported('BINARY/VARBINARY column types are not supported by this platform.'); |
363
|
|
|
} |
364
|
|
|
|
365
|
|
|
/** |
366
|
|
|
* Returns the SQL snippet used to declare a CLOB column type. |
367
|
|
|
* |
368
|
|
|
* @param mixed[] $field |
369
|
|
|
* |
370
|
|
|
* @return string |
371
|
|
|
*/ |
372
|
|
|
abstract public function getClobTypeDeclarationSQL(array $field); |
373
|
|
|
|
374
|
|
|
/** |
375
|
|
|
* Returns the SQL Snippet used to declare a BLOB column type. |
376
|
|
|
* |
377
|
|
|
* @param mixed[] $field |
378
|
|
|
* |
379
|
|
|
* @return string |
380
|
|
|
*/ |
381
|
|
|
abstract public function getBlobTypeDeclarationSQL(array $field); |
382
|
|
|
|
383
|
|
|
/** |
384
|
|
|
* Gets the name of the platform. |
385
|
|
|
* |
386
|
|
|
* @return string |
387
|
|
|
*/ |
388
|
|
|
abstract public function getName(); |
389
|
|
|
|
390
|
|
|
/** |
391
|
|
|
* Registers a doctrine type to be used in conjunction with a column type of this platform. |
392
|
|
|
* |
393
|
|
|
* @param string $dbType |
394
|
|
|
* @param string $doctrineType |
395
|
|
|
* |
396
|
|
|
* @return void |
397
|
|
|
* |
398
|
|
|
* @throws DBALException If the type is not found. |
399
|
|
|
*/ |
400
|
687 |
|
public function registerDoctrineTypeMapping($dbType, $doctrineType) |
401
|
|
|
{ |
402
|
687 |
|
if ($this->doctrineTypeMapping === null) { |
403
|
682 |
|
$this->initializeAllDoctrineTypeMappings(); |
404
|
|
|
} |
405
|
|
|
|
406
|
687 |
|
if (! Types\Type::hasType($doctrineType)) { |
407
|
220 |
|
throw DBALException::typeNotFound($doctrineType); |
408
|
|
|
} |
409
|
|
|
|
410
|
467 |
|
$dbType = strtolower($dbType); |
411
|
467 |
|
$this->doctrineTypeMapping[$dbType] = $doctrineType; |
412
|
|
|
|
413
|
467 |
|
$doctrineType = Type::getType($doctrineType); |
414
|
|
|
|
415
|
467 |
|
if (! $doctrineType->requiresSQLCommentHint($this)) { |
416
|
247 |
|
return; |
417
|
|
|
} |
418
|
|
|
|
419
|
220 |
|
$this->markDoctrineTypeCommented($doctrineType); |
420
|
220 |
|
} |
421
|
|
|
|
422
|
|
|
/** |
423
|
|
|
* Gets the Doctrine type that is mapped for the given database column type. |
424
|
|
|
* |
425
|
|
|
* @param string $dbType |
426
|
|
|
* |
427
|
|
|
* @return string |
428
|
|
|
* |
429
|
|
|
* @throws DBALException |
430
|
|
|
*/ |
431
|
2346 |
|
public function getDoctrineTypeMapping($dbType) |
432
|
|
|
{ |
433
|
2346 |
|
if ($this->doctrineTypeMapping === null) { |
434
|
298 |
|
$this->initializeAllDoctrineTypeMappings(); |
435
|
|
|
} |
436
|
|
|
|
437
|
2346 |
|
$dbType = strtolower($dbType); |
438
|
|
|
|
439
|
2346 |
|
if (! isset($this->doctrineTypeMapping[$dbType])) { |
440
|
220 |
|
throw new DBALException('Unknown database type ' . $dbType . ' requested, ' . static::class . ' may not support it.'); |
441
|
|
|
} |
442
|
|
|
|
443
|
2126 |
|
return $this->doctrineTypeMapping[$dbType]; |
444
|
|
|
} |
445
|
|
|
|
446
|
|
|
/** |
447
|
|
|
* Checks if a database type is currently supported by this platform. |
448
|
|
|
* |
449
|
|
|
* @param string $dbType |
450
|
|
|
* |
451
|
|
|
* @return bool |
452
|
|
|
*/ |
453
|
328 |
|
public function hasDoctrineTypeMappingFor($dbType) |
454
|
|
|
{ |
455
|
328 |
|
if ($this->doctrineTypeMapping === null) { |
456
|
286 |
|
$this->initializeAllDoctrineTypeMappings(); |
457
|
|
|
} |
458
|
|
|
|
459
|
328 |
|
$dbType = strtolower($dbType); |
460
|
|
|
|
461
|
328 |
|
return isset($this->doctrineTypeMapping[$dbType]); |
462
|
|
|
} |
463
|
|
|
|
464
|
|
|
/** |
465
|
|
|
* Initializes the Doctrine Type comments instance variable for in_array() checks. |
466
|
|
|
* |
467
|
|
|
* @return void |
468
|
|
|
*/ |
469
|
11149 |
|
protected function initializeCommentedDoctrineTypes() |
470
|
|
|
{ |
471
|
11149 |
|
$this->doctrineTypeComments = []; |
472
|
|
|
|
473
|
11149 |
|
foreach (Type::getTypesMap() as $typeName => $className) { |
474
|
11149 |
|
$type = Type::getType($typeName); |
475
|
|
|
|
476
|
11149 |
|
if (! $type->requiresSQLCommentHint($this)) { |
477
|
11149 |
|
continue; |
478
|
|
|
} |
479
|
|
|
|
480
|
11149 |
|
$this->doctrineTypeComments[] = $typeName; |
481
|
|
|
} |
482
|
11149 |
|
} |
483
|
|
|
|
484
|
|
|
/** |
485
|
|
|
* Is it necessary for the platform to add a parsable type comment to allow reverse engineering the given type? |
486
|
|
|
* |
487
|
|
|
* @return bool |
488
|
|
|
*/ |
489
|
14561 |
|
public function isCommentedDoctrineType(Type $doctrineType) |
490
|
|
|
{ |
491
|
14561 |
|
if ($this->doctrineTypeComments === null) { |
492
|
10929 |
|
$this->initializeCommentedDoctrineTypes(); |
493
|
|
|
} |
494
|
|
|
|
495
|
14561 |
|
assert(is_array($this->doctrineTypeComments)); |
496
|
|
|
|
497
|
14561 |
|
return in_array($doctrineType->getName(), $this->doctrineTypeComments, true); |
498
|
|
|
} |
499
|
|
|
|
500
|
|
|
/** |
501
|
|
|
* Marks this type as to be commented in ALTER TABLE and CREATE TABLE statements. |
502
|
|
|
* |
503
|
|
|
* @param string|Type $doctrineType |
504
|
|
|
* |
505
|
|
|
* @return void |
506
|
|
|
*/ |
507
|
220 |
|
public function markDoctrineTypeCommented($doctrineType) |
508
|
|
|
{ |
509
|
220 |
|
if ($this->doctrineTypeComments === null) { |
510
|
220 |
|
$this->initializeCommentedDoctrineTypes(); |
511
|
|
|
} |
512
|
|
|
|
513
|
220 |
|
assert(is_array($this->doctrineTypeComments)); |
514
|
|
|
|
515
|
220 |
|
$this->doctrineTypeComments[] = $doctrineType instanceof Type ? $doctrineType->getName() : $doctrineType; |
516
|
220 |
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* Gets the comment to append to a column comment that helps parsing this type in reverse engineering. |
520
|
|
|
* |
521
|
|
|
* @return string |
522
|
|
|
*/ |
523
|
724 |
|
public function getDoctrineTypeComment(Type $doctrineType) |
524
|
|
|
{ |
525
|
724 |
|
return '(DC2Type:' . $doctrineType->getName() . ')'; |
526
|
|
|
} |
527
|
|
|
|
528
|
|
|
/** |
529
|
|
|
* Gets the comment of a passed column modified by potential doctrine type comment hints. |
530
|
|
|
* |
531
|
|
|
* @return string|null |
532
|
|
|
*/ |
533
|
8865 |
|
protected function getColumnComment(Column $column) |
534
|
|
|
{ |
535
|
8865 |
|
$comment = $column->getComment(); |
536
|
|
|
|
537
|
8865 |
|
if ($this->isCommentedDoctrineType($column->getType())) { |
538
|
724 |
|
$comment .= $this->getDoctrineTypeComment($column->getType()); |
539
|
|
|
} |
540
|
|
|
|
541
|
8865 |
|
return $comment; |
542
|
|
|
} |
543
|
|
|
|
544
|
|
|
/** |
545
|
|
|
* Gets the character used for identifier quoting. |
546
|
|
|
* |
547
|
|
|
* @return string |
548
|
|
|
*/ |
549
|
3825 |
|
public function getIdentifierQuoteCharacter() |
550
|
|
|
{ |
551
|
3825 |
|
return '"'; |
552
|
|
|
} |
553
|
|
|
|
554
|
|
|
/** |
555
|
|
|
* Gets the string portion that starts an SQL comment. |
556
|
|
|
* |
557
|
|
|
* @return string |
558
|
|
|
*/ |
559
|
|
|
public function getSqlCommentStartString() |
560
|
|
|
{ |
561
|
|
|
return '--'; |
562
|
|
|
} |
563
|
|
|
|
564
|
|
|
/** |
565
|
|
|
* Gets the string portion that ends an SQL comment. |
566
|
|
|
* |
567
|
|
|
* @return string |
568
|
|
|
*/ |
569
|
|
|
public function getSqlCommentEndString() |
570
|
|
|
{ |
571
|
|
|
return "\n"; |
572
|
|
|
} |
573
|
|
|
|
574
|
|
|
/** |
575
|
|
|
* Gets the maximum length of a char field. |
576
|
|
|
*/ |
577
|
665 |
|
public function getCharMaxLength() : int |
578
|
|
|
{ |
579
|
665 |
|
return $this->getVarcharMaxLength(); |
580
|
|
|
} |
581
|
|
|
|
582
|
|
|
/** |
583
|
|
|
* Gets the maximum length of a varchar field. |
584
|
|
|
* |
585
|
|
|
* @return int |
586
|
|
|
*/ |
587
|
1831 |
|
public function getVarcharMaxLength() |
588
|
|
|
{ |
589
|
1831 |
|
return 4000; |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* Gets the default length of a varchar field. |
594
|
|
|
* |
595
|
|
|
* @return int |
596
|
|
|
*/ |
597
|
919 |
|
public function getVarcharDefaultLength() |
598
|
|
|
{ |
599
|
919 |
|
return 255; |
600
|
|
|
} |
601
|
|
|
|
602
|
|
|
/** |
603
|
|
|
* Gets the maximum length of a binary field. |
604
|
|
|
* |
605
|
|
|
* @return int |
606
|
|
|
*/ |
607
|
|
|
public function getBinaryMaxLength() |
608
|
|
|
{ |
609
|
|
|
return 4000; |
610
|
|
|
} |
611
|
|
|
|
612
|
|
|
/** |
613
|
|
|
* Gets the default length of a binary field. |
614
|
|
|
* |
615
|
|
|
* @return int |
616
|
|
|
*/ |
617
|
235 |
|
public function getBinaryDefaultLength() |
618
|
|
|
{ |
619
|
235 |
|
return 255; |
620
|
|
|
} |
621
|
|
|
|
622
|
|
|
/** |
623
|
|
|
* Gets all SQL wildcard characters of the platform. |
624
|
|
|
* |
625
|
|
|
* @return string[] |
626
|
|
|
*/ |
627
|
|
|
public function getWildcards() |
628
|
|
|
{ |
629
|
|
|
return ['%', '_']; |
630
|
|
|
} |
631
|
|
|
|
632
|
|
|
/** |
633
|
|
|
* Returns the regular expression operator. |
634
|
|
|
* |
635
|
|
|
* @return string |
636
|
|
|
* |
637
|
|
|
* @throws DBALException If not supported on this platform. |
638
|
|
|
*/ |
639
|
44 |
|
public function getRegexpExpression() |
640
|
|
|
{ |
641
|
44 |
|
throw DBALException::notSupported(__METHOD__); |
642
|
|
|
} |
643
|
|
|
|
644
|
|
|
/** |
645
|
|
|
* Returns the global unique identifier expression. |
646
|
|
|
* |
647
|
|
|
* @deprecated Use application-generated UUIDs instead |
648
|
|
|
* |
649
|
|
|
* @return string |
650
|
|
|
* |
651
|
|
|
* @throws DBALException If not supported on this platform. |
652
|
|
|
*/ |
653
|
|
|
public function getGuidExpression() |
654
|
|
|
{ |
655
|
|
|
throw DBALException::notSupported(__METHOD__); |
656
|
|
|
} |
657
|
|
|
|
658
|
|
|
/** |
659
|
|
|
* Returns the SQL snippet to get the average value of a column. |
660
|
|
|
* |
661
|
|
|
* @param string $column The column to use. |
662
|
|
|
* |
663
|
|
|
* @return string Generated SQL including an AVG aggregate function. |
664
|
|
|
*/ |
665
|
|
|
public function getAvgExpression($column) |
666
|
|
|
{ |
667
|
|
|
return 'AVG(' . $column . ')'; |
668
|
|
|
} |
669
|
|
|
|
670
|
|
|
/** |
671
|
|
|
* Returns the SQL snippet to get the number of rows (without a NULL value) of a column. |
672
|
|
|
* |
673
|
|
|
* If a '*' is used instead of a column the number of selected rows is returned. |
674
|
|
|
* |
675
|
|
|
* @param string|int $column The column to use. |
676
|
|
|
* |
677
|
|
|
* @return string Generated SQL including a COUNT aggregate function. |
678
|
|
|
*/ |
679
|
|
|
public function getCountExpression($column) |
680
|
|
|
{ |
681
|
|
|
return 'COUNT(' . $column . ')'; |
682
|
|
|
} |
683
|
|
|
|
684
|
|
|
/** |
685
|
|
|
* Returns the SQL snippet to get the highest value of a column. |
686
|
|
|
* |
687
|
|
|
* @param string $column The column to use. |
688
|
|
|
* |
689
|
|
|
* @return string Generated SQL including a MAX aggregate function. |
690
|
|
|
*/ |
691
|
|
|
public function getMaxExpression($column) |
692
|
|
|
{ |
693
|
|
|
return 'MAX(' . $column . ')'; |
694
|
|
|
} |
695
|
|
|
|
696
|
|
|
/** |
697
|
|
|
* Returns the SQL snippet to get the lowest value of a column. |
698
|
|
|
* |
699
|
|
|
* @param string $column The column to use. |
700
|
|
|
* |
701
|
|
|
* @return string Generated SQL including a MIN aggregate function. |
702
|
|
|
*/ |
703
|
|
|
public function getMinExpression($column) |
704
|
|
|
{ |
705
|
|
|
return 'MIN(' . $column . ')'; |
706
|
|
|
} |
707
|
|
|
|
708
|
|
|
/** |
709
|
|
|
* Returns the SQL snippet to get the total sum of a column. |
710
|
|
|
* |
711
|
|
|
* @param string $column The column to use. |
712
|
|
|
* |
713
|
|
|
* @return string Generated SQL including a SUM aggregate function. |
714
|
|
|
*/ |
715
|
|
|
public function getSumExpression($column) |
716
|
|
|
{ |
717
|
|
|
return 'SUM(' . $column . ')'; |
718
|
|
|
} |
719
|
|
|
|
720
|
|
|
// scalar functions |
721
|
|
|
|
722
|
|
|
/** |
723
|
|
|
* Returns the SQL snippet to get the md5 sum of a field. |
724
|
|
|
* |
725
|
|
|
* Note: Not SQL92, but common functionality. |
726
|
|
|
* |
727
|
|
|
* @param string $column |
728
|
|
|
* |
729
|
|
|
* @return string |
730
|
|
|
*/ |
731
|
|
|
public function getMd5Expression($column) |
732
|
|
|
{ |
733
|
|
|
return 'MD5(' . $column . ')'; |
734
|
|
|
} |
735
|
|
|
|
736
|
|
|
/** |
737
|
|
|
* Returns the SQL snippet to get the length of a text field. |
738
|
|
|
* |
739
|
|
|
* @param string $column |
740
|
|
|
* |
741
|
|
|
* @return string |
742
|
|
|
*/ |
743
|
|
|
public function getLengthExpression($column) |
744
|
|
|
{ |
745
|
|
|
return 'LENGTH(' . $column . ')'; |
746
|
|
|
} |
747
|
|
|
|
748
|
|
|
/** |
749
|
|
|
* Returns the SQL snippet to get the squared value of a column. |
750
|
|
|
* |
751
|
|
|
* @param string $column The column to use. |
752
|
|
|
* |
753
|
|
|
* @return string Generated SQL including an SQRT aggregate function. |
754
|
|
|
*/ |
755
|
|
|
public function getSqrtExpression($column) |
756
|
|
|
{ |
757
|
|
|
return 'SQRT(' . $column . ')'; |
758
|
|
|
} |
759
|
|
|
|
760
|
|
|
/** |
761
|
|
|
* Returns the SQL snippet to round a numeric field to the number of decimals specified. |
762
|
|
|
* |
763
|
|
|
* @param string $column |
764
|
|
|
* @param int $decimals |
765
|
|
|
* |
766
|
|
|
* @return string |
767
|
|
|
*/ |
768
|
|
|
public function getRoundExpression($column, $decimals = 0) |
769
|
|
|
{ |
770
|
|
|
return 'ROUND(' . $column . ', ' . $decimals . ')'; |
771
|
|
|
} |
772
|
|
|
|
773
|
|
|
/** |
774
|
|
|
* Returns the SQL snippet to get the remainder of the division operation $expression1 / $expression2. |
775
|
|
|
* |
776
|
|
|
* @param string $expression1 |
777
|
|
|
* @param string $expression2 |
778
|
|
|
* |
779
|
|
|
* @return string |
780
|
|
|
*/ |
781
|
|
|
public function getModExpression($expression1, $expression2) |
782
|
|
|
{ |
783
|
|
|
return 'MOD(' . $expression1 . ', ' . $expression2 . ')'; |
784
|
|
|
} |
785
|
|
|
|
786
|
|
|
/** |
787
|
|
|
* Returns the SQL snippet to trim a string. |
788
|
|
|
* |
789
|
|
|
* @param string $str The expression to apply the trim to. |
790
|
|
|
* @param int $mode The position of the trim (leading/trailing/both). |
791
|
|
|
* @param string|bool $char The char to trim, has to be quoted already. Defaults to space. |
792
|
|
|
* |
793
|
|
|
* @return string |
794
|
|
|
*/ |
795
|
684 |
|
public function getTrimExpression($str, $mode = TrimMode::UNSPECIFIED, $char = false) |
796
|
|
|
{ |
797
|
684 |
|
$expression = ''; |
798
|
|
|
|
799
|
684 |
|
switch ($mode) { |
800
|
|
|
case TrimMode::LEADING: |
801
|
171 |
|
$expression = 'LEADING '; |
802
|
171 |
|
break; |
803
|
|
|
|
804
|
|
|
case TrimMode::TRAILING: |
805
|
171 |
|
$expression = 'TRAILING '; |
806
|
171 |
|
break; |
807
|
|
|
|
808
|
|
|
case TrimMode::BOTH: |
809
|
171 |
|
$expression = 'BOTH '; |
810
|
171 |
|
break; |
811
|
|
|
} |
812
|
|
|
|
813
|
684 |
|
if ($char !== false) { |
814
|
532 |
|
$expression .= $char . ' '; |
|
|
|
|
815
|
|
|
} |
816
|
|
|
|
817
|
684 |
|
if ($mode !== TrimMode::UNSPECIFIED || $char !== false) { |
818
|
646 |
|
$expression .= 'FROM '; |
819
|
|
|
} |
820
|
|
|
|
821
|
684 |
|
return 'TRIM(' . $expression . $str . ')'; |
822
|
|
|
} |
823
|
|
|
|
824
|
|
|
/** |
825
|
|
|
* Returns the SQL snippet to trim trailing space characters from the expression. |
826
|
|
|
* |
827
|
|
|
* @param string $str Literal string or column name. |
828
|
|
|
* |
829
|
|
|
* @return string |
830
|
|
|
*/ |
831
|
22 |
|
public function getRtrimExpression($str) |
832
|
|
|
{ |
833
|
22 |
|
return 'RTRIM(' . $str . ')'; |
834
|
|
|
} |
835
|
|
|
|
836
|
|
|
/** |
837
|
|
|
* Returns the SQL snippet to trim leading space characters from the expression. |
838
|
|
|
* |
839
|
|
|
* @param string $str Literal string or column name. |
840
|
|
|
* |
841
|
|
|
* @return string |
842
|
|
|
*/ |
843
|
22 |
|
public function getLtrimExpression($str) |
844
|
|
|
{ |
845
|
22 |
|
return 'LTRIM(' . $str . ')'; |
846
|
|
|
} |
847
|
|
|
|
848
|
|
|
/** |
849
|
|
|
* Returns the SQL snippet to change all characters from the expression to uppercase, |
850
|
|
|
* according to the current character set mapping. |
851
|
|
|
* |
852
|
|
|
* @param string $str Literal string or column name. |
853
|
|
|
* |
854
|
|
|
* @return string |
855
|
|
|
*/ |
856
|
|
|
public function getUpperExpression($str) |
857
|
|
|
{ |
858
|
|
|
return 'UPPER(' . $str . ')'; |
859
|
|
|
} |
860
|
|
|
|
861
|
|
|
/** |
862
|
|
|
* Returns the SQL snippet to change all characters from the expression to lowercase, |
863
|
|
|
* according to the current character set mapping. |
864
|
|
|
* |
865
|
|
|
* @param string $str Literal string or column name. |
866
|
|
|
* |
867
|
|
|
* @return string |
868
|
|
|
*/ |
869
|
|
|
public function getLowerExpression($str) |
870
|
|
|
{ |
871
|
|
|
return 'LOWER(' . $str . ')'; |
872
|
|
|
} |
873
|
|
|
|
874
|
|
|
/** |
875
|
|
|
* Returns the SQL snippet to get the position of the first occurrence of substring $substr in string $str. |
876
|
|
|
* |
877
|
|
|
* @param string $str Literal string. |
878
|
|
|
* @param string $substr Literal string to find. |
879
|
|
|
* @param int|false $startPos Position to start at, beginning of string by default. |
880
|
|
|
* |
881
|
|
|
* @return string |
882
|
|
|
* |
883
|
|
|
* @throws DBALException If not supported on this platform. |
884
|
|
|
*/ |
885
|
|
|
public function getLocateExpression($str, $substr, $startPos = false) |
|
|
|
|
886
|
|
|
{ |
887
|
|
|
throw DBALException::notSupported(__METHOD__); |
888
|
|
|
} |
889
|
|
|
|
890
|
|
|
/** |
891
|
|
|
* Returns the SQL snippet to get the current system date. |
892
|
|
|
* |
893
|
|
|
* @return string |
894
|
|
|
*/ |
895
|
|
|
public function getNowExpression() |
896
|
|
|
{ |
897
|
|
|
return 'NOW()'; |
898
|
|
|
} |
899
|
|
|
|
900
|
|
|
/** |
901
|
|
|
* Returns a SQL snippet to get a substring inside an SQL statement. |
902
|
|
|
* |
903
|
|
|
* Note: Not SQL92, but common functionality. |
904
|
|
|
* |
905
|
|
|
* SQLite only supports the 2 parameter variant of this function. |
906
|
|
|
* |
907
|
|
|
* @param string $value An sql string literal or column name/alias. |
908
|
|
|
* @param int $from Where to start the substring portion. |
909
|
|
|
* @param int|null $length The substring portion length. |
910
|
|
|
* |
911
|
|
|
* @return string |
912
|
|
|
*/ |
913
|
|
|
public function getSubstringExpression($value, $from, $length = null) |
914
|
|
|
{ |
915
|
|
|
if ($length === null) { |
916
|
|
|
return 'SUBSTRING(' . $value . ' FROM ' . $from . ')'; |
917
|
|
|
} |
918
|
|
|
|
919
|
|
|
return 'SUBSTRING(' . $value . ' FROM ' . $from . ' FOR ' . $length . ')'; |
920
|
|
|
} |
921
|
|
|
|
922
|
|
|
/** |
923
|
|
|
* Returns a SQL snippet to concatenate the given expressions. |
924
|
|
|
* |
925
|
|
|
* Accepts an arbitrary number of string parameters. Each parameter must contain an expression. |
926
|
|
|
* |
927
|
|
|
* @return string |
928
|
|
|
*/ |
929
|
66 |
|
public function getConcatExpression() |
930
|
|
|
{ |
931
|
66 |
|
return implode(' || ', func_get_args()); |
932
|
|
|
} |
933
|
|
|
|
934
|
|
|
/** |
935
|
|
|
* Returns the SQL for a logical not. |
936
|
|
|
* |
937
|
|
|
* Example: |
938
|
|
|
* <code> |
939
|
|
|
* $q = new Doctrine_Query(); |
940
|
|
|
* $e = $q->expr; |
941
|
|
|
* $q->select('*')->from('table') |
942
|
|
|
* ->where($e->eq('id', $e->not('null')); |
943
|
|
|
* </code> |
944
|
|
|
* |
945
|
|
|
* @param string $expression |
946
|
|
|
* |
947
|
|
|
* @return string The logical expression. |
948
|
|
|
*/ |
949
|
|
|
public function getNotExpression($expression) |
950
|
|
|
{ |
951
|
|
|
return 'NOT(' . $expression . ')'; |
952
|
|
|
} |
953
|
|
|
|
954
|
|
|
/** |
955
|
|
|
* Returns the SQL that checks if an expression is null. |
956
|
|
|
* |
957
|
|
|
* @param string $expression The expression that should be compared to null. |
958
|
|
|
* |
959
|
|
|
* @return string The logical expression. |
960
|
|
|
*/ |
961
|
88 |
|
public function getIsNullExpression($expression) |
962
|
|
|
{ |
963
|
88 |
|
return $expression . ' IS NULL'; |
964
|
|
|
} |
965
|
|
|
|
966
|
|
|
/** |
967
|
|
|
* Returns the SQL that checks if an expression is not null. |
968
|
|
|
* |
969
|
|
|
* @param string $expression The expression that should be compared to null. |
970
|
|
|
* |
971
|
|
|
* @return string The logical expression. |
972
|
|
|
*/ |
973
|
|
|
public function getIsNotNullExpression($expression) |
974
|
|
|
{ |
975
|
|
|
return $expression . ' IS NOT NULL'; |
976
|
|
|
} |
977
|
|
|
|
978
|
|
|
/** |
979
|
|
|
* Returns the SQL that checks if an expression evaluates to a value between two values. |
980
|
|
|
* |
981
|
|
|
* The parameter $expression is checked if it is between $value1 and $value2. |
982
|
|
|
* |
983
|
|
|
* Note: There is a slight difference in the way BETWEEN works on some databases. |
984
|
|
|
* http://www.w3schools.com/sql/sql_between.asp. If you want complete database |
985
|
|
|
* independence you should avoid using between(). |
986
|
|
|
* |
987
|
|
|
* @param string $expression The value to compare to. |
988
|
|
|
* @param string $value1 The lower value to compare with. |
989
|
|
|
* @param string $value2 The higher value to compare with. |
990
|
|
|
* |
991
|
|
|
* @return string The logical expression. |
992
|
|
|
*/ |
993
|
|
|
public function getBetweenExpression($expression, $value1, $value2) |
994
|
|
|
{ |
995
|
|
|
return $expression . ' BETWEEN ' . $value1 . ' AND ' . $value2; |
996
|
|
|
} |
997
|
|
|
|
998
|
|
|
/** |
999
|
|
|
* Returns the SQL to get the arccosine of a value. |
1000
|
|
|
* |
1001
|
|
|
* @param string $value |
1002
|
|
|
* |
1003
|
|
|
* @return string |
1004
|
|
|
*/ |
1005
|
|
|
public function getAcosExpression($value) |
1006
|
|
|
{ |
1007
|
|
|
return 'ACOS(' . $value . ')'; |
1008
|
|
|
} |
1009
|
|
|
|
1010
|
|
|
/** |
1011
|
|
|
* Returns the SQL to get the sine of a value. |
1012
|
|
|
* |
1013
|
|
|
* @param string $value |
1014
|
|
|
* |
1015
|
|
|
* @return string |
1016
|
|
|
*/ |
1017
|
|
|
public function getSinExpression($value) |
1018
|
|
|
{ |
1019
|
|
|
return 'SIN(' . $value . ')'; |
1020
|
|
|
} |
1021
|
|
|
|
1022
|
|
|
/** |
1023
|
|
|
* Returns the SQL to get the PI value. |
1024
|
|
|
* |
1025
|
|
|
* @return string |
1026
|
|
|
*/ |
1027
|
|
|
public function getPiExpression() |
1028
|
|
|
{ |
1029
|
|
|
return 'PI()'; |
1030
|
|
|
} |
1031
|
|
|
|
1032
|
|
|
/** |
1033
|
|
|
* Returns the SQL to get the cosine of a value. |
1034
|
|
|
* |
1035
|
|
|
* @param string $value |
1036
|
|
|
* |
1037
|
|
|
* @return string |
1038
|
|
|
*/ |
1039
|
|
|
public function getCosExpression($value) |
1040
|
|
|
{ |
1041
|
|
|
return 'COS(' . $value . ')'; |
1042
|
|
|
} |
1043
|
|
|
|
1044
|
|
|
/** |
1045
|
|
|
* Returns the SQL to calculate the difference in days between the two passed dates. |
1046
|
|
|
* |
1047
|
|
|
* Computes diff = date1 - date2. |
1048
|
|
|
* |
1049
|
|
|
* @param string $date1 |
1050
|
|
|
* @param string $date2 |
1051
|
|
|
* |
1052
|
|
|
* @return string |
1053
|
|
|
* |
1054
|
|
|
* @throws DBALException If not supported on this platform. |
1055
|
|
|
*/ |
1056
|
|
|
public function getDateDiffExpression($date1, $date2) |
|
|
|
|
1057
|
|
|
{ |
1058
|
|
|
throw DBALException::notSupported(__METHOD__); |
1059
|
|
|
} |
1060
|
|
|
|
1061
|
|
|
/** |
1062
|
|
|
* Returns the SQL to add the number of given seconds to a date. |
1063
|
|
|
* |
1064
|
|
|
* @param string $date |
1065
|
|
|
* @param int $seconds |
1066
|
|
|
* |
1067
|
|
|
* @return string |
1068
|
|
|
* |
1069
|
|
|
* @throws DBALException If not supported on this platform. |
1070
|
|
|
*/ |
1071
|
66 |
|
public function getDateAddSecondsExpression($date, $seconds) |
1072
|
|
|
{ |
1073
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '+', $seconds, DateIntervalUnit::SECOND); |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
/** |
1077
|
|
|
* Returns the SQL to subtract the number of given seconds from a date. |
1078
|
|
|
* |
1079
|
|
|
* @param string $date |
1080
|
|
|
* @param int $seconds |
1081
|
|
|
* |
1082
|
|
|
* @return string |
1083
|
|
|
* |
1084
|
|
|
* @throws DBALException If not supported on this platform. |
1085
|
|
|
*/ |
1086
|
66 |
|
public function getDateSubSecondsExpression($date, $seconds) |
1087
|
|
|
{ |
1088
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '-', $seconds, DateIntervalUnit::SECOND); |
1089
|
|
|
} |
1090
|
|
|
|
1091
|
|
|
/** |
1092
|
|
|
* Returns the SQL to add the number of given minutes to a date. |
1093
|
|
|
* |
1094
|
|
|
* @param string $date |
1095
|
|
|
* @param int $minutes |
1096
|
|
|
* |
1097
|
|
|
* @return string |
1098
|
|
|
* |
1099
|
|
|
* @throws DBALException If not supported on this platform. |
1100
|
|
|
*/ |
1101
|
66 |
|
public function getDateAddMinutesExpression($date, $minutes) |
1102
|
|
|
{ |
1103
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '+', $minutes, DateIntervalUnit::MINUTE); |
1104
|
|
|
} |
1105
|
|
|
|
1106
|
|
|
/** |
1107
|
|
|
* Returns the SQL to subtract the number of given minutes from a date. |
1108
|
|
|
* |
1109
|
|
|
* @param string $date |
1110
|
|
|
* @param int $minutes |
1111
|
|
|
* |
1112
|
|
|
* @return string |
1113
|
|
|
* |
1114
|
|
|
* @throws DBALException If not supported on this platform. |
1115
|
|
|
*/ |
1116
|
66 |
|
public function getDateSubMinutesExpression($date, $minutes) |
1117
|
|
|
{ |
1118
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '-', $minutes, DateIntervalUnit::MINUTE); |
1119
|
|
|
} |
1120
|
|
|
|
1121
|
|
|
/** |
1122
|
|
|
* Returns the SQL to add the number of given hours to a date. |
1123
|
|
|
* |
1124
|
|
|
* @param string $date |
1125
|
|
|
* @param int $hours |
1126
|
|
|
* |
1127
|
|
|
* @return string |
1128
|
|
|
* |
1129
|
|
|
* @throws DBALException If not supported on this platform. |
1130
|
|
|
*/ |
1131
|
66 |
|
public function getDateAddHourExpression($date, $hours) |
1132
|
|
|
{ |
1133
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '+', $hours, DateIntervalUnit::HOUR); |
1134
|
|
|
} |
1135
|
|
|
|
1136
|
|
|
/** |
1137
|
|
|
* Returns the SQL to subtract the number of given hours to a date. |
1138
|
|
|
* |
1139
|
|
|
* @param string $date |
1140
|
|
|
* @param int $hours |
1141
|
|
|
* |
1142
|
|
|
* @return string |
1143
|
|
|
* |
1144
|
|
|
* @throws DBALException If not supported on this platform. |
1145
|
|
|
*/ |
1146
|
66 |
|
public function getDateSubHourExpression($date, $hours) |
1147
|
|
|
{ |
1148
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '-', $hours, DateIntervalUnit::HOUR); |
1149
|
|
|
} |
1150
|
|
|
|
1151
|
|
|
/** |
1152
|
|
|
* Returns the SQL to add the number of given days to a date. |
1153
|
|
|
* |
1154
|
|
|
* @param string $date |
1155
|
|
|
* @param int $days |
1156
|
|
|
* |
1157
|
|
|
* @return string |
1158
|
|
|
* |
1159
|
|
|
* @throws DBALException If not supported on this platform. |
1160
|
|
|
*/ |
1161
|
110 |
|
public function getDateAddDaysExpression($date, $days) |
1162
|
|
|
{ |
1163
|
110 |
|
return $this->getDateArithmeticIntervalExpression($date, '+', $days, DateIntervalUnit::DAY); |
1164
|
|
|
} |
1165
|
|
|
|
1166
|
|
|
/** |
1167
|
|
|
* Returns the SQL to subtract the number of given days to a date. |
1168
|
|
|
* |
1169
|
|
|
* @param string $date |
1170
|
|
|
* @param int $days |
1171
|
|
|
* |
1172
|
|
|
* @return string |
1173
|
|
|
* |
1174
|
|
|
* @throws DBALException If not supported on this platform. |
1175
|
|
|
*/ |
1176
|
67 |
|
public function getDateSubDaysExpression($date, $days) |
1177
|
|
|
{ |
1178
|
67 |
|
return $this->getDateArithmeticIntervalExpression($date, '-', $days, DateIntervalUnit::DAY); |
1179
|
|
|
} |
1180
|
|
|
|
1181
|
|
|
/** |
1182
|
|
|
* Returns the SQL to add the number of given weeks to a date. |
1183
|
|
|
* |
1184
|
|
|
* @param string $date |
1185
|
|
|
* @param int $weeks |
1186
|
|
|
* |
1187
|
|
|
* @return string |
1188
|
|
|
* |
1189
|
|
|
* @throws DBALException If not supported on this platform. |
1190
|
|
|
*/ |
1191
|
66 |
|
public function getDateAddWeeksExpression($date, $weeks) |
1192
|
|
|
{ |
1193
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '+', $weeks, DateIntervalUnit::WEEK); |
1194
|
|
|
} |
1195
|
|
|
|
1196
|
|
|
/** |
1197
|
|
|
* Returns the SQL to subtract the number of given weeks from a date. |
1198
|
|
|
* |
1199
|
|
|
* @param string $date |
1200
|
|
|
* @param int $weeks |
1201
|
|
|
* |
1202
|
|
|
* @return string |
1203
|
|
|
* |
1204
|
|
|
* @throws DBALException If not supported on this platform. |
1205
|
|
|
*/ |
1206
|
66 |
|
public function getDateSubWeeksExpression($date, $weeks) |
1207
|
|
|
{ |
1208
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '-', $weeks, DateIntervalUnit::WEEK); |
1209
|
|
|
} |
1210
|
|
|
|
1211
|
|
|
/** |
1212
|
|
|
* Returns the SQL to add the number of given months to a date. |
1213
|
|
|
* |
1214
|
|
|
* @param string $date |
1215
|
|
|
* @param int $months |
1216
|
|
|
* |
1217
|
|
|
* @return string |
1218
|
|
|
* |
1219
|
|
|
* @throws DBALException If not supported on this platform. |
1220
|
|
|
*/ |
1221
|
66 |
|
public function getDateAddMonthExpression($date, $months) |
1222
|
|
|
{ |
1223
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '+', $months, DateIntervalUnit::MONTH); |
1224
|
|
|
} |
1225
|
|
|
|
1226
|
|
|
/** |
1227
|
|
|
* Returns the SQL to subtract the number of given months to a date. |
1228
|
|
|
* |
1229
|
|
|
* @param string $date |
1230
|
|
|
* @param int $months |
1231
|
|
|
* |
1232
|
|
|
* @return string |
1233
|
|
|
* |
1234
|
|
|
* @throws DBALException If not supported on this platform. |
1235
|
|
|
*/ |
1236
|
66 |
|
public function getDateSubMonthExpression($date, $months) |
1237
|
|
|
{ |
1238
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '-', $months, DateIntervalUnit::MONTH); |
1239
|
|
|
} |
1240
|
|
|
|
1241
|
|
|
/** |
1242
|
|
|
* Returns the SQL to add the number of given quarters to a date. |
1243
|
|
|
* |
1244
|
|
|
* @param string $date |
1245
|
|
|
* @param int $quarters |
1246
|
|
|
* |
1247
|
|
|
* @return string |
1248
|
|
|
* |
1249
|
|
|
* @throws DBALException If not supported on this platform. |
1250
|
|
|
*/ |
1251
|
66 |
|
public function getDateAddQuartersExpression($date, $quarters) |
1252
|
|
|
{ |
1253
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '+', $quarters, DateIntervalUnit::QUARTER); |
1254
|
|
|
} |
1255
|
|
|
|
1256
|
|
|
/** |
1257
|
|
|
* Returns the SQL to subtract the number of given quarters from a date. |
1258
|
|
|
* |
1259
|
|
|
* @param string $date |
1260
|
|
|
* @param int $quarters |
1261
|
|
|
* |
1262
|
|
|
* @return string |
1263
|
|
|
* |
1264
|
|
|
* @throws DBALException If not supported on this platform. |
1265
|
|
|
*/ |
1266
|
66 |
|
public function getDateSubQuartersExpression($date, $quarters) |
1267
|
|
|
{ |
1268
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '-', $quarters, DateIntervalUnit::QUARTER); |
1269
|
|
|
} |
1270
|
|
|
|
1271
|
|
|
/** |
1272
|
|
|
* Returns the SQL to add the number of given years to a date. |
1273
|
|
|
* |
1274
|
|
|
* @param string $date |
1275
|
|
|
* @param int $years |
1276
|
|
|
* |
1277
|
|
|
* @return string |
1278
|
|
|
* |
1279
|
|
|
* @throws DBALException If not supported on this platform. |
1280
|
|
|
*/ |
1281
|
66 |
|
public function getDateAddYearsExpression($date, $years) |
1282
|
|
|
{ |
1283
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '+', $years, DateIntervalUnit::YEAR); |
1284
|
|
|
} |
1285
|
|
|
|
1286
|
|
|
/** |
1287
|
|
|
* Returns the SQL to subtract the number of given years from a date. |
1288
|
|
|
* |
1289
|
|
|
* @param string $date |
1290
|
|
|
* @param int $years |
1291
|
|
|
* |
1292
|
|
|
* @return string |
1293
|
|
|
* |
1294
|
|
|
* @throws DBALException If not supported on this platform. |
1295
|
|
|
*/ |
1296
|
66 |
|
public function getDateSubYearsExpression($date, $years) |
1297
|
|
|
{ |
1298
|
66 |
|
return $this->getDateArithmeticIntervalExpression($date, '-', $years, DateIntervalUnit::YEAR); |
1299
|
|
|
} |
1300
|
|
|
|
1301
|
|
|
/** |
1302
|
|
|
* Returns the SQL for a date arithmetic expression. |
1303
|
|
|
* |
1304
|
|
|
* @param string $date The column or literal representing a date to perform the arithmetic operation on. |
1305
|
|
|
* @param string $operator The arithmetic operator (+ or -). |
1306
|
|
|
* @param int $interval The interval that shall be calculated into the date. |
1307
|
|
|
* @param string $unit The unit of the interval that shall be calculated into the date. |
1308
|
|
|
* One of the DATE_INTERVAL_UNIT_* constants. |
1309
|
|
|
* |
1310
|
|
|
* @return string |
1311
|
|
|
* |
1312
|
|
|
* @throws DBALException If not supported on this platform. |
1313
|
|
|
*/ |
1314
|
|
|
protected function getDateArithmeticIntervalExpression($date, $operator, $interval, $unit) |
|
|
|
|
1315
|
|
|
{ |
1316
|
|
|
throw DBALException::notSupported(__METHOD__); |
1317
|
|
|
} |
1318
|
|
|
|
1319
|
|
|
/** |
1320
|
|
|
* Returns the SQL bit AND comparison expression. |
1321
|
|
|
* |
1322
|
|
|
* @param string $value1 |
1323
|
|
|
* @param string $value2 |
1324
|
|
|
* |
1325
|
|
|
* @return string |
1326
|
|
|
*/ |
1327
|
196 |
|
public function getBitAndComparisonExpression($value1, $value2) |
1328
|
|
|
{ |
1329
|
196 |
|
return '(' . $value1 . ' & ' . $value2 . ')'; |
1330
|
|
|
} |
1331
|
|
|
|
1332
|
|
|
/** |
1333
|
|
|
* Returns the SQL bit OR comparison expression. |
1334
|
|
|
* |
1335
|
|
|
* @param string $value1 |
1336
|
|
|
* @param string $value2 |
1337
|
|
|
* |
1338
|
|
|
* @return string |
1339
|
|
|
*/ |
1340
|
196 |
|
public function getBitOrComparisonExpression($value1, $value2) |
1341
|
|
|
{ |
1342
|
196 |
|
return '(' . $value1 . ' | ' . $value2 . ')'; |
1343
|
|
|
} |
1344
|
|
|
|
1345
|
|
|
/** |
1346
|
|
|
* Returns the FOR UPDATE expression. |
1347
|
|
|
* |
1348
|
|
|
* @return string |
1349
|
|
|
*/ |
1350
|
36 |
|
public function getForUpdateSQL() |
1351
|
|
|
{ |
1352
|
36 |
|
return 'FOR UPDATE'; |
1353
|
|
|
} |
1354
|
|
|
|
1355
|
|
|
/** |
1356
|
|
|
* Honors that some SQL vendors such as MsSql use table hints for locking instead of the ANSI SQL FOR UPDATE specification. |
1357
|
|
|
* |
1358
|
|
|
* @param string $fromClause The FROM clause to append the hint for the given lock mode to. |
1359
|
|
|
* @param int|null $lockMode One of the Doctrine\DBAL\LockMode::* constants. If null is given, nothing will |
1360
|
|
|
* be appended to the FROM clause. |
1361
|
|
|
* |
1362
|
|
|
* @return string |
1363
|
|
|
*/ |
1364
|
38 |
|
public function appendLockHint($fromClause, $lockMode) |
|
|
|
|
1365
|
|
|
{ |
1366
|
38 |
|
return $fromClause; |
1367
|
|
|
} |
1368
|
|
|
|
1369
|
|
|
/** |
1370
|
|
|
* Returns the SQL snippet to append to any SELECT statement which locks rows in shared read lock. |
1371
|
|
|
* |
1372
|
|
|
* This defaults to the ANSI SQL "FOR UPDATE", which is an exclusive lock (Write). Some database |
1373
|
|
|
* vendors allow to lighten this constraint up to be a real read lock. |
1374
|
|
|
* |
1375
|
|
|
* @return string |
1376
|
|
|
*/ |
1377
|
|
|
public function getReadLockSQL() |
1378
|
|
|
{ |
1379
|
|
|
return $this->getForUpdateSQL(); |
1380
|
|
|
} |
1381
|
|
|
|
1382
|
|
|
/** |
1383
|
|
|
* Returns the SQL snippet to append to any SELECT statement which obtains an exclusive lock on the rows. |
1384
|
|
|
* |
1385
|
|
|
* The semantics of this lock mode should equal the SELECT .. FOR UPDATE of the ANSI SQL standard. |
1386
|
|
|
* |
1387
|
|
|
* @return string |
1388
|
|
|
*/ |
1389
|
42 |
|
public function getWriteLockSQL() |
1390
|
|
|
{ |
1391
|
42 |
|
return $this->getForUpdateSQL(); |
1392
|
|
|
} |
1393
|
|
|
|
1394
|
|
|
/** |
1395
|
|
|
* Returns the SQL snippet to drop an existing database. |
1396
|
|
|
* |
1397
|
|
|
* @param string $database The name of the database that should be dropped. |
1398
|
|
|
* |
1399
|
|
|
* @return string |
1400
|
|
|
*/ |
1401
|
54 |
|
public function getDropDatabaseSQL($database) |
1402
|
|
|
{ |
1403
|
54 |
|
return 'DROP DATABASE ' . $database; |
1404
|
|
|
} |
1405
|
|
|
|
1406
|
|
|
/** |
1407
|
|
|
* Returns the SQL snippet to drop an existing table. |
1408
|
|
|
* |
1409
|
|
|
* @param Table|string $table |
1410
|
|
|
* |
1411
|
|
|
* @return string |
1412
|
|
|
* |
1413
|
|
|
* @throws InvalidArgumentException |
1414
|
|
|
*/ |
1415
|
3784 |
|
public function getDropTableSQL($table) |
1416
|
|
|
{ |
1417
|
3784 |
|
$tableArg = $table; |
1418
|
|
|
|
1419
|
3784 |
|
if ($table instanceof Table) { |
1420
|
325 |
|
$table = $table->getQuotedName($this); |
1421
|
|
|
} |
1422
|
|
|
|
1423
|
3784 |
|
if (! is_string($table)) { |
|
|
|
|
1424
|
|
|
throw new InvalidArgumentException('getDropTableSQL() expects $table parameter to be string or \Doctrine\DBAL\Schema\Table.'); |
1425
|
|
|
} |
1426
|
|
|
|
1427
|
3784 |
|
if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaDropTable)) { |
1428
|
220 |
|
$eventArgs = new SchemaDropTableEventArgs($tableArg, $this); |
1429
|
220 |
|
$this->_eventManager->dispatchEvent(Events::onSchemaDropTable, $eventArgs); |
1430
|
|
|
|
1431
|
220 |
|
if ($eventArgs->isDefaultPrevented()) { |
1432
|
|
|
$sql = $eventArgs->getSql(); |
1433
|
|
|
|
1434
|
|
|
if ($sql === null) { |
1435
|
|
|
throw new UnexpectedValueException('Default implementation of DROP TABLE was overridden with NULL'); |
1436
|
|
|
} |
1437
|
|
|
|
1438
|
|
|
return $sql; |
1439
|
|
|
} |
1440
|
|
|
} |
1441
|
|
|
|
1442
|
3784 |
|
return 'DROP TABLE ' . $table; |
1443
|
|
|
} |
1444
|
|
|
|
1445
|
|
|
/** |
1446
|
|
|
* Returns the SQL to safely drop a temporary table WITHOUT implicitly committing an open transaction. |
1447
|
|
|
* |
1448
|
|
|
* @param Table|string $table |
1449
|
|
|
* |
1450
|
|
|
* @return string |
1451
|
|
|
*/ |
1452
|
18 |
|
public function getDropTemporaryTableSQL($table) |
1453
|
|
|
{ |
1454
|
18 |
|
return $this->getDropTableSQL($table); |
1455
|
|
|
} |
1456
|
|
|
|
1457
|
|
|
/** |
1458
|
|
|
* Returns the SQL to drop an index from a table. |
1459
|
|
|
* |
1460
|
|
|
* @param Index|string $index |
1461
|
|
|
* @param Table|string $table |
1462
|
|
|
* |
1463
|
|
|
* @return string |
1464
|
|
|
* |
1465
|
|
|
* @throws InvalidArgumentException |
1466
|
|
|
*/ |
1467
|
135 |
|
public function getDropIndexSQL($index, $table = null) |
1468
|
|
|
{ |
1469
|
135 |
|
if ($index instanceof Index) { |
1470
|
127 |
|
$index = $index->getQuotedName($this); |
1471
|
8 |
|
} elseif (! is_string($index)) { |
|
|
|
|
1472
|
|
|
throw new InvalidArgumentException('AbstractPlatform::getDropIndexSQL() expects $index parameter to be string or \Doctrine\DBAL\Schema\Index.'); |
1473
|
|
|
} |
1474
|
|
|
|
1475
|
135 |
|
return 'DROP INDEX ' . $index; |
1476
|
|
|
} |
1477
|
|
|
|
1478
|
|
|
/** |
1479
|
|
|
* Returns the SQL to drop a constraint. |
1480
|
|
|
* |
1481
|
|
|
* @param Constraint|string $constraint |
1482
|
|
|
* @param Table|string $table |
1483
|
|
|
* |
1484
|
|
|
* @return string |
1485
|
|
|
*/ |
1486
|
543 |
|
public function getDropConstraintSQL($constraint, $table) |
1487
|
|
|
{ |
1488
|
543 |
|
if (! $constraint instanceof Constraint) { |
1489
|
450 |
|
$constraint = new Identifier($constraint); |
1490
|
|
|
} |
1491
|
|
|
|
1492
|
543 |
|
if (! $table instanceof Table) { |
1493
|
543 |
|
$table = new Identifier($table); |
1494
|
|
|
} |
1495
|
|
|
|
1496
|
543 |
|
$constraint = $constraint->getQuotedName($this); |
1497
|
543 |
|
$table = $table->getQuotedName($this); |
1498
|
|
|
|
1499
|
543 |
|
return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $constraint; |
1500
|
|
|
} |
1501
|
|
|
|
1502
|
|
|
/** |
1503
|
|
|
* Returns the SQL to drop a foreign key. |
1504
|
|
|
* |
1505
|
|
|
* @param ForeignKeyConstraint|string $foreignKey |
1506
|
|
|
* @param Table|string $table |
1507
|
|
|
* |
1508
|
|
|
* @return string |
1509
|
|
|
*/ |
1510
|
351 |
|
public function getDropForeignKeySQL($foreignKey, $table) |
1511
|
|
|
{ |
1512
|
351 |
|
if (! $foreignKey instanceof ForeignKeyConstraint) { |
1513
|
110 |
|
$foreignKey = new Identifier($foreignKey); |
1514
|
|
|
} |
1515
|
|
|
|
1516
|
351 |
|
if (! $table instanceof Table) { |
1517
|
351 |
|
$table = new Identifier($table); |
1518
|
|
|
} |
1519
|
|
|
|
1520
|
351 |
|
$foreignKey = $foreignKey->getQuotedName($this); |
1521
|
351 |
|
$table = $table->getQuotedName($this); |
1522
|
|
|
|
1523
|
351 |
|
return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey; |
1524
|
|
|
} |
1525
|
|
|
|
1526
|
|
|
/** |
1527
|
|
|
* Returns the SQL statement(s) to create a table with the specified name, columns and constraints |
1528
|
|
|
* on this platform. |
1529
|
|
|
* |
1530
|
|
|
* @param int $createFlags |
1531
|
|
|
* |
1532
|
|
|
* @return string[] The sequence of SQL statements. |
1533
|
|
|
* |
1534
|
|
|
* @throws DBALException |
1535
|
|
|
* @throws InvalidArgumentException |
1536
|
|
|
*/ |
1537
|
7247 |
|
public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDEXES) |
1538
|
|
|
{ |
1539
|
7247 |
|
if (! is_int($createFlags)) { |
|
|
|
|
1540
|
|
|
throw new InvalidArgumentException('Second argument of AbstractPlatform::getCreateTableSQL() has to be integer.'); |
1541
|
|
|
} |
1542
|
|
|
|
1543
|
7247 |
|
if (count($table->getColumns()) === 0) { |
1544
|
220 |
|
throw DBALException::noColumnsSpecifiedForTable($table->getName()); |
1545
|
|
|
} |
1546
|
|
|
|
1547
|
7027 |
|
$tableName = $table->getQuotedName($this); |
1548
|
7027 |
|
$options = $table->getOptions(); |
1549
|
7027 |
|
$options['uniqueConstraints'] = []; |
1550
|
7027 |
|
$options['indexes'] = []; |
1551
|
7027 |
|
$options['primary'] = []; |
1552
|
|
|
|
1553
|
7027 |
|
if (($createFlags&self::CREATE_INDEXES) > 0) { |
1554
|
6763 |
|
foreach ($table->getIndexes() as $index) { |
1555
|
4539 |
|
if ($index->isPrimary()) { |
1556
|
3574 |
|
$options['primary'] = $index->getQuotedColumns($this); |
1557
|
3574 |
|
$options['primary_index'] = $index; |
1558
|
|
|
} else { |
1559
|
1414 |
|
$options['indexes'][$index->getQuotedName($this)] = $index; |
1560
|
|
|
} |
1561
|
|
|
} |
1562
|
|
|
} |
1563
|
|
|
|
1564
|
7027 |
|
$columnSql = []; |
1565
|
7027 |
|
$columns = []; |
1566
|
|
|
|
1567
|
7027 |
|
foreach ($table->getColumns() as $column) { |
1568
|
7027 |
|
if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTableColumn)) { |
1569
|
220 |
|
$eventArgs = new SchemaCreateTableColumnEventArgs($column, $table, $this); |
1570
|
220 |
|
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTableColumn, $eventArgs); |
1571
|
|
|
|
1572
|
220 |
|
$columnSql = array_merge($columnSql, $eventArgs->getSql()); |
1573
|
|
|
|
1574
|
220 |
|
if ($eventArgs->isDefaultPrevented()) { |
1575
|
|
|
continue; |
1576
|
|
|
} |
1577
|
|
|
} |
1578
|
|
|
|
1579
|
7027 |
|
$columnData = $column->toArray(); |
1580
|
7027 |
|
$columnData['name'] = $column->getQuotedName($this); |
1581
|
7027 |
|
$columnData['version'] = $column->hasPlatformOption('version') ? $column->getPlatformOption('version') : false; |
1582
|
7027 |
|
$columnData['comment'] = $this->getColumnComment($column); |
1583
|
|
|
|
1584
|
7027 |
|
if ($columnData['type'] instanceof Types\StringType && $columnData['length'] === null) { |
1585
|
2561 |
|
$columnData['length'] = 255; |
1586
|
|
|
} |
1587
|
|
|
|
1588
|
7027 |
|
if (in_array($column->getName(), $options['primary'], true)) { |
1589
|
3310 |
|
$columnData['primary'] = true; |
1590
|
|
|
} |
1591
|
|
|
|
1592
|
7027 |
|
$columns[$columnData['name']] = $columnData; |
1593
|
|
|
} |
1594
|
|
|
|
1595
|
7027 |
|
if (($createFlags&self::CREATE_FOREIGNKEYS) > 0) { |
1596
|
4342 |
|
$options['foreignKeys'] = []; |
1597
|
4342 |
|
foreach ($table->getForeignKeys() as $fkConstraint) { |
1598
|
614 |
|
$options['foreignKeys'][] = $fkConstraint; |
1599
|
|
|
} |
1600
|
|
|
} |
1601
|
|
|
|
1602
|
7027 |
|
if ($this->_eventManager !== null && $this->_eventManager->hasListeners(Events::onSchemaCreateTable)) { |
1603
|
220 |
|
$eventArgs = new SchemaCreateTableEventArgs($table, $columns, $options, $this); |
1604
|
220 |
|
$this->_eventManager->dispatchEvent(Events::onSchemaCreateTable, $eventArgs); |
1605
|
|
|
|
1606
|
220 |
|
if ($eventArgs->isDefaultPrevented()) { |
1607
|
|
|
return array_merge($eventArgs->getSql(), $columnSql); |
1608
|
|
|
} |
1609
|
|
|
} |
1610
|
|
|
|
1611
|
7027 |
|
$sql = $this->_getCreateTableSQL($tableName, $columns, $options); |
1612
|
7027 |
|
if ($this->supportsCommentOnStatement()) { |
1613
|
2550 |
|
if ($table->hasOption('comment')) { |
1614
|
51 |
|
$sql[] = $this->getCommentOnTableSQL($tableName, $table->getOption('comment')); |
1615
|
|
|
} |
1616
|
|
|
|
1617
|
2550 |
|
foreach ($table->getColumns() as $column) { |
1618
|
2550 |
|
$comment = $this->getColumnComment($column); |
1619
|
|
|
|
1620
|
2550 |
|
if ($comment === null || $comment === '') { |
1621
|
2396 |
|
continue; |
1622
|
|
|
} |
1623
|
|
|
|
1624
|
440 |
|
$sql[] = $this->getCommentOnColumnSQL($tableName, $column->getQuotedName($this), $comment); |
1625
|
|
|
} |
1626
|
|
|
} |
1627
|
|
|
|
1628
|
7027 |
|
return array_merge($sql, $columnSql); |
1629
|
|
|
} |
1630
|
|
|
|
1631
|
51 |
|
protected function getCommentOnTableSQL(string $tableName, ?string $comment) : string |
1632
|
|
|
{ |
1633
|
51 |
|
$tableName = new Identifier($tableName); |
1634
|
|
|
|
1635
|
51 |
|
return sprintf( |
1636
|
3 |
|
'COMMENT ON TABLE %s IS %s', |
1637
|
51 |
|
$tableName->getQuotedName($this), |
1638
|
51 |
|
$this->quoteStringLiteral((string) $comment) |
1639
|
|
|
); |
1640
|
|
|
} |
1641
|
|
|
|
1642
|
|
|
/** |
1643
|
|
|
* @param string $tableName |
1644
|
|
|
* @param string $columnName |
1645
|
|
|
* @param string|null $comment |
1646
|
|
|
* |
1647
|
|
|
* @return string |
1648
|
|
|
*/ |
1649
|
681 |
|
public function getCommentOnColumnSQL($tableName, $columnName, $comment) |
1650
|
|
|
{ |
1651
|
681 |
|
$tableName = new Identifier($tableName); |
1652
|
681 |
|
$columnName = new Identifier($columnName); |
1653
|
|
|
|
1654
|
681 |
|
return sprintf( |
1655
|
60 |
|
'COMMENT ON COLUMN %s.%s IS %s', |
1656
|
681 |
|
$tableName->getQuotedName($this), |
1657
|
681 |
|
$columnName->getQuotedName($this), |
1658
|
681 |
|
$this->quoteStringLiteral((string) $comment) |
1659
|
|
|
); |
1660
|
|
|
} |
1661
|
|
|
|
1662
|
|
|
/** |
1663
|
|
|
* Returns the SQL to create inline comment on a column. |
1664
|
|
|
* |
1665
|
|
|
* @param string $comment |
1666
|
|
|
* |
1667
|
|
|
* @return string |
1668
|
|
|
* |
1669
|
|
|
* @throws DBALException If not supported on this platform. |
1670
|
|
|
*/ |
1671
|
1126 |
|
public function getInlineColumnCommentSQL($comment) |
1672
|
|
|
{ |
1673
|
1126 |
|
if (! $this->supportsInlineColumnComments()) { |
1674
|
132 |
|
throw DBALException::notSupported(__METHOD__); |
1675
|
|
|
} |
1676
|
|
|
|
1677
|
994 |
|
return 'COMMENT ' . $this->quoteStringLiteral($comment); |
1678
|
|
|
} |
1679
|
|
|
|
1680
|
|
|
/** |
1681
|
|
|
* Returns the SQL used to create a table. |
1682
|
|
|
* |
1683
|
|
|
* @param string $tableName |
1684
|
|
|
* @param mixed[][] $columns |
1685
|
|
|
* @param mixed[] $options |
1686
|
|
|
* |
1687
|
|
|
* @return string[] |
1688
|
|
|
*/ |
1689
|
786 |
|
protected function _getCreateTableSQL($tableName, array $columns, array $options = []) |
1690
|
|
|
{ |
1691
|
786 |
|
$columnListSql = $this->getColumnDeclarationListSQL($columns); |
1692
|
|
|
|
1693
|
786 |
|
if (isset($options['uniqueConstraints']) && ! empty($options['uniqueConstraints'])) { |
1694
|
|
|
foreach ($options['uniqueConstraints'] as $name => $definition) { |
1695
|
|
|
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition); |
1696
|
|
|
} |
1697
|
|
|
} |
1698
|
|
|
|
1699
|
786 |
|
if (isset($options['primary']) && ! empty($options['primary'])) { |
1700
|
401 |
|
$columnListSql .= ', PRIMARY KEY(' . implode(', ', array_unique(array_values($options['primary']))) . ')'; |
1701
|
|
|
} |
1702
|
|
|
|
1703
|
786 |
|
if (isset($options['indexes']) && ! empty($options['indexes'])) { |
1704
|
|
|
foreach ($options['indexes'] as $index => $definition) { |
1705
|
|
|
$columnListSql .= ', ' . $this->getIndexDeclarationSQL($index, $definition); |
1706
|
|
|
} |
1707
|
|
|
} |
1708
|
|
|
|
1709
|
786 |
|
$query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql; |
1710
|
|
|
|
1711
|
786 |
|
$check = $this->getCheckDeclarationSQL($columns); |
1712
|
786 |
|
if (! empty($check)) { |
1713
|
22 |
|
$query .= ', ' . $check; |
1714
|
|
|
} |
1715
|
|
|
|
1716
|
786 |
|
$query .= ')'; |
1717
|
|
|
|
1718
|
786 |
|
$sql = [$query]; |
1719
|
|
|
|
1720
|
786 |
|
if (isset($options['foreignKeys'])) { |
1721
|
333 |
|
foreach ((array) $options['foreignKeys'] as $definition) { |
1722
|
79 |
|
$sql[] = $this->getCreateForeignKeySQL($definition, $tableName); |
1723
|
|
|
} |
1724
|
|
|
} |
1725
|
|
|
|
1726
|
786 |
|
return $sql; |
1727
|
|
|
} |
1728
|
|
|
|
1729
|
|
|
/** |
1730
|
|
|
* @return string |
1731
|
|
|
*/ |
1732
|
36 |
|
public function getCreateTemporaryTableSnippetSQL() |
1733
|
|
|
{ |
1734
|
36 |
|
return 'CREATE TEMPORARY TABLE'; |
1735
|
|
|
} |
1736
|
|
|
|
1737
|
|
|
/** |
1738
|
|
|
* Returns the SQL to create a sequence on this platform. |
1739
|
|
|
* |
1740
|
|
|
* @return string |
1741
|
|
|
* |
1742
|
|
|
* @throws DBALException If not supported on this platform. |
1743
|
|
|
*/ |
1744
|
|
|
public function getCreateSequenceSQL(Sequence $sequence) |
|
|
|
|
1745
|
|
|
{ |
1746
|
|
|
throw DBALException::notSupported(__METHOD__); |
1747
|
|
|
} |
1748
|
|
|
|
1749
|
|
|
/** |
1750
|
|
|
* Returns the SQL to change a sequence on this platform. |
1751
|
|
|
* |
1752
|
|
|
* @return string |
1753
|
|
|
* |
1754
|
|
|
* @throws DBALException If not supported on this platform. |
1755
|
|
|
*/ |
1756
|
|
|
public function getAlterSequenceSQL(Sequence $sequence) |
|
|
|
|
1757
|
|
|
{ |
1758
|
|
|
throw DBALException::notSupported(__METHOD__); |
1759
|
|
|
} |
1760
|
|
|
|
1761
|
|
|
/** |
1762
|
|
|
* Returns the SQL to create a constraint on a table on this platform. |
1763
|
|
|
* |
1764
|
|
|
* @param Table|string $table |
1765
|
|
|
* |
1766
|
|
|
* @return string |
1767
|
|
|
* |
1768
|
|
|
* @throws InvalidArgumentException |
1769
|
|
|
*/ |
1770
|
267 |
|
public function getCreateConstraintSQL(Constraint $constraint, $table) |
1771
|
|
|
{ |
1772
|
267 |
|
if ($table instanceof Table) { |
1773
|
|
|
$table = $table->getQuotedName($this); |
1774
|
|
|
} |
1775
|
|
|
|
1776
|
267 |
|
$query = 'ALTER TABLE ' . $table . ' ADD CONSTRAINT ' . $constraint->getQuotedName($this); |
1777
|
|
|
|
1778
|
267 |
|
$columnList = '(' . implode(', ', $constraint->getQuotedColumns($this)) . ')'; |
1779
|
|
|
|
1780
|
267 |
|
$referencesClause = ''; |
1781
|
267 |
|
if ($constraint instanceof Index) { |
1782
|
267 |
|
if ($constraint->isPrimary()) { |
1783
|
267 |
|
$query .= ' PRIMARY KEY'; |
1784
|
176 |
|
} elseif ($constraint->isUnique()) { |
1785
|
176 |
|
$query .= ' UNIQUE'; |
1786
|
|
|
} else { |
1787
|
|
|
throw new InvalidArgumentException( |
1788
|
267 |
|
'Can only create primary or unique constraints, no common indexes with getCreateConstraintSQL().' |
1789
|
|
|
); |
1790
|
|
|
} |
1791
|
176 |
|
} elseif ($constraint instanceof ForeignKeyConstraint) { |
1792
|
176 |
|
$query .= ' FOREIGN KEY'; |
1793
|
|
|
|
1794
|
176 |
|
$referencesClause = ' REFERENCES ' . $constraint->getQuotedForeignTableName($this) . |
1795
|
176 |
|
' (' . implode(', ', $constraint->getQuotedForeignColumns($this)) . ')'; |
1796
|
|
|
} |
1797
|
|
|
|
1798
|
267 |
|
$query .= ' ' . $columnList . $referencesClause; |
1799
|
|
|
|
1800
|
267 |
|
return $query; |
1801
|
|
|
} |
1802
|
|
|
|
1803
|
|
|
/** |
1804
|
|
|
* Returns the SQL to create an index on a table on this platform. |
1805
|
|
|
* |
1806
|
|
|
* @param Table|string $table The name of the table on which the index is to be created. |
1807
|
|
|
* |
1808
|
|
|
* @return string |
1809
|
|
|
* |
1810
|
|
|
* @throws InvalidArgumentException |
1811
|
|
|
*/ |
1812
|
2227 |
|
public function getCreateIndexSQL(Index $index, $table) |
1813
|
|
|
{ |
1814
|
2227 |
|
if ($table instanceof Table) { |
1815
|
22 |
|
$table = $table->getQuotedName($this); |
1816
|
|
|
} |
1817
|
|
|
|
1818
|
2227 |
|
$name = $index->getQuotedName($this); |
1819
|
2227 |
|
$columns = $index->getColumns(); |
1820
|
|
|
|
1821
|
2227 |
|
if (count($columns) === 0) { |
1822
|
|
|
throw new InvalidArgumentException("Incomplete definition. 'columns' required."); |
1823
|
|
|
} |
1824
|
|
|
|
1825
|
2227 |
|
if ($index->isPrimary()) { |
1826
|
396 |
|
return $this->getCreatePrimaryKeySQL($index, $table); |
1827
|
|
|
} |
1828
|
|
|
|
1829
|
1853 |
|
$query = 'CREATE ' . $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name . ' ON ' . $table; |
1830
|
1853 |
|
$query .= ' (' . $this->getIndexFieldDeclarationListSQL($index) . ')' . $this->getPartialIndexSQL($index); |
1831
|
|
|
|
1832
|
1853 |
|
return $query; |
1833
|
|
|
} |
1834
|
|
|
|
1835
|
|
|
/** |
1836
|
|
|
* Adds condition for partial index. |
1837
|
|
|
* |
1838
|
|
|
* @return string |
1839
|
|
|
*/ |
1840
|
2863 |
|
protected function getPartialIndexSQL(Index $index) |
1841
|
|
|
{ |
1842
|
2863 |
|
if ($this->supportsPartialIndexes() && $index->hasOption('where')) { |
1843
|
49 |
|
return ' WHERE ' . $index->getOption('where'); |
1844
|
|
|
} |
1845
|
|
|
|
1846
|
2814 |
|
return ''; |
1847
|
|
|
} |
1848
|
|
|
|
1849
|
|
|
/** |
1850
|
|
|
* Adds additional flags for index generation. |
1851
|
|
|
* |
1852
|
|
|
* @return string |
1853
|
|
|
*/ |
1854
|
1041 |
|
protected function getCreateIndexSQLFlags(Index $index) |
1855
|
|
|
{ |
1856
|
1041 |
|
return $index->isUnique() ? 'UNIQUE ' : ''; |
1857
|
|
|
} |
1858
|
|
|
|
1859
|
|
|
/** |
1860
|
|
|
* Returns the SQL to create an unnamed primary key constraint. |
1861
|
|
|
* |
1862
|
|
|
* @param Table|string $table |
1863
|
|
|
* |
1864
|
|
|
* @return string |
1865
|
|
|
*/ |
1866
|
374 |
|
public function getCreatePrimaryKeySQL(Index $index, $table) |
1867
|
|
|
{ |
1868
|
374 |
|
if ($table instanceof Table) { |
1869
|
|
|
$table = $table->getQuotedName($this); |
1870
|
|
|
} |
1871
|
|
|
|
1872
|
374 |
|
return 'ALTER TABLE ' . $table . ' ADD PRIMARY KEY (' . $this->getIndexFieldDeclarationListSQL($index) . ')'; |
1873
|
|
|
} |
1874
|
|
|
|
1875
|
|
|
/** |
1876
|
|
|
* Returns the SQL to create a named schema. |
1877
|
|
|
* |
1878
|
|
|
* @param string $schemaName |
1879
|
|
|
* |
1880
|
|
|
* @return string |
1881
|
|
|
* |
1882
|
|
|
* @throws DBALException If not supported on this platform. |
1883
|
|
|
*/ |
1884
|
154 |
|
public function getCreateSchemaSQL($schemaName) |
|
|
|
|
1885
|
|
|
{ |
1886
|
154 |
|
throw DBALException::notSupported(__METHOD__); |
1887
|
|
|
} |
1888
|
|
|
|
1889
|
|
|
/** |
1890
|
|
|
* Quotes a string so that it can be safely used as a table or column name, |
1891
|
|
|
* even if it is a reserved word of the platform. This also detects identifier |
1892
|
|
|
* chains separated by dot and quotes them independently. |
1893
|
|
|
* |
1894
|
|
|
* NOTE: Just because you CAN use quoted identifiers doesn't mean |
1895
|
|
|
* you SHOULD use them. In general, they end up causing way more |
1896
|
|
|
* problems than they solve. |
1897
|
|
|
* |
1898
|
|
|
* @param string $str The identifier name to be quoted. |
1899
|
|
|
* |
1900
|
|
|
* @return string The quoted identifier string. |
1901
|
|
|
*/ |
1902
|
4826 |
|
public function quoteIdentifier($str) |
1903
|
|
|
{ |
1904
|
4826 |
|
if (strpos($str, '.') !== false) { |
1905
|
238 |
|
$parts = array_map([$this, 'quoteSingleIdentifier'], explode('.', $str)); |
1906
|
|
|
|
1907
|
238 |
|
return implode('.', $parts); |
1908
|
|
|
} |
1909
|
|
|
|
1910
|
4826 |
|
return $this->quoteSingleIdentifier($str); |
1911
|
|
|
} |
1912
|
|
|
|
1913
|
|
|
/** |
1914
|
|
|
* Quotes a single identifier (no dot chain separation). |
1915
|
|
|
* |
1916
|
|
|
* @param string $str The identifier name to be quoted. |
1917
|
|
|
* |
1918
|
|
|
* @return string The quoted identifier string. |
1919
|
|
|
*/ |
1920
|
8273 |
|
public function quoteSingleIdentifier($str) |
1921
|
|
|
{ |
1922
|
8273 |
|
$c = $this->getIdentifierQuoteCharacter(); |
1923
|
|
|
|
1924
|
8273 |
|
return $c . str_replace($c, $c . $c, $str) . $c; |
1925
|
|
|
} |
1926
|
|
|
|
1927
|
|
|
/** |
1928
|
|
|
* Returns the SQL to create a new foreign key. |
1929
|
|
|
* |
1930
|
|
|
* @param ForeignKeyConstraint $foreignKey The foreign key constraint. |
1931
|
|
|
* @param Table|string $table The name of the table on which the foreign key is to be created. |
1932
|
|
|
* |
1933
|
|
|
* @return string |
1934
|
|
|
*/ |
1935
|
1082 |
|
public function getCreateForeignKeySQL(ForeignKeyConstraint $foreignKey, $table) |
1936
|
|
|
{ |
1937
|
1082 |
|
if ($table instanceof Table) { |
1938
|
43 |
|
$table = $table->getQuotedName($this); |
1939
|
|
|
} |
1940
|
|
|
|
1941
|
1082 |
|
return 'ALTER TABLE ' . $table . ' ADD ' . $this->getForeignKeyDeclarationSQL($foreignKey); |
1942
|
|
|
} |
1943
|
|
|
|
1944
|
|
|
/** |
1945
|
|
|
* Gets the SQL statements for altering an existing table. |
1946
|
|
|
* |
1947
|
|
|
* This method returns an array of SQL statements, since some platforms need several statements. |
1948
|
|
|
* |
1949
|
|
|
* @return string[] |
1950
|
|
|
* |
1951
|
|
|
* @throws DBALException If not supported on this platform. |
1952
|
|
|
*/ |
1953
|
|
|
public function getAlterTableSQL(TableDiff $diff) |
1954
|
|
|
{ |
1955
|
|
|
throw DBALException::notSupported(__METHOD__); |
1956
|
|
|
} |
1957
|
|
|
|
1958
|
|
|
/** |
1959
|
|
|
* @param mixed[] $columnSql |
1960
|
|
|
* |
1961
|
|
|
* @return bool |
1962
|
|
|
*/ |
1963
|
1224 |
|
protected function onSchemaAlterTableAddColumn(Column $column, TableDiff $diff, &$columnSql) |
1964
|
|
|
{ |
1965
|
1224 |
|
if ($this->_eventManager === null) { |
1966
|
968 |
|
return false; |
1967
|
|
|
} |
1968
|
|
|
|
1969
|
256 |
|
if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTableAddColumn)) { |
1970
|
36 |
|
return false; |
1971
|
|
|
} |
1972
|
|
|
|
1973
|
220 |
|
$eventArgs = new SchemaAlterTableAddColumnEventArgs($column, $diff, $this); |
1974
|
220 |
|
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTableAddColumn, $eventArgs); |
1975
|
|
|
|
1976
|
220 |
|
$columnSql = array_merge($columnSql, $eventArgs->getSql()); |
1977
|
|
|
|
1978
|
220 |
|
return $eventArgs->isDefaultPrevented(); |
1979
|
|
|
} |
1980
|
|
|
|
1981
|
|
|
/** |
1982
|
|
|
* @param string[] $columnSql |
1983
|
|
|
* |
1984
|
|
|
* @return bool |
1985
|
|
|
*/ |
1986
|
864 |
|
protected function onSchemaAlterTableRemoveColumn(Column $column, TableDiff $diff, &$columnSql) |
1987
|
|
|
{ |
1988
|
864 |
|
if ($this->_eventManager === null) { |
1989
|
616 |
|
return false; |
1990
|
|
|
} |
1991
|
|
|
|
1992
|
248 |
|
if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTableRemoveColumn)) { |
1993
|
28 |
|
return false; |
1994
|
|
|
} |
1995
|
|
|
|
1996
|
220 |
|
$eventArgs = new SchemaAlterTableRemoveColumnEventArgs($column, $diff, $this); |
1997
|
220 |
|
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTableRemoveColumn, $eventArgs); |
1998
|
|
|
|
1999
|
220 |
|
$columnSql = array_merge($columnSql, $eventArgs->getSql()); |
2000
|
|
|
|
2001
|
220 |
|
return $eventArgs->isDefaultPrevented(); |
2002
|
|
|
} |
2003
|
|
|
|
2004
|
|
|
/** |
2005
|
|
|
* @param string[] $columnSql |
2006
|
|
|
* |
2007
|
|
|
* @return bool |
2008
|
|
|
*/ |
2009
|
2499 |
|
protected function onSchemaAlterTableChangeColumn(ColumnDiff $columnDiff, TableDiff $diff, &$columnSql) |
2010
|
|
|
{ |
2011
|
2499 |
|
if ($this->_eventManager === null) { |
2012
|
1958 |
|
return false; |
2013
|
|
|
} |
2014
|
|
|
|
2015
|
541 |
|
if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTableChangeColumn)) { |
2016
|
321 |
|
return false; |
2017
|
|
|
} |
2018
|
|
|
|
2019
|
220 |
|
$eventArgs = new SchemaAlterTableChangeColumnEventArgs($columnDiff, $diff, $this); |
2020
|
220 |
|
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTableChangeColumn, $eventArgs); |
2021
|
|
|
|
2022
|
220 |
|
$columnSql = array_merge($columnSql, $eventArgs->getSql()); |
2023
|
|
|
|
2024
|
220 |
|
return $eventArgs->isDefaultPrevented(); |
2025
|
|
|
} |
2026
|
|
|
|
2027
|
|
|
/** |
2028
|
|
|
* @param string $oldColumnName |
2029
|
|
|
* @param string[] $columnSql |
2030
|
|
|
* |
2031
|
|
|
* @return bool |
2032
|
|
|
*/ |
2033
|
950 |
|
protected function onSchemaAlterTableRenameColumn($oldColumnName, Column $column, TableDiff $diff, &$columnSql) |
2034
|
|
|
{ |
2035
|
950 |
|
if ($this->_eventManager === null) { |
2036
|
704 |
|
return false; |
2037
|
|
|
} |
2038
|
|
|
|
2039
|
246 |
|
if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTableRenameColumn)) { |
2040
|
26 |
|
return false; |
2041
|
|
|
} |
2042
|
|
|
|
2043
|
220 |
|
$eventArgs = new SchemaAlterTableRenameColumnEventArgs($oldColumnName, $column, $diff, $this); |
2044
|
220 |
|
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTableRenameColumn, $eventArgs); |
2045
|
|
|
|
2046
|
220 |
|
$columnSql = array_merge($columnSql, $eventArgs->getSql()); |
2047
|
|
|
|
2048
|
220 |
|
return $eventArgs->isDefaultPrevented(); |
2049
|
|
|
} |
2050
|
|
|
|
2051
|
|
|
/** |
2052
|
|
|
* @param string[] $sql |
2053
|
|
|
* |
2054
|
|
|
* @return bool |
2055
|
|
|
*/ |
2056
|
5000 |
|
protected function onSchemaAlterTable(TableDiff $diff, &$sql) |
2057
|
|
|
{ |
2058
|
5000 |
|
if ($this->_eventManager === null) { |
2059
|
4334 |
|
return false; |
2060
|
|
|
} |
2061
|
|
|
|
2062
|
666 |
|
if (! $this->_eventManager->hasListeners(Events::onSchemaAlterTable)) { |
2063
|
446 |
|
return false; |
2064
|
|
|
} |
2065
|
|
|
|
2066
|
220 |
|
$eventArgs = new SchemaAlterTableEventArgs($diff, $this); |
2067
|
220 |
|
$this->_eventManager->dispatchEvent(Events::onSchemaAlterTable, $eventArgs); |
2068
|
|
|
|
2069
|
220 |
|
$sql = array_merge($sql, $eventArgs->getSql()); |
2070
|
|
|
|
2071
|
220 |
|
return $eventArgs->isDefaultPrevented(); |
2072
|
|
|
} |
2073
|
|
|
|
2074
|
|
|
/** |
2075
|
|
|
* @return string[] |
2076
|
|
|
*/ |
2077
|
4691 |
|
protected function getPreAlterTableIndexForeignKeySQL(TableDiff $diff) |
2078
|
|
|
{ |
2079
|
4691 |
|
$tableName = $diff->getName($this)->getQuotedName($this); |
2080
|
|
|
|
2081
|
4691 |
|
$sql = []; |
2082
|
4691 |
|
if ($this->supportsForeignKeyConstraints()) { |
2083
|
4691 |
|
foreach ($diff->removedForeignKeys as $foreignKey) { |
2084
|
329 |
|
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName); |
2085
|
|
|
} |
2086
|
|
|
|
2087
|
4691 |
|
foreach ($diff->changedForeignKeys as $foreignKey) { |
2088
|
264 |
|
$sql[] = $this->getDropForeignKeySQL($foreignKey, $tableName); |
2089
|
|
|
} |
2090
|
|
|
} |
2091
|
|
|
|
2092
|
4691 |
|
foreach ($diff->removedIndexes as $index) { |
2093
|
221 |
|
$sql[] = $this->getDropIndexSQL($index, $tableName); |
2094
|
|
|
} |
2095
|
|
|
|
2096
|
4691 |
|
foreach ($diff->changedIndexes as $index) { |
2097
|
394 |
|
$sql[] = $this->getDropIndexSQL($index, $tableName); |
2098
|
|
|
} |
2099
|
|
|
|
2100
|
4691 |
|
return $sql; |
2101
|
|
|
} |
2102
|
|
|
|
2103
|
|
|
/** |
2104
|
|
|
* @return string[] |
2105
|
|
|
*/ |
2106
|
4691 |
|
protected function getPostAlterTableIndexForeignKeySQL(TableDiff $diff) |
2107
|
|
|
{ |
2108
|
4691 |
|
$sql = []; |
2109
|
4691 |
|
$newName = $diff->getNewName(); |
2110
|
|
|
|
2111
|
4691 |
|
if ($newName !== false) { |
2112
|
399 |
|
$tableName = $newName->getQuotedName($this); |
2113
|
|
|
} else { |
2114
|
4294 |
|
$tableName = $diff->getName($this)->getQuotedName($this); |
2115
|
|
|
} |
2116
|
|
|
|
2117
|
4691 |
|
if ($this->supportsForeignKeyConstraints()) { |
2118
|
4691 |
|
foreach ($diff->addedForeignKeys as $foreignKey) { |
2119
|
306 |
|
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName); |
2120
|
|
|
} |
2121
|
|
|
|
2122
|
4691 |
|
foreach ($diff->changedForeignKeys as $foreignKey) { |
2123
|
264 |
|
$sql[] = $this->getCreateForeignKeySQL($foreignKey, $tableName); |
2124
|
|
|
} |
2125
|
|
|
} |
2126
|
|
|
|
2127
|
4691 |
|
foreach ($diff->addedIndexes as $index) { |
2128
|
87 |
|
$sql[] = $this->getCreateIndexSQL($index, $tableName); |
2129
|
|
|
} |
2130
|
|
|
|
2131
|
4691 |
|
foreach ($diff->changedIndexes as $index) { |
2132
|
394 |
|
$sql[] = $this->getCreateIndexSQL($index, $tableName); |
2133
|
|
|
} |
2134
|
|
|
|
2135
|
4691 |
|
foreach ($diff->renamedIndexes as $oldIndexName => $index) { |
2136
|
1032 |
|
$oldIndexName = new Identifier($oldIndexName); |
2137
|
1032 |
|
$sql = array_merge( |
2138
|
1032 |
|
$sql, |
2139
|
1032 |
|
$this->getRenameIndexSQL($oldIndexName->getQuotedName($this), $index, $tableName) |
2140
|
|
|
); |
2141
|
|
|
} |
2142
|
|
|
|
2143
|
4691 |
|
return $sql; |
2144
|
|
|
} |
2145
|
|
|
|
2146
|
|
|
/** |
2147
|
|
|
* Returns the SQL for renaming an index on a table. |
2148
|
|
|
* |
2149
|
|
|
* @param string $oldIndexName The name of the index to rename from. |
2150
|
|
|
* @param Index $index The definition of the index to rename to. |
2151
|
|
|
* @param string $tableName The table to rename the given index on. |
2152
|
|
|
* |
2153
|
|
|
* @return string[] The sequence of SQL statements for renaming the given index. |
2154
|
|
|
*/ |
2155
|
236 |
|
protected function getRenameIndexSQL($oldIndexName, Index $index, $tableName) |
2156
|
|
|
{ |
2157
|
|
|
return [ |
2158
|
236 |
|
$this->getDropIndexSQL($oldIndexName, $tableName), |
2159
|
236 |
|
$this->getCreateIndexSQL($index, $tableName), |
2160
|
|
|
]; |
2161
|
|
|
} |
2162
|
|
|
|
2163
|
|
|
/** |
2164
|
|
|
* Common code for alter table statement generation that updates the changed Index and Foreign Key definitions. |
2165
|
|
|
* |
2166
|
|
|
* @deprecated |
2167
|
|
|
* |
2168
|
|
|
* @return string[] |
2169
|
|
|
*/ |
2170
|
|
|
protected function _getAlterTableIndexForeignKeySQL(TableDiff $diff) |
2171
|
|
|
{ |
2172
|
|
|
return array_merge($this->getPreAlterTableIndexForeignKeySQL($diff), $this->getPostAlterTableIndexForeignKeySQL($diff)); |
2173
|
|
|
} |
2174
|
|
|
|
2175
|
|
|
/** |
2176
|
|
|
* Gets declaration of a number of fields in bulk. |
2177
|
|
|
* |
2178
|
|
|
* @param mixed[][] $fields A multidimensional associative array. |
2179
|
|
|
* The first dimension determines the field name, while the second |
2180
|
|
|
* dimension is keyed with the name of the properties |
2181
|
|
|
* of the field being declared as array indexes. Currently, the types |
2182
|
|
|
* of supported field properties are as follows: |
2183
|
|
|
* |
2184
|
|
|
* length |
2185
|
|
|
* Integer value that determines the maximum length of the text |
2186
|
|
|
* field. If this argument is missing the field should be |
2187
|
|
|
* declared to have the longest length allowed by the DBMS. |
2188
|
|
|
* |
2189
|
|
|
* default |
2190
|
|
|
* Text value to be used as default for this field. |
2191
|
|
|
* |
2192
|
|
|
* notnull |
2193
|
|
|
* Boolean flag that indicates whether this field is constrained |
2194
|
|
|
* to not be set to null. |
2195
|
|
|
* charset |
2196
|
|
|
* Text value with the default CHARACTER SET for this field. |
2197
|
|
|
* collation |
2198
|
|
|
* Text value with the default COLLATION for this field. |
2199
|
|
|
* unique |
2200
|
|
|
* unique constraint |
2201
|
|
|
* |
2202
|
|
|
* @return string |
2203
|
|
|
*/ |
2204
|
7027 |
|
public function getColumnDeclarationListSQL(array $fields) |
2205
|
|
|
{ |
2206
|
7027 |
|
$queryFields = []; |
2207
|
|
|
|
2208
|
7027 |
|
foreach ($fields as $fieldName => $field) { |
2209
|
7027 |
|
$queryFields[] = $this->getColumnDeclarationSQL($fieldName, $field); |
2210
|
|
|
} |
2211
|
|
|
|
2212
|
7027 |
|
return implode(', ', $queryFields); |
2213
|
|
|
} |
2214
|
|
|
|
2215
|
|
|
/** |
2216
|
|
|
* Obtains DBMS specific SQL code portion needed to declare a generic type |
2217
|
|
|
* field to be used in statements like CREATE TABLE. |
2218
|
|
|
* |
2219
|
|
|
* @param string $name The name the field to be declared. |
2220
|
|
|
* @param mixed[] $field An associative array with the name of the properties |
2221
|
|
|
* of the field being declared as array indexes. Currently, the types |
2222
|
|
|
* of supported field properties are as follows: |
2223
|
|
|
* |
2224
|
|
|
* length |
2225
|
|
|
* Integer value that determines the maximum length of the text |
2226
|
|
|
* field. If this argument is missing the field should be |
2227
|
|
|
* declared to have the longest length allowed by the DBMS. |
2228
|
|
|
* |
2229
|
|
|
* default |
2230
|
|
|
* Text value to be used as default for this field. |
2231
|
|
|
* |
2232
|
|
|
* notnull |
2233
|
|
|
* Boolean flag that indicates whether this field is constrained |
2234
|
|
|
* to not be set to null. |
2235
|
|
|
* charset |
2236
|
|
|
* Text value with the default CHARACTER SET for this field. |
2237
|
|
|
* collation |
2238
|
|
|
* Text value with the default COLLATION for this field. |
2239
|
|
|
* unique |
2240
|
|
|
* unique constraint |
2241
|
|
|
* check |
2242
|
|
|
* column check constraint |
2243
|
|
|
* columnDefinition |
2244
|
|
|
* a string that defines the complete column |
2245
|
|
|
* |
2246
|
|
|
* @return string DBMS specific SQL code portion that should be used to declare the column. |
2247
|
|
|
*/ |
2248
|
7578 |
|
public function getColumnDeclarationSQL($name, array $field) |
2249
|
|
|
{ |
2250
|
7578 |
|
if (isset($field['columnDefinition'])) { |
2251
|
189 |
|
$columnDef = $this->getCustomTypeDeclarationSQL($field); |
2252
|
|
|
} else { |
2253
|
7402 |
|
$default = $this->getDefaultValueDeclarationSQL($field); |
2254
|
|
|
|
2255
|
7402 |
|
$charset = ! empty($field['charset']) ? |
2256
|
7402 |
|
' ' . $this->getColumnCharsetDeclarationSQL($field['charset']) : ''; |
2257
|
|
|
|
2258
|
7402 |
|
$collation = ! empty($field['collation']) ? |
2259
|
7402 |
|
' ' . $this->getColumnCollationDeclarationSQL($field['collation']) : ''; |
2260
|
|
|
|
2261
|
7402 |
|
$notnull = ! empty($field['notnull']) ? ' NOT NULL' : ''; |
2262
|
|
|
|
2263
|
7402 |
|
$unique = ! empty($field['unique']) ? |
2264
|
7402 |
|
' ' . $this->getUniqueFieldDeclarationSQL() : ''; |
2265
|
|
|
|
2266
|
7402 |
|
$check = ! empty($field['check']) ? ' ' . $field['check'] : ''; |
2267
|
|
|
|
2268
|
7402 |
|
$typeDecl = $field['type']->getSQLDeclaration($field, $this); |
2269
|
7402 |
|
$columnDef = $typeDecl . $charset . $default . $notnull . $unique . $check . $collation; |
2270
|
|
|
|
2271
|
7402 |
|
if ($this->supportsInlineColumnComments() && isset($field['comment']) && $field['comment'] !== '') { |
2272
|
895 |
|
$columnDef .= ' ' . $this->getInlineColumnCommentSQL($field['comment']); |
2273
|
|
|
} |
2274
|
|
|
} |
2275
|
|
|
|
2276
|
7578 |
|
return $name . ' ' . $columnDef; |
2277
|
|
|
} |
2278
|
|
|
|
2279
|
|
|
/** |
2280
|
|
|
* Returns the SQL snippet that declares a floating point column of arbitrary precision. |
2281
|
|
|
* |
2282
|
|
|
* @param mixed[] $columnDef |
2283
|
|
|
* |
2284
|
|
|
* @return string |
2285
|
|
|
*/ |
2286
|
1835 |
|
public function getDecimalTypeDeclarationSQL(array $columnDef) |
2287
|
|
|
{ |
2288
|
1835 |
|
$columnDef['precision'] = ! isset($columnDef['precision']) || empty($columnDef['precision']) |
2289
|
1835 |
|
? 10 : $columnDef['precision']; |
2290
|
1835 |
|
$columnDef['scale'] = ! isset($columnDef['scale']) || empty($columnDef['scale']) |
2291
|
1835 |
|
? 0 : $columnDef['scale']; |
2292
|
|
|
|
2293
|
1835 |
|
return 'NUMERIC(' . $columnDef['precision'] . ', ' . $columnDef['scale'] . ')'; |
2294
|
|
|
} |
2295
|
|
|
|
2296
|
|
|
/** |
2297
|
|
|
* Obtains DBMS specific SQL code portion needed to set a default value |
2298
|
|
|
* declaration to be used in statements like CREATE TABLE. |
2299
|
|
|
* |
2300
|
|
|
* @param mixed[] $field The field definition array. |
2301
|
|
|
* |
2302
|
|
|
* @return string DBMS specific SQL code portion needed to set a default value. |
2303
|
|
|
*/ |
2304
|
8936 |
|
public function getDefaultValueDeclarationSQL($field) |
2305
|
|
|
{ |
2306
|
8936 |
|
if (! isset($field['default'])) { |
2307
|
7492 |
|
return empty($field['notnull']) ? ' DEFAULT NULL' : ''; |
2308
|
|
|
} |
2309
|
|
|
|
2310
|
1881 |
|
$default = $field['default']; |
2311
|
|
|
|
2312
|
1881 |
|
if (! isset($field['type'])) { |
2313
|
88 |
|
return " DEFAULT '" . $default . "'"; |
2314
|
|
|
} |
2315
|
|
|
|
2316
|
1793 |
|
$type = $field['type']; |
2317
|
|
|
|
2318
|
1793 |
|
if ($type instanceof Types\PhpIntegerMappingType) { |
2319
|
514 |
|
return ' DEFAULT ' . $default; |
2320
|
|
|
} |
2321
|
|
|
|
2322
|
1364 |
|
if ($type instanceof Types\PhpDateTimeMappingType && $default === $this->getCurrentTimestampSQL()) { |
2323
|
270 |
|
return ' DEFAULT ' . $this->getCurrentTimestampSQL(); |
2324
|
|
|
} |
2325
|
|
|
|
2326
|
1110 |
|
if ($type instanceof Types\TimeType && $default === $this->getCurrentTimeSQL()) { |
2327
|
13 |
|
return ' DEFAULT ' . $this->getCurrentTimeSQL(); |
2328
|
|
|
} |
2329
|
|
|
|
2330
|
1101 |
|
if ($type instanceof Types\DateType && $default === $this->getCurrentDateSQL()) { |
2331
|
234 |
|
return ' DEFAULT ' . $this->getCurrentDateSQL(); |
2332
|
|
|
} |
2333
|
|
|
|
2334
|
867 |
|
if ($type instanceof Types\BooleanType) { |
2335
|
249 |
|
return " DEFAULT '" . $this->convertBooleans($default) . "'"; |
|
|
|
|
2336
|
|
|
} |
2337
|
|
|
|
2338
|
840 |
|
return ' DEFAULT ' . $this->quoteStringLiteral($default); |
2339
|
|
|
} |
2340
|
|
|
|
2341
|
|
|
/** |
2342
|
|
|
* Obtains DBMS specific SQL code portion needed to set a CHECK constraint |
2343
|
|
|
* declaration to be used in statements like CREATE TABLE. |
2344
|
|
|
* |
2345
|
|
|
* @param string[]|mixed[][] $definition The check definition. |
2346
|
|
|
* |
2347
|
|
|
* @return string DBMS specific SQL code portion needed to set a CHECK constraint. |
2348
|
|
|
*/ |
2349
|
1706 |
|
public function getCheckDeclarationSQL(array $definition) |
2350
|
|
|
{ |
2351
|
1706 |
|
$constraints = []; |
2352
|
1706 |
|
foreach ($definition as $field => $def) { |
2353
|
1706 |
|
if (is_string($def)) { |
2354
|
|
|
$constraints[] = 'CHECK (' . $def . ')'; |
2355
|
|
|
} else { |
2356
|
1706 |
|
if (isset($def['min'])) { |
2357
|
44 |
|
$constraints[] = 'CHECK (' . $field . ' >= ' . $def['min'] . ')'; |
2358
|
|
|
} |
2359
|
|
|
|
2360
|
1706 |
|
if (isset($def['max'])) { |
2361
|
44 |
|
$constraints[] = 'CHECK (' . $field . ' <= ' . $def['max'] . ')'; |
2362
|
|
|
} |
2363
|
|
|
} |
2364
|
|
|
} |
2365
|
|
|
|
2366
|
1706 |
|
return implode(', ', $constraints); |
2367
|
|
|
} |
2368
|
|
|
|
2369
|
|
|
/** |
2370
|
|
|
* Obtains DBMS specific SQL code portion needed to set a unique |
2371
|
|
|
* constraint declaration to be used in statements like CREATE TABLE. |
2372
|
|
|
* |
2373
|
|
|
* @param string $name The name of the unique constraint. |
2374
|
|
|
* @param Index $index The index definition. |
2375
|
|
|
* |
2376
|
|
|
* @return string DBMS specific SQL code portion needed to set a constraint. |
2377
|
|
|
* |
2378
|
|
|
* @throws InvalidArgumentException |
2379
|
|
|
*/ |
2380
|
396 |
|
public function getUniqueConstraintDeclarationSQL($name, Index $index) |
2381
|
|
|
{ |
2382
|
396 |
|
$columns = $index->getColumns(); |
2383
|
396 |
|
$name = new Identifier($name); |
2384
|
|
|
|
2385
|
396 |
|
if (count($columns) === 0) { |
2386
|
|
|
throw new InvalidArgumentException("Incomplete definition. 'columns' required."); |
2387
|
|
|
} |
2388
|
|
|
|
2389
|
396 |
|
return 'CONSTRAINT ' . $name->getQuotedName($this) . ' UNIQUE (' |
2390
|
396 |
|
. $this->getIndexFieldDeclarationListSQL($index) |
2391
|
396 |
|
. ')' . $this->getPartialIndexSQL($index); |
2392
|
|
|
} |
2393
|
|
|
|
2394
|
|
|
/** |
2395
|
|
|
* Obtains DBMS specific SQL code portion needed to set an index |
2396
|
|
|
* declaration to be used in statements like CREATE TABLE. |
2397
|
|
|
* |
2398
|
|
|
* @param string $name The name of the index. |
2399
|
|
|
* @param Index $index The index definition. |
2400
|
|
|
* |
2401
|
|
|
* @return string DBMS specific SQL code portion needed to set an index. |
2402
|
|
|
* |
2403
|
|
|
* @throws InvalidArgumentException |
2404
|
|
|
*/ |
2405
|
1020 |
|
public function getIndexDeclarationSQL($name, Index $index) |
2406
|
|
|
{ |
2407
|
1020 |
|
$columns = $index->getColumns(); |
2408
|
1020 |
|
$name = new Identifier($name); |
2409
|
|
|
|
2410
|
1020 |
|
if (count($columns) === 0) { |
2411
|
|
|
throw new InvalidArgumentException("Incomplete definition. 'columns' required."); |
2412
|
|
|
} |
2413
|
|
|
|
2414
|
1020 |
|
return $this->getCreateIndexSQLFlags($index) . 'INDEX ' . $name->getQuotedName($this) . ' (' |
2415
|
1020 |
|
. $this->getIndexFieldDeclarationListSQL($index) |
2416
|
1020 |
|
. ')' . $this->getPartialIndexSQL($index); |
2417
|
|
|
} |
2418
|
|
|
|
2419
|
|
|
/** |
2420
|
|
|
* Obtains SQL code portion needed to create a custom column, |
2421
|
|
|
* e.g. when a field has the "columnDefinition" keyword. |
2422
|
|
|
* Only "AUTOINCREMENT" and "PRIMARY KEY" are added if appropriate. |
2423
|
|
|
* |
2424
|
|
|
* @param mixed[] $columnDef |
2425
|
|
|
* |
2426
|
|
|
* @return string |
2427
|
|
|
*/ |
2428
|
233 |
|
public function getCustomTypeDeclarationSQL(array $columnDef) |
2429
|
|
|
{ |
2430
|
233 |
|
return $columnDef['columnDefinition']; |
2431
|
|
|
} |
2432
|
|
|
|
2433
|
|
|
/** |
2434
|
|
|
* Obtains DBMS specific SQL code portion needed to set an index |
2435
|
|
|
* declaration to be used in statements like CREATE TABLE. |
2436
|
|
|
* |
2437
|
|
|
* @param mixed[]|Index $columnsOrIndex array declaration is deprecated, prefer passing Index to this method |
2438
|
|
|
*/ |
2439
|
3567 |
|
public function getIndexFieldDeclarationListSQL($columnsOrIndex) : string |
2440
|
|
|
{ |
2441
|
3567 |
|
if ($columnsOrIndex instanceof Index) { |
2442
|
3347 |
|
return implode(', ', $columnsOrIndex->getQuotedColumns($this)); |
2443
|
|
|
} |
2444
|
|
|
|
2445
|
264 |
|
if (! is_array($columnsOrIndex)) { |
|
|
|
|
2446
|
|
|
throw new InvalidArgumentException('Fields argument should be an Index or array.'); |
2447
|
|
|
} |
2448
|
|
|
|
2449
|
264 |
|
$ret = []; |
2450
|
|
|
|
2451
|
264 |
|
foreach ($columnsOrIndex as $column => $definition) { |
2452
|
264 |
|
if (is_array($definition)) { |
2453
|
|
|
$ret[] = $column; |
2454
|
|
|
} else { |
2455
|
264 |
|
$ret[] = $definition; |
2456
|
|
|
} |
2457
|
|
|
} |
2458
|
|
|
|
2459
|
264 |
|
return implode(', ', $ret); |
2460
|
|
|
} |
2461
|
|
|
|
2462
|
|
|
/** |
2463
|
|
|
* Returns the required SQL string that fits between CREATE ... TABLE |
2464
|
|
|
* to create the table as a temporary table. |
2465
|
|
|
* |
2466
|
|
|
* Should be overridden in driver classes to return the correct string for the |
2467
|
|
|
* specific database type. |
2468
|
|
|
* |
2469
|
|
|
* The default is to return the string "TEMPORARY" - this will result in a |
2470
|
|
|
* SQL error for any database that does not support temporary tables, or that |
2471
|
|
|
* requires a different SQL command from "CREATE TEMPORARY TABLE". |
2472
|
|
|
* |
2473
|
|
|
* @return string The string required to be placed between "CREATE" and "TABLE" |
2474
|
|
|
* to generate a temporary table, if possible. |
2475
|
|
|
*/ |
2476
|
|
|
public function getTemporaryTableSQL() |
2477
|
|
|
{ |
2478
|
|
|
return 'TEMPORARY'; |
2479
|
|
|
} |
2480
|
|
|
|
2481
|
|
|
/** |
2482
|
|
|
* Some vendors require temporary table names to be qualified specially. |
2483
|
|
|
* |
2484
|
|
|
* @param string $tableName |
2485
|
|
|
* |
2486
|
|
|
* @return string |
2487
|
|
|
*/ |
2488
|
34 |
|
public function getTemporaryTableName($tableName) |
2489
|
|
|
{ |
2490
|
34 |
|
return $tableName; |
2491
|
|
|
} |
2492
|
|
|
|
2493
|
|
|
/** |
2494
|
|
|
* Obtain DBMS specific SQL code portion needed to set the FOREIGN KEY constraint |
2495
|
|
|
* of a field declaration to be used in statements like CREATE TABLE. |
2496
|
|
|
* |
2497
|
|
|
* @return string DBMS specific SQL code portion needed to set the FOREIGN KEY constraint |
2498
|
|
|
* of a field declaration. |
2499
|
|
|
*/ |
2500
|
1380 |
|
public function getForeignKeyDeclarationSQL(ForeignKeyConstraint $foreignKey) |
2501
|
|
|
{ |
2502
|
1380 |
|
$sql = $this->getForeignKeyBaseDeclarationSQL($foreignKey); |
2503
|
1314 |
|
$sql .= $this->getAdvancedForeignKeyOptionsSQL($foreignKey); |
2504
|
|
|
|
2505
|
1314 |
|
return $sql; |
2506
|
|
|
} |
2507
|
|
|
|
2508
|
|
|
/** |
2509
|
|
|
* Returns the FOREIGN KEY query section dealing with non-standard options |
2510
|
|
|
* as MATCH, INITIALLY DEFERRED, ON UPDATE, ... |
2511
|
|
|
* |
2512
|
|
|
* @param ForeignKeyConstraint $foreignKey The foreign key definition. |
2513
|
|
|
* |
2514
|
|
|
* @return string |
2515
|
|
|
*/ |
2516
|
1235 |
|
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) |
2517
|
|
|
{ |
2518
|
1235 |
|
$query = ''; |
2519
|
1235 |
|
if ($this->supportsForeignKeyOnUpdate() && $foreignKey->hasOption('onUpdate')) { |
2520
|
22 |
|
$query .= ' ON UPDATE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onUpdate')); |
2521
|
|
|
} |
2522
|
|
|
|
2523
|
1235 |
|
if ($foreignKey->hasOption('onDelete')) { |
2524
|
87 |
|
$query .= ' ON DELETE ' . $this->getForeignKeyReferentialActionSQL($foreignKey->getOption('onDelete')); |
2525
|
|
|
} |
2526
|
|
|
|
2527
|
1235 |
|
return $query; |
2528
|
|
|
} |
2529
|
|
|
|
2530
|
|
|
/** |
2531
|
|
|
* Returns the given referential action in uppercase if valid, otherwise throws an exception. |
2532
|
|
|
* |
2533
|
|
|
* @param string $action The foreign key referential action. |
2534
|
|
|
* |
2535
|
|
|
* @return string |
2536
|
|
|
* |
2537
|
|
|
* @throws InvalidArgumentException If unknown referential action given. |
2538
|
|
|
*/ |
2539
|
1429 |
|
public function getForeignKeyReferentialActionSQL($action) |
2540
|
|
|
{ |
2541
|
1429 |
|
$upper = strtoupper($action); |
2542
|
64 |
|
switch ($upper) { |
2543
|
1429 |
|
case 'CASCADE': |
2544
|
973 |
|
case 'SET NULL': |
2545
|
753 |
|
case 'NO ACTION': |
2546
|
577 |
|
case 'RESTRICT': |
2547
|
401 |
|
case 'SET DEFAULT': |
2548
|
1231 |
|
return $upper; |
2549
|
|
|
|
2550
|
|
|
default: |
2551
|
198 |
|
throw new InvalidArgumentException('Invalid foreign key action: ' . $upper); |
2552
|
|
|
} |
2553
|
|
|
} |
2554
|
|
|
|
2555
|
|
|
/** |
2556
|
|
|
* Obtains DBMS specific SQL code portion needed to set the FOREIGN KEY constraint |
2557
|
|
|
* of a field declaration to be used in statements like CREATE TABLE. |
2558
|
|
|
* |
2559
|
|
|
* @return string |
2560
|
|
|
* |
2561
|
|
|
* @throws InvalidArgumentException |
2562
|
|
|
*/ |
2563
|
1182 |
|
public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) |
2564
|
|
|
{ |
2565
|
1182 |
|
$sql = ''; |
2566
|
1182 |
|
if (strlen($foreignKey->getName()) > 0) { |
2567
|
984 |
|
$sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' '; |
2568
|
|
|
} |
2569
|
|
|
|
2570
|
1182 |
|
$sql .= 'FOREIGN KEY ('; |
2571
|
|
|
|
2572
|
1182 |
|
if (count($foreignKey->getLocalColumns()) === 0) { |
2573
|
|
|
throw new InvalidArgumentException("Incomplete definition. 'local' required."); |
2574
|
|
|
} |
2575
|
|
|
|
2576
|
1182 |
|
if (count($foreignKey->getForeignColumns()) === 0) { |
2577
|
|
|
throw new InvalidArgumentException("Incomplete definition. 'foreign' required."); |
2578
|
|
|
} |
2579
|
|
|
|
2580
|
1182 |
|
if (strlen($foreignKey->getForeignTableName()) === 0) { |
2581
|
|
|
throw new InvalidArgumentException("Incomplete definition. 'foreignTable' required."); |
2582
|
|
|
} |
2583
|
|
|
|
2584
|
1182 |
|
return $sql . implode(', ', $foreignKey->getQuotedLocalColumns($this)) |
2585
|
1182 |
|
. ') REFERENCES ' |
2586
|
1182 |
|
. $foreignKey->getQuotedForeignTableName($this) . ' (' |
2587
|
1182 |
|
. implode(', ', $foreignKey->getQuotedForeignColumns($this)) . ')'; |
2588
|
|
|
} |
2589
|
|
|
|
2590
|
|
|
/** |
2591
|
|
|
* Obtains DBMS specific SQL code portion needed to set the UNIQUE constraint |
2592
|
|
|
* of a field declaration to be used in statements like CREATE TABLE. |
2593
|
|
|
* |
2594
|
|
|
* @return string DBMS specific SQL code portion needed to set the UNIQUE constraint |
2595
|
|
|
* of a field declaration. |
2596
|
|
|
*/ |
2597
|
|
|
public function getUniqueFieldDeclarationSQL() |
2598
|
|
|
{ |
2599
|
|
|
return 'UNIQUE'; |
2600
|
|
|
} |
2601
|
|
|
|
2602
|
|
|
/** |
2603
|
|
|
* Obtains DBMS specific SQL code portion needed to set the CHARACTER SET |
2604
|
|
|
* of a field declaration to be used in statements like CREATE TABLE. |
2605
|
|
|
* |
2606
|
|
|
* @param string $charset The name of the charset. |
2607
|
|
|
* |
2608
|
|
|
* @return string DBMS specific SQL code portion needed to set the CHARACTER SET |
2609
|
|
|
* of a field declaration. |
2610
|
|
|
*/ |
2611
|
|
|
public function getColumnCharsetDeclarationSQL($charset) |
|
|
|
|
2612
|
|
|
{ |
2613
|
|
|
return ''; |
2614
|
|
|
} |
2615
|
|
|
|
2616
|
|
|
/** |
2617
|
|
|
* Obtains DBMS specific SQL code portion needed to set the COLLATION |
2618
|
|
|
* of a field declaration to be used in statements like CREATE TABLE. |
2619
|
|
|
* |
2620
|
|
|
* @param string $collation The name of the collation. |
2621
|
|
|
* |
2622
|
|
|
* @return string DBMS specific SQL code portion needed to set the COLLATION |
2623
|
|
|
* of a field declaration. |
2624
|
|
|
*/ |
2625
|
93 |
|
public function getColumnCollationDeclarationSQL($collation) |
2626
|
|
|
{ |
2627
|
93 |
|
return $this->supportsColumnCollation() ? 'COLLATE ' . $collation : ''; |
2628
|
|
|
} |
2629
|
|
|
|
2630
|
|
|
/** |
2631
|
|
|
* Whether the platform prefers sequences for ID generation. |
2632
|
|
|
* Subclasses should override this method to return TRUE if they prefer sequences. |
2633
|
|
|
* |
2634
|
|
|
* @return bool |
2635
|
|
|
*/ |
2636
|
44 |
|
public function prefersSequences() |
2637
|
|
|
{ |
2638
|
44 |
|
return false; |
2639
|
|
|
} |
2640
|
|
|
|
2641
|
|
|
/** |
2642
|
|
|
* Whether the platform prefers identity columns (eg. autoincrement) for ID generation. |
2643
|
|
|
* Subclasses should override this method to return TRUE if they prefer identity columns. |
2644
|
|
|
* |
2645
|
|
|
* @return bool |
2646
|
|
|
*/ |
2647
|
66 |
|
public function prefersIdentityColumns() |
2648
|
|
|
{ |
2649
|
66 |
|
return false; |
2650
|
|
|
} |
2651
|
|
|
|
2652
|
|
|
/** |
2653
|
|
|
* Some platforms need the boolean values to be converted. |
2654
|
|
|
* |
2655
|
|
|
* The default conversion in this implementation converts to integers (false => 0, true => 1). |
2656
|
|
|
* |
2657
|
|
|
* Note: if the input is not a boolean the original input might be returned. |
2658
|
|
|
* |
2659
|
|
|
* There are two contexts when converting booleans: Literals and Prepared Statements. |
2660
|
|
|
* This method should handle the literal case |
2661
|
|
|
* |
2662
|
|
|
* @param mixed $item A boolean or an array of them. |
2663
|
|
|
* |
2664
|
|
|
* @return mixed A boolean database value or an array of them. |
2665
|
|
|
*/ |
2666
|
309 |
|
public function convertBooleans($item) |
2667
|
|
|
{ |
2668
|
309 |
|
if (is_array($item)) { |
2669
|
|
|
foreach ($item as $k => $value) { |
2670
|
|
|
if (! is_bool($value)) { |
2671
|
|
|
continue; |
2672
|
|
|
} |
2673
|
|
|
|
2674
|
|
|
$item[$k] = (int) $value; |
2675
|
|
|
} |
2676
|
309 |
|
} elseif (is_bool($item)) { |
2677
|
287 |
|
$item = (int) $item; |
2678
|
|
|
} |
2679
|
|
|
|
2680
|
309 |
|
return $item; |
2681
|
|
|
} |
2682
|
|
|
|
2683
|
|
|
/** |
2684
|
|
|
* Some platforms have boolean literals that needs to be correctly converted |
2685
|
|
|
* |
2686
|
|
|
* The default conversion tries to convert value into bool "(bool)$item" |
2687
|
|
|
* |
2688
|
|
|
* @param mixed $item |
2689
|
|
|
* |
2690
|
|
|
* @return bool|null |
2691
|
|
|
*/ |
2692
|
484 |
|
public function convertFromBoolean($item) |
2693
|
|
|
{ |
2694
|
484 |
|
return $item === null ? null: (bool) $item; |
2695
|
|
|
} |
2696
|
|
|
|
2697
|
|
|
/** |
2698
|
|
|
* This method should handle the prepared statements case. When there is no |
2699
|
|
|
* distinction, it's OK to use the same method. |
2700
|
|
|
* |
2701
|
|
|
* Note: if the input is not a boolean the original input might be returned. |
2702
|
|
|
* |
2703
|
|
|
* @param mixed $item A boolean or an array of them. |
2704
|
|
|
* |
2705
|
|
|
* @return mixed A boolean database value or an array of them. |
2706
|
|
|
*/ |
2707
|
100 |
|
public function convertBooleansToDatabaseValue($item) |
2708
|
|
|
{ |
2709
|
100 |
|
return $this->convertBooleans($item); |
2710
|
|
|
} |
2711
|
|
|
|
2712
|
|
|
/** |
2713
|
|
|
* Returns the SQL specific for the platform to get the current date. |
2714
|
|
|
* |
2715
|
|
|
* @return string |
2716
|
|
|
*/ |
2717
|
207 |
|
public function getCurrentDateSQL() |
2718
|
|
|
{ |
2719
|
207 |
|
return 'CURRENT_DATE'; |
2720
|
|
|
} |
2721
|
|
|
|
2722
|
|
|
/** |
2723
|
|
|
* Returns the SQL specific for the platform to get the current time. |
2724
|
|
|
* |
2725
|
|
|
* @return string |
2726
|
|
|
*/ |
2727
|
18 |
|
public function getCurrentTimeSQL() |
2728
|
|
|
{ |
2729
|
18 |
|
return 'CURRENT_TIME'; |
2730
|
|
|
} |
2731
|
|
|
|
2732
|
|
|
/** |
2733
|
|
|
* Returns the SQL specific for the platform to get the current timestamp |
2734
|
|
|
* |
2735
|
|
|
* @return string |
2736
|
|
|
*/ |
2737
|
263 |
|
public function getCurrentTimestampSQL() |
2738
|
|
|
{ |
2739
|
263 |
|
return 'CURRENT_TIMESTAMP'; |
2740
|
|
|
} |
2741
|
|
|
|
2742
|
|
|
/** |
2743
|
|
|
* Returns the SQL for a given transaction isolation level Connection constant. |
2744
|
|
|
* |
2745
|
|
|
* @param int $level |
2746
|
|
|
* |
2747
|
|
|
* @return string |
2748
|
|
|
* |
2749
|
|
|
* @throws InvalidArgumentException |
2750
|
|
|
*/ |
2751
|
132 |
|
protected function _getTransactionIsolationLevelSQL($level) |
2752
|
|
|
{ |
2753
|
6 |
|
switch ($level) { |
2754
|
126 |
|
case TransactionIsolationLevel::READ_UNCOMMITTED: |
2755
|
132 |
|
return 'READ UNCOMMITTED'; |
2756
|
|
|
|
2757
|
126 |
|
case TransactionIsolationLevel::READ_COMMITTED: |
2758
|
132 |
|
return 'READ COMMITTED'; |
2759
|
|
|
|
2760
|
126 |
|
case TransactionIsolationLevel::REPEATABLE_READ: |
2761
|
132 |
|
return 'REPEATABLE READ'; |
2762
|
|
|
|
2763
|
126 |
|
case TransactionIsolationLevel::SERIALIZABLE: |
2764
|
132 |
|
return 'SERIALIZABLE'; |
2765
|
|
|
|
2766
|
|
|
default: |
2767
|
|
|
throw new InvalidArgumentException('Invalid isolation level:' . $level); |
2768
|
|
|
} |
2769
|
|
|
} |
2770
|
|
|
|
2771
|
|
|
/** |
2772
|
|
|
* @return string |
2773
|
|
|
* |
2774
|
|
|
* @throws DBALException If not supported on this platform. |
2775
|
|
|
*/ |
2776
|
1 |
|
public function getListDatabasesSQL() |
2777
|
|
|
{ |
2778
|
1 |
|
throw DBALException::notSupported(__METHOD__); |
2779
|
|
|
} |
2780
|
|
|
|
2781
|
|
|
/** |
2782
|
|
|
* Returns the SQL statement for retrieving the namespaces defined in the database. |
2783
|
|
|
* |
2784
|
|
|
* @return string |
2785
|
|
|
* |
2786
|
|
|
* @throws DBALException If not supported on this platform. |
2787
|
|
|
*/ |
2788
|
|
|
public function getListNamespacesSQL() |
2789
|
|
|
{ |
2790
|
|
|
throw DBALException::notSupported(__METHOD__); |
2791
|
|
|
} |
2792
|
|
|
|
2793
|
|
|
/** |
2794
|
|
|
* @param string $database |
2795
|
|
|
* |
2796
|
|
|
* @return string |
2797
|
|
|
* |
2798
|
|
|
* @throws DBALException If not supported on this platform. |
2799
|
|
|
*/ |
2800
|
|
|
public function getListSequencesSQL($database) |
2801
|
|
|
{ |
2802
|
|
|
throw DBALException::notSupported(__METHOD__); |
2803
|
|
|
} |
2804
|
|
|
|
2805
|
|
|
/** |
2806
|
|
|
* @param string $table |
2807
|
|
|
* |
2808
|
|
|
* @return string |
2809
|
|
|
* |
2810
|
|
|
* @throws DBALException If not supported on this platform. |
2811
|
|
|
*/ |
2812
|
|
|
public function getListTableConstraintsSQL($table) |
2813
|
|
|
{ |
2814
|
|
|
throw DBALException::notSupported(__METHOD__); |
2815
|
|
|
} |
2816
|
|
|
|
2817
|
|
|
/** |
2818
|
|
|
* @param string $table |
2819
|
|
|
* @param string|null $database |
2820
|
|
|
* |
2821
|
|
|
* @return string |
2822
|
|
|
* |
2823
|
|
|
* @throws DBALException If not supported on this platform. |
2824
|
|
|
*/ |
2825
|
|
|
public function getListTableColumnsSQL($table, $database = null) |
2826
|
|
|
{ |
2827
|
|
|
throw DBALException::notSupported(__METHOD__); |
2828
|
|
|
} |
2829
|
|
|
|
2830
|
|
|
/** |
2831
|
|
|
* @return string |
2832
|
|
|
* |
2833
|
|
|
* @throws DBALException If not supported on this platform. |
2834
|
|
|
*/ |
2835
|
|
|
public function getListTablesSQL() |
2836
|
|
|
{ |
2837
|
|
|
throw DBALException::notSupported(__METHOD__); |
2838
|
|
|
} |
2839
|
|
|
|
2840
|
|
|
/** |
2841
|
|
|
* @return string |
2842
|
|
|
* |
2843
|
|
|
* @throws DBALException If not supported on this platform. |
2844
|
|
|
*/ |
2845
|
|
|
public function getListUsersSQL() |
2846
|
|
|
{ |
2847
|
|
|
throw DBALException::notSupported(__METHOD__); |
2848
|
|
|
} |
2849
|
|
|
|
2850
|
|
|
/** |
2851
|
|
|
* Returns the SQL to list all views of a database or user. |
2852
|
|
|
* |
2853
|
|
|
* @param string $database |
2854
|
|
|
* |
2855
|
|
|
* @return string |
2856
|
|
|
* |
2857
|
|
|
* @throws DBALException If not supported on this platform. |
2858
|
|
|
*/ |
2859
|
|
|
public function getListViewsSQL($database) |
2860
|
|
|
{ |
2861
|
|
|
throw DBALException::notSupported(__METHOD__); |
2862
|
|
|
} |
2863
|
|
|
|
2864
|
|
|
/** |
2865
|
|
|
* Returns the list of indexes for the current database. |
2866
|
|
|
* |
2867
|
|
|
* The current database parameter is optional but will always be passed |
2868
|
|
|
* when using the SchemaManager API and is the database the given table is in. |
2869
|
|
|
* |
2870
|
|
|
* Attention: Some platforms only support currentDatabase when they |
2871
|
|
|
* are connected with that database. Cross-database information schema |
2872
|
|
|
* requests may be impossible. |
2873
|
|
|
* |
2874
|
|
|
* @param string $table |
2875
|
|
|
* @param string $currentDatabase |
2876
|
|
|
* |
2877
|
|
|
* @return string |
2878
|
|
|
* |
2879
|
|
|
* @throws DBALException If not supported on this platform. |
2880
|
|
|
*/ |
2881
|
|
|
public function getListTableIndexesSQL($table, $currentDatabase = null) |
|
|
|
|
2882
|
|
|
{ |
2883
|
|
|
throw DBALException::notSupported(__METHOD__); |
2884
|
|
|
} |
2885
|
|
|
|
2886
|
|
|
/** |
2887
|
|
|
* @param string $table |
2888
|
|
|
* |
2889
|
|
|
* @return string |
2890
|
|
|
* |
2891
|
|
|
* @throws DBALException If not supported on this platform. |
2892
|
|
|
*/ |
2893
|
|
|
public function getListTableForeignKeysSQL($table) |
2894
|
|
|
{ |
2895
|
|
|
throw DBALException::notSupported(__METHOD__); |
2896
|
|
|
} |
2897
|
|
|
|
2898
|
|
|
/** |
2899
|
|
|
* @param string $name |
2900
|
|
|
* @param string $sql |
2901
|
|
|
* |
2902
|
|
|
* @return string |
2903
|
|
|
* |
2904
|
|
|
* @throws DBALException If not supported on this platform. |
2905
|
|
|
*/ |
2906
|
|
|
public function getCreateViewSQL($name, $sql) |
2907
|
|
|
{ |
2908
|
|
|
throw DBALException::notSupported(__METHOD__); |
2909
|
|
|
} |
2910
|
|
|
|
2911
|
|
|
/** |
2912
|
|
|
* @param string $name |
2913
|
|
|
* |
2914
|
|
|
* @return string |
2915
|
|
|
* |
2916
|
|
|
* @throws DBALException If not supported on this platform. |
2917
|
|
|
*/ |
2918
|
|
|
public function getDropViewSQL($name) |
2919
|
|
|
{ |
2920
|
|
|
throw DBALException::notSupported(__METHOD__); |
2921
|
|
|
} |
2922
|
|
|
|
2923
|
|
|
/** |
2924
|
|
|
* Returns the SQL snippet to drop an existing sequence. |
2925
|
|
|
* |
2926
|
|
|
* @param Sequence|string $sequence |
2927
|
|
|
* |
2928
|
|
|
* @return string |
2929
|
|
|
* |
2930
|
|
|
* @throws DBALException If not supported on this platform. |
2931
|
|
|
*/ |
2932
|
|
|
public function getDropSequenceSQL($sequence) |
|
|
|
|
2933
|
|
|
{ |
2934
|
|
|
throw DBALException::notSupported(__METHOD__); |
2935
|
|
|
} |
2936
|
|
|
|
2937
|
|
|
/** |
2938
|
|
|
* @param string $sequenceName |
2939
|
|
|
* |
2940
|
|
|
* @return string |
2941
|
|
|
* |
2942
|
|
|
* @throws DBALException If not supported on this platform. |
2943
|
|
|
*/ |
2944
|
|
|
public function getSequenceNextValSQL($sequenceName) |
|
|
|
|
2945
|
|
|
{ |
2946
|
|
|
throw DBALException::notSupported(__METHOD__); |
2947
|
|
|
} |
2948
|
|
|
|
2949
|
|
|
/** |
2950
|
|
|
* Returns the SQL to create a new database. |
2951
|
|
|
* |
2952
|
|
|
* @param string $database The name of the database that should be created. |
2953
|
|
|
* |
2954
|
|
|
* @return string |
2955
|
|
|
* |
2956
|
|
|
* @throws DBALException If not supported on this platform. |
2957
|
|
|
*/ |
2958
|
22 |
|
public function getCreateDatabaseSQL($database) |
2959
|
|
|
{ |
2960
|
22 |
|
throw DBALException::notSupported(__METHOD__); |
2961
|
|
|
} |
2962
|
|
|
|
2963
|
|
|
/** |
2964
|
|
|
* Returns the SQL to set the transaction isolation level. |
2965
|
|
|
* |
2966
|
|
|
* @param int $level |
2967
|
|
|
* |
2968
|
|
|
* @return string |
2969
|
|
|
* |
2970
|
|
|
* @throws DBALException If not supported on this platform. |
2971
|
|
|
*/ |
2972
|
|
|
public function getSetTransactionIsolationSQL($level) |
2973
|
|
|
{ |
2974
|
|
|
throw DBALException::notSupported(__METHOD__); |
2975
|
|
|
} |
2976
|
|
|
|
2977
|
|
|
/** |
2978
|
|
|
* Obtains DBMS specific SQL to be used to create datetime fields in |
2979
|
|
|
* statements like CREATE TABLE. |
2980
|
|
|
* |
2981
|
|
|
* @param mixed[] $fieldDeclaration |
2982
|
|
|
* |
2983
|
|
|
* @return string |
2984
|
|
|
* |
2985
|
|
|
* @throws DBALException If not supported on this platform. |
2986
|
|
|
*/ |
2987
|
|
|
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) |
2988
|
|
|
{ |
2989
|
|
|
throw DBALException::notSupported(__METHOD__); |
2990
|
|
|
} |
2991
|
|
|
|
2992
|
|
|
/** |
2993
|
|
|
* Obtains DBMS specific SQL to be used to create datetime with timezone offset fields. |
2994
|
|
|
* |
2995
|
|
|
* @param mixed[] $fieldDeclaration |
2996
|
|
|
* |
2997
|
|
|
* @return string |
2998
|
|
|
*/ |
2999
|
210 |
|
public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) |
3000
|
|
|
{ |
3001
|
210 |
|
return $this->getDateTimeTypeDeclarationSQL($fieldDeclaration); |
3002
|
|
|
} |
3003
|
|
|
|
3004
|
|
|
/** |
3005
|
|
|
* Obtains DBMS specific SQL to be used to create date fields in statements |
3006
|
|
|
* like CREATE TABLE. |
3007
|
|
|
* |
3008
|
|
|
* @param mixed[] $fieldDeclaration |
3009
|
|
|
* |
3010
|
|
|
* @return string |
3011
|
|
|
* |
3012
|
|
|
* @throws DBALException If not supported on this platform. |
3013
|
|
|
*/ |
3014
|
|
|
public function getDateTypeDeclarationSQL(array $fieldDeclaration) |
3015
|
|
|
{ |
3016
|
|
|
throw DBALException::notSupported(__METHOD__); |
3017
|
|
|
} |
3018
|
|
|
|
3019
|
|
|
/** |
3020
|
|
|
* Obtains DBMS specific SQL to be used to create time fields in statements |
3021
|
|
|
* like CREATE TABLE. |
3022
|
|
|
* |
3023
|
|
|
* @param mixed[] $fieldDeclaration |
3024
|
|
|
* |
3025
|
|
|
* @return string |
3026
|
|
|
* |
3027
|
|
|
* @throws DBALException If not supported on this platform. |
3028
|
|
|
*/ |
3029
|
|
|
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) |
3030
|
|
|
{ |
3031
|
|
|
throw DBALException::notSupported(__METHOD__); |
3032
|
|
|
} |
3033
|
|
|
|
3034
|
|
|
/** |
3035
|
|
|
* @param mixed[] $fieldDeclaration |
3036
|
|
|
* |
3037
|
|
|
* @return string |
3038
|
|
|
*/ |
3039
|
1079 |
|
public function getFloatDeclarationSQL(array $fieldDeclaration) |
3040
|
|
|
{ |
3041
|
1079 |
|
return 'DOUBLE PRECISION'; |
3042
|
|
|
} |
3043
|
|
|
|
3044
|
|
|
/** |
3045
|
|
|
* Gets the default transaction isolation level of the platform. |
3046
|
|
|
* |
3047
|
|
|
* @see TransactionIsolationLevel |
3048
|
|
|
* |
3049
|
|
|
* @return int The default isolation level. |
3050
|
|
|
*/ |
3051
|
|
|
public function getDefaultTransactionIsolationLevel() |
3052
|
|
|
{ |
3053
|
|
|
return TransactionIsolationLevel::READ_COMMITTED; |
3054
|
|
|
} |
3055
|
|
|
|
3056
|
|
|
/* supports*() methods */ |
3057
|
|
|
|
3058
|
|
|
/** |
3059
|
|
|
* Whether the platform supports sequences. |
3060
|
|
|
* |
3061
|
|
|
* @return bool |
3062
|
|
|
*/ |
3063
|
118 |
|
public function supportsSequences() |
3064
|
|
|
{ |
3065
|
118 |
|
return false; |
3066
|
|
|
} |
3067
|
|
|
|
3068
|
|
|
/** |
3069
|
|
|
* Whether the platform supports identity columns. |
3070
|
|
|
* |
3071
|
|
|
* Identity columns are columns that receive an auto-generated value from the |
3072
|
|
|
* database on insert of a row. |
3073
|
|
|
* |
3074
|
|
|
* @return bool |
3075
|
|
|
*/ |
3076
|
24 |
|
public function supportsIdentityColumns() |
3077
|
|
|
{ |
3078
|
24 |
|
return false; |
3079
|
|
|
} |
3080
|
|
|
|
3081
|
|
|
/** |
3082
|
|
|
* Whether the platform emulates identity columns through sequences. |
3083
|
|
|
* |
3084
|
|
|
* Some platforms that do not support identity columns natively |
3085
|
|
|
* but support sequences can emulate identity columns by using |
3086
|
|
|
* sequences. |
3087
|
|
|
* |
3088
|
|
|
* @return bool |
3089
|
|
|
*/ |
3090
|
170 |
|
public function usesSequenceEmulatedIdentityColumns() |
3091
|
|
|
{ |
3092
|
170 |
|
return false; |
3093
|
|
|
} |
3094
|
|
|
|
3095
|
|
|
/** |
3096
|
|
|
* Returns the name of the sequence for a particular identity column in a particular table. |
3097
|
|
|
* |
3098
|
|
|
* @see usesSequenceEmulatedIdentityColumns |
3099
|
|
|
* |
3100
|
|
|
* @param string $tableName The name of the table to return the sequence name for. |
3101
|
|
|
* @param string $columnName The name of the identity column in the table to return the sequence name for. |
3102
|
|
|
* |
3103
|
|
|
* @return string |
3104
|
|
|
* |
3105
|
|
|
* @throws DBALException If not supported on this platform. |
3106
|
|
|
*/ |
3107
|
154 |
|
public function getIdentitySequenceName($tableName, $columnName) |
3108
|
|
|
{ |
3109
|
154 |
|
throw DBALException::notSupported(__METHOD__); |
3110
|
|
|
} |
3111
|
|
|
|
3112
|
|
|
/** |
3113
|
|
|
* Whether the platform supports indexes. |
3114
|
|
|
* |
3115
|
|
|
* @return bool |
3116
|
|
|
*/ |
3117
|
22 |
|
public function supportsIndexes() |
3118
|
|
|
{ |
3119
|
22 |
|
return true; |
3120
|
|
|
} |
3121
|
|
|
|
3122
|
|
|
/** |
3123
|
|
|
* Whether the platform supports partial indexes. |
3124
|
|
|
* |
3125
|
|
|
* @return bool |
3126
|
|
|
*/ |
3127
|
2411 |
|
public function supportsPartialIndexes() |
3128
|
|
|
{ |
3129
|
2411 |
|
return false; |
3130
|
|
|
} |
3131
|
|
|
|
3132
|
|
|
/** |
3133
|
|
|
* Whether the platform supports indexes with column length definitions. |
3134
|
|
|
*/ |
3135
|
3612 |
|
public function supportsColumnLengthIndexes() : bool |
3136
|
|
|
{ |
3137
|
3612 |
|
return false; |
3138
|
|
|
} |
3139
|
|
|
|
3140
|
|
|
/** |
3141
|
|
|
* Whether the platform supports altering tables. |
3142
|
|
|
* |
3143
|
|
|
* @return bool |
3144
|
|
|
*/ |
3145
|
44 |
|
public function supportsAlterTable() |
3146
|
|
|
{ |
3147
|
44 |
|
return true; |
3148
|
|
|
} |
3149
|
|
|
|
3150
|
|
|
/** |
3151
|
|
|
* Whether the platform supports transactions. |
3152
|
|
|
* |
3153
|
|
|
* @return bool |
3154
|
|
|
*/ |
3155
|
22 |
|
public function supportsTransactions() |
3156
|
|
|
{ |
3157
|
22 |
|
return true; |
3158
|
|
|
} |
3159
|
|
|
|
3160
|
|
|
/** |
3161
|
|
|
* Whether the platform supports savepoints. |
3162
|
|
|
* |
3163
|
|
|
* @return bool |
3164
|
|
|
*/ |
3165
|
240 |
|
public function supportsSavepoints() |
3166
|
|
|
{ |
3167
|
240 |
|
return true; |
3168
|
|
|
} |
3169
|
|
|
|
3170
|
|
|
/** |
3171
|
|
|
* Whether the platform supports releasing savepoints. |
3172
|
|
|
* |
3173
|
|
|
* @return bool |
3174
|
|
|
*/ |
3175
|
40 |
|
public function supportsReleaseSavepoints() |
3176
|
|
|
{ |
3177
|
40 |
|
return $this->supportsSavepoints(); |
3178
|
|
|
} |
3179
|
|
|
|
3180
|
|
|
/** |
3181
|
|
|
* Whether the platform supports primary key constraints. |
3182
|
|
|
* |
3183
|
|
|
* @return bool |
3184
|
|
|
*/ |
3185
|
22 |
|
public function supportsPrimaryConstraints() |
3186
|
|
|
{ |
3187
|
22 |
|
return true; |
3188
|
|
|
} |
3189
|
|
|
|
3190
|
|
|
/** |
3191
|
|
|
* Whether the platform supports foreign key constraints. |
3192
|
|
|
* |
3193
|
|
|
* @return bool |
3194
|
|
|
*/ |
3195
|
6300 |
|
public function supportsForeignKeyConstraints() |
3196
|
|
|
{ |
3197
|
6300 |
|
return true; |
3198
|
|
|
} |
3199
|
|
|
|
3200
|
|
|
/** |
3201
|
|
|
* Whether foreign key constraints can be dropped. |
3202
|
|
|
* |
3203
|
|
|
* If false, then getDropForeignKeySQL() throws exception. |
3204
|
|
|
*/ |
3205
|
470 |
|
public function supportsCreateDropForeignKeyConstraints() : bool |
3206
|
|
|
{ |
3207
|
470 |
|
return true; |
3208
|
|
|
} |
3209
|
|
|
|
3210
|
|
|
/** |
3211
|
|
|
* Whether this platform supports onUpdate in foreign key constraints. |
3212
|
|
|
* |
3213
|
|
|
* @return bool |
3214
|
|
|
*/ |
3215
|
1257 |
|
public function supportsForeignKeyOnUpdate() |
3216
|
|
|
{ |
3217
|
1257 |
|
return $this->supportsForeignKeyConstraints(); |
3218
|
|
|
} |
3219
|
|
|
|
3220
|
|
|
/** |
3221
|
|
|
* Whether the platform supports database schemas. |
3222
|
|
|
* |
3223
|
|
|
* @return bool |
3224
|
|
|
*/ |
3225
|
186 |
|
public function supportsSchemas() |
3226
|
|
|
{ |
3227
|
186 |
|
return false; |
3228
|
|
|
} |
3229
|
|
|
|
3230
|
|
|
/** |
3231
|
|
|
* Whether this platform can emulate schemas. |
3232
|
|
|
* |
3233
|
|
|
* Platforms that either support or emulate schemas don't automatically |
3234
|
|
|
* filter a schema for the namespaced elements in {@link |
3235
|
|
|
* AbstractManager#createSchema}. |
3236
|
|
|
* |
3237
|
|
|
* @return bool |
3238
|
|
|
*/ |
3239
|
22 |
|
public function canEmulateSchemas() |
3240
|
|
|
{ |
3241
|
22 |
|
return false; |
3242
|
|
|
} |
3243
|
|
|
|
3244
|
|
|
/** |
3245
|
|
|
* Returns the default schema name. |
3246
|
|
|
* |
3247
|
|
|
* @return string |
3248
|
|
|
* |
3249
|
|
|
* @throws DBALException If not supported on this platform. |
3250
|
|
|
*/ |
3251
|
|
|
public function getDefaultSchemaName() |
3252
|
|
|
{ |
3253
|
|
|
throw DBALException::notSupported(__METHOD__); |
3254
|
|
|
} |
3255
|
|
|
|
3256
|
|
|
/** |
3257
|
|
|
* Whether this platform supports create database. |
3258
|
|
|
* |
3259
|
|
|
* Some databases don't allow to create and drop databases at all or only with certain tools. |
3260
|
|
|
* |
3261
|
|
|
* @return bool |
3262
|
|
|
*/ |
3263
|
69 |
|
public function supportsCreateDropDatabase() |
3264
|
|
|
{ |
3265
|
69 |
|
return true; |
3266
|
|
|
} |
3267
|
|
|
|
3268
|
|
|
/** |
3269
|
|
|
* Whether the platform supports getting the affected rows of a recent update/delete type query. |
3270
|
|
|
* |
3271
|
|
|
* @return bool |
3272
|
|
|
*/ |
3273
|
22 |
|
public function supportsGettingAffectedRows() |
3274
|
|
|
{ |
3275
|
22 |
|
return true; |
3276
|
|
|
} |
3277
|
|
|
|
3278
|
|
|
/** |
3279
|
|
|
* Whether this platform support to add inline column comments as postfix. |
3280
|
|
|
* |
3281
|
|
|
* @return bool |
3282
|
|
|
*/ |
3283
|
2750 |
|
public function supportsInlineColumnComments() |
3284
|
|
|
{ |
3285
|
2750 |
|
return false; |
3286
|
|
|
} |
3287
|
|
|
|
3288
|
|
|
/** |
3289
|
|
|
* Whether this platform support the proprietary syntax "COMMENT ON asset". |
3290
|
|
|
* |
3291
|
|
|
* @return bool |
3292
|
|
|
*/ |
3293
|
4587 |
|
public function supportsCommentOnStatement() |
3294
|
|
|
{ |
3295
|
4587 |
|
return false; |
3296
|
|
|
} |
3297
|
|
|
|
3298
|
|
|
/** |
3299
|
|
|
* Does this platform have native guid type. |
3300
|
|
|
* |
3301
|
|
|
* @return bool |
3302
|
|
|
*/ |
3303
|
6598 |
|
public function hasNativeGuidType() |
3304
|
|
|
{ |
3305
|
6598 |
|
return false; |
3306
|
|
|
} |
3307
|
|
|
|
3308
|
|
|
/** |
3309
|
|
|
* Does this platform have native JSON type. |
3310
|
|
|
* |
3311
|
|
|
* @return bool |
3312
|
|
|
*/ |
3313
|
7711 |
|
public function hasNativeJsonType() |
3314
|
|
|
{ |
3315
|
7711 |
|
return false; |
3316
|
|
|
} |
3317
|
|
|
|
3318
|
|
|
/** |
3319
|
|
|
* @deprecated |
3320
|
|
|
* |
3321
|
|
|
* @return string |
3322
|
|
|
* |
3323
|
|
|
* @todo Remove in 3.0 |
3324
|
|
|
*/ |
3325
|
|
|
public function getIdentityColumnNullInsertSQL() |
3326
|
|
|
{ |
3327
|
|
|
return ''; |
3328
|
|
|
} |
3329
|
|
|
|
3330
|
|
|
/** |
3331
|
|
|
* Whether this platform supports views. |
3332
|
|
|
* |
3333
|
|
|
* @return bool |
3334
|
|
|
*/ |
3335
|
22 |
|
public function supportsViews() |
3336
|
|
|
{ |
3337
|
22 |
|
return true; |
3338
|
|
|
} |
3339
|
|
|
|
3340
|
|
|
/** |
3341
|
|
|
* Does this platform support column collation? |
3342
|
|
|
* |
3343
|
|
|
* @return bool |
3344
|
|
|
*/ |
3345
|
|
|
public function supportsColumnCollation() |
3346
|
|
|
{ |
3347
|
|
|
return false; |
3348
|
|
|
} |
3349
|
|
|
|
3350
|
|
|
/** |
3351
|
|
|
* Gets the format string, as accepted by the date() function, that describes |
3352
|
|
|
* the format of a stored datetime value of this platform. |
3353
|
|
|
* |
3354
|
|
|
* @return string The format string. |
3355
|
|
|
*/ |
3356
|
374 |
|
public function getDateTimeFormatString() |
3357
|
|
|
{ |
3358
|
374 |
|
return 'Y-m-d H:i:s'; |
3359
|
|
|
} |
3360
|
|
|
|
3361
|
|
|
/** |
3362
|
|
|
* Gets the format string, as accepted by the date() function, that describes |
3363
|
|
|
* the format of a stored datetime with timezone value of this platform. |
3364
|
|
|
* |
3365
|
|
|
* @return string The format string. |
3366
|
|
|
*/ |
3367
|
146 |
|
public function getDateTimeTzFormatString() |
3368
|
|
|
{ |
3369
|
146 |
|
return 'Y-m-d H:i:s'; |
3370
|
|
|
} |
3371
|
|
|
|
3372
|
|
|
/** |
3373
|
|
|
* Gets the format string, as accepted by the date() function, that describes |
3374
|
|
|
* the format of a stored date value of this platform. |
3375
|
|
|
* |
3376
|
|
|
* @return string The format string. |
3377
|
|
|
*/ |
3378
|
151 |
|
public function getDateFormatString() |
3379
|
|
|
{ |
3380
|
151 |
|
return 'Y-m-d'; |
3381
|
|
|
} |
3382
|
|
|
|
3383
|
|
|
/** |
3384
|
|
|
* Gets the format string, as accepted by the date() function, that describes |
3385
|
|
|
* the format of a stored time value of this platform. |
3386
|
|
|
* |
3387
|
|
|
* @return string The format string. |
3388
|
|
|
*/ |
3389
|
129 |
|
public function getTimeFormatString() |
3390
|
|
|
{ |
3391
|
129 |
|
return 'H:i:s'; |
3392
|
|
|
} |
3393
|
|
|
|
3394
|
|
|
/** |
3395
|
|
|
* Adds an driver-specific LIMIT clause to the query. |
3396
|
|
|
* |
3397
|
|
|
* @param string $query |
3398
|
|
|
* @param int|null $limit |
3399
|
|
|
* @param int|null $offset |
3400
|
|
|
* |
3401
|
|
|
* @return string |
3402
|
|
|
* |
3403
|
|
|
* @throws DBALException |
3404
|
|
|
*/ |
3405
|
1562 |
|
final public function modifyLimitQuery($query, $limit, $offset = null) |
3406
|
|
|
{ |
3407
|
1562 |
|
if ($limit !== null) { |
3408
|
1188 |
|
$limit = (int) $limit; |
3409
|
|
|
} |
3410
|
|
|
|
3411
|
1562 |
|
$offset = (int) $offset; |
3412
|
|
|
|
3413
|
1562 |
|
if ($offset < 0) { |
3414
|
|
|
throw new DBALException(sprintf( |
3415
|
|
|
'Offset must be a positive integer or zero, %d given', |
3416
|
|
|
$offset |
3417
|
|
|
)); |
3418
|
|
|
} |
3419
|
|
|
|
3420
|
1562 |
|
if ($offset > 0 && ! $this->supportsLimitOffset()) { |
3421
|
|
|
throw new DBALException(sprintf( |
3422
|
|
|
'Platform %s does not support offset values in limit queries.', |
3423
|
|
|
$this->getName() |
3424
|
|
|
)); |
3425
|
|
|
} |
3426
|
|
|
|
3427
|
1562 |
|
return $this->doModifyLimitQuery($query, $limit, $offset); |
3428
|
|
|
} |
3429
|
|
|
|
3430
|
|
|
/** |
3431
|
|
|
* Adds an platform-specific LIMIT clause to the query. |
3432
|
|
|
* |
3433
|
|
|
* @param string $query |
3434
|
|
|
* @param int|null $limit |
3435
|
|
|
* @param int|null $offset |
3436
|
|
|
* |
3437
|
|
|
* @return string |
3438
|
|
|
*/ |
3439
|
246 |
|
protected function doModifyLimitQuery($query, $limit, $offset) |
3440
|
|
|
{ |
3441
|
246 |
|
if ($limit !== null) { |
3442
|
174 |
|
$query .= ' LIMIT ' . $limit; |
3443
|
|
|
} |
3444
|
|
|
|
3445
|
246 |
|
if ($offset > 0) { |
3446
|
42 |
|
$query .= ' OFFSET ' . $offset; |
3447
|
|
|
} |
3448
|
|
|
|
3449
|
246 |
|
return $query; |
3450
|
|
|
} |
3451
|
|
|
|
3452
|
|
|
/** |
3453
|
|
|
* Whether the database platform support offsets in modify limit clauses. |
3454
|
|
|
* |
3455
|
|
|
* @return bool |
3456
|
|
|
*/ |
3457
|
338 |
|
public function supportsLimitOffset() |
3458
|
|
|
{ |
3459
|
338 |
|
return true; |
3460
|
|
|
} |
3461
|
|
|
|
3462
|
|
|
/** |
3463
|
|
|
* Gets the character casing of a column in an SQL result set of this platform. |
3464
|
|
|
* |
3465
|
|
|
* @param string $column The column name for which to get the correct character casing. |
3466
|
|
|
* |
3467
|
|
|
* @return string The column name in the character casing used in SQL result sets. |
3468
|
|
|
*/ |
3469
|
|
|
public function getSQLResultCasing($column) |
3470
|
|
|
{ |
3471
|
|
|
return $column; |
3472
|
|
|
} |
3473
|
|
|
|
3474
|
|
|
/** |
3475
|
|
|
* Makes any fixes to a name of a schema element (table, sequence, ...) that are required |
3476
|
|
|
* by restrictions of the platform, like a maximum length. |
3477
|
|
|
* |
3478
|
|
|
* @param string $schemaElementName |
3479
|
|
|
* |
3480
|
|
|
* @return string |
3481
|
|
|
*/ |
3482
|
|
|
public function fixSchemaElementName($schemaElementName) |
3483
|
|
|
{ |
3484
|
|
|
return $schemaElementName; |
3485
|
|
|
} |
3486
|
|
|
|
3487
|
|
|
/** |
3488
|
|
|
* Maximum length of any given database identifier, like tables or column names. |
3489
|
|
|
* |
3490
|
|
|
* @return int |
3491
|
|
|
*/ |
3492
|
386 |
|
public function getMaxIdentifierLength() |
3493
|
|
|
{ |
3494
|
386 |
|
return 63; |
3495
|
|
|
} |
3496
|
|
|
|
3497
|
|
|
/** |
3498
|
|
|
* Returns the insert SQL for an empty insert statement. |
3499
|
|
|
* |
3500
|
|
|
* @param string $tableName |
3501
|
|
|
* @param string $identifierColumnName |
3502
|
|
|
* |
3503
|
|
|
* @return string |
3504
|
|
|
*/ |
3505
|
14 |
|
public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName) |
3506
|
|
|
{ |
3507
|
14 |
|
return 'INSERT INTO ' . $tableName . ' (' . $identifierColumnName . ') VALUES (null)'; |
3508
|
|
|
} |
3509
|
|
|
|
3510
|
|
|
/** |
3511
|
|
|
* Generates a Truncate Table SQL statement for a given table. |
3512
|
|
|
* |
3513
|
|
|
* Cascade is not supported on many platforms but would optionally cascade the truncate by |
3514
|
|
|
* following the foreign keys. |
3515
|
|
|
* |
3516
|
|
|
* @param string $tableName |
3517
|
|
|
* @param bool $cascade |
3518
|
|
|
* |
3519
|
|
|
* @return string |
3520
|
|
|
*/ |
3521
|
174 |
|
public function getTruncateTableSQL($tableName, $cascade = false) |
|
|
|
|
3522
|
|
|
{ |
3523
|
174 |
|
$tableIdentifier = new Identifier($tableName); |
3524
|
|
|
|
3525
|
174 |
|
return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this); |
3526
|
|
|
} |
3527
|
|
|
|
3528
|
|
|
/** |
3529
|
|
|
* This is for test reasons, many vendors have special requirements for dummy statements. |
3530
|
|
|
* |
3531
|
|
|
* @return string |
3532
|
|
|
*/ |
3533
|
174 |
|
public function getDummySelectSQL() |
3534
|
|
|
{ |
3535
|
174 |
|
$expression = func_num_args() > 0 ? func_get_arg(0) : '1'; |
3536
|
|
|
|
3537
|
174 |
|
return sprintf('SELECT %s', $expression); |
3538
|
|
|
} |
3539
|
|
|
|
3540
|
|
|
/** |
3541
|
|
|
* Returns the SQL to create a new savepoint. |
3542
|
|
|
* |
3543
|
|
|
* @param string $savepoint |
3544
|
|
|
* |
3545
|
|
|
* @return string |
3546
|
|
|
*/ |
3547
|
19 |
|
public function createSavePoint($savepoint) |
3548
|
|
|
{ |
3549
|
19 |
|
return 'SAVEPOINT ' . $savepoint; |
3550
|
|
|
} |
3551
|
|
|
|
3552
|
|
|
/** |
3553
|
|
|
* Returns the SQL to release a savepoint. |
3554
|
|
|
* |
3555
|
|
|
* @param string $savepoint |
3556
|
|
|
* |
3557
|
|
|
* @return string |
3558
|
|
|
*/ |
3559
|
18 |
|
public function releaseSavePoint($savepoint) |
3560
|
|
|
{ |
3561
|
18 |
|
return 'RELEASE SAVEPOINT ' . $savepoint; |
3562
|
|
|
} |
3563
|
|
|
|
3564
|
|
|
/** |
3565
|
|
|
* Returns the SQL to rollback a savepoint. |
3566
|
|
|
* |
3567
|
|
|
* @param string $savepoint |
3568
|
|
|
* |
3569
|
|
|
* @return string |
3570
|
|
|
*/ |
3571
|
19 |
|
public function rollbackSavePoint($savepoint) |
3572
|
|
|
{ |
3573
|
19 |
|
return 'ROLLBACK TO SAVEPOINT ' . $savepoint; |
3574
|
|
|
} |
3575
|
|
|
|
3576
|
|
|
/** |
3577
|
|
|
* Returns the keyword list instance of this platform. |
3578
|
|
|
* |
3579
|
|
|
* @return KeywordList |
3580
|
|
|
* |
3581
|
|
|
* @throws DBALException If no keyword list is specified. |
3582
|
|
|
*/ |
3583
|
15793 |
|
final public function getReservedKeywordsList() |
3584
|
|
|
{ |
3585
|
|
|
// Check for an existing instantiation of the keywords class. |
3586
|
15793 |
|
if ($this->_keywords !== null) { |
3587
|
15023 |
|
return $this->_keywords; |
3588
|
|
|
} |
3589
|
|
|
|
3590
|
11765 |
|
$class = $this->getReservedKeywordsClass(); |
3591
|
11765 |
|
$keywords = new $class(); |
3592
|
11765 |
|
if (! $keywords instanceof KeywordList) { |
3593
|
|
|
throw DBALException::notSupported(__METHOD__); |
3594
|
|
|
} |
3595
|
|
|
|
3596
|
|
|
// Store the instance so it doesn't need to be generated on every request. |
3597
|
11765 |
|
$this->_keywords = $keywords; |
3598
|
|
|
|
3599
|
11765 |
|
return $keywords; |
3600
|
|
|
} |
3601
|
|
|
|
3602
|
|
|
/** |
3603
|
|
|
* Returns the class name of the reserved keywords list. |
3604
|
|
|
* |
3605
|
|
|
* @return string |
3606
|
|
|
* |
3607
|
|
|
* @throws DBALException If not supported on this platform. |
3608
|
|
|
*/ |
3609
|
|
|
protected function getReservedKeywordsClass() |
3610
|
|
|
{ |
3611
|
|
|
throw DBALException::notSupported(__METHOD__); |
3612
|
|
|
} |
3613
|
|
|
|
3614
|
|
|
/** |
3615
|
|
|
* Quotes a literal string. |
3616
|
|
|
* This method is NOT meant to fix SQL injections! |
3617
|
|
|
* It is only meant to escape this platform's string literal |
3618
|
|
|
* quote character inside the given literal string. |
3619
|
|
|
* |
3620
|
|
|
* @param string $str The literal string to be quoted. |
3621
|
|
|
* |
3622
|
|
|
* @return string The quoted literal string. |
3623
|
|
|
*/ |
3624
|
6661 |
|
public function quoteStringLiteral($str) |
3625
|
|
|
{ |
3626
|
6661 |
|
$c = $this->getStringLiteralQuoteCharacter(); |
3627
|
|
|
|
3628
|
6661 |
|
return $c . str_replace($c, $c . $c, $str) . $c; |
3629
|
|
|
} |
3630
|
|
|
|
3631
|
|
|
/** |
3632
|
|
|
* Gets the character used for string literal quoting. |
3633
|
|
|
* |
3634
|
|
|
* @return string |
3635
|
|
|
*/ |
3636
|
6881 |
|
public function getStringLiteralQuoteCharacter() |
3637
|
|
|
{ |
3638
|
6881 |
|
return "'"; |
3639
|
|
|
} |
3640
|
|
|
|
3641
|
|
|
/** |
3642
|
|
|
* Escapes metacharacters in a string intended to be used with a LIKE |
3643
|
|
|
* operator. |
3644
|
|
|
* |
3645
|
|
|
* @param string $inputString a literal, unquoted string |
3646
|
|
|
* @param string $escapeChar should be reused by the caller in the LIKE |
3647
|
|
|
* expression. |
3648
|
|
|
*/ |
3649
|
242 |
|
final public function escapeStringForLike(string $inputString, string $escapeChar) : string |
3650
|
|
|
{ |
3651
|
242 |
|
return preg_replace( |
3652
|
242 |
|
'~([' . preg_quote($this->getLikeWildcardCharacters() . $escapeChar, '~') . '])~u', |
3653
|
242 |
|
addcslashes($escapeChar, '\\') . '$1', |
3654
|
242 |
|
$inputString |
3655
|
|
|
); |
3656
|
|
|
} |
3657
|
|
|
|
3658
|
242 |
|
protected function getLikeWildcardCharacters() : string |
3659
|
|
|
{ |
3660
|
242 |
|
return '%_'; |
3661
|
|
|
} |
3662
|
|
|
} |
3663
|
|
|
|
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.