1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace PhpMyAdmin\SqlParser\Components; |
6
|
|
|
|
7
|
|
|
use PhpMyAdmin\SqlParser\Component; |
8
|
|
|
use PhpMyAdmin\SqlParser\Parser; |
9
|
|
|
use PhpMyAdmin\SqlParser\Token; |
10
|
|
|
use PhpMyAdmin\SqlParser\TokensList; |
11
|
|
|
|
12
|
|
|
use function array_key_exists; |
13
|
|
|
use function in_array; |
14
|
|
|
use function is_numeric; |
15
|
|
|
use function is_string; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* Parses an alter operation. |
19
|
|
|
* |
20
|
|
|
* @final |
21
|
|
|
*/ |
22
|
|
|
class AlterOperation extends Component |
23
|
|
|
{ |
24
|
|
|
/** |
25
|
|
|
* All database options. |
26
|
|
|
* |
27
|
|
|
* @var array<string, int|array<int, int|string>> |
28
|
|
|
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})> |
29
|
|
|
*/ |
30
|
|
|
public static $DB_OPTIONS = [ |
31
|
|
|
'CHARACTER SET' => [ |
32
|
|
|
1, |
33
|
|
|
'var', |
34
|
|
|
], |
35
|
|
|
'CHARSET' => [ |
36
|
|
|
1, |
37
|
|
|
'var', |
38
|
|
|
], |
39
|
|
|
'DEFAULT CHARACTER SET' => [ |
40
|
|
|
1, |
41
|
|
|
'var', |
42
|
|
|
], |
43
|
|
|
'DEFAULT CHARSET' => [ |
44
|
|
|
1, |
45
|
|
|
'var', |
46
|
|
|
], |
47
|
|
|
'UPGRADE' => [ |
48
|
|
|
1, |
49
|
|
|
'var', |
50
|
|
|
], |
51
|
|
|
'COLLATE' => [ |
52
|
|
|
2, |
53
|
|
|
'var', |
54
|
|
|
], |
55
|
|
|
'DEFAULT COLLATE' => [ |
56
|
|
|
2, |
57
|
|
|
'var', |
58
|
|
|
], |
59
|
|
|
]; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* All table options. |
63
|
|
|
* |
64
|
|
|
* @var array<string, int|array<int, int|string>> |
65
|
|
|
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})> |
66
|
|
|
*/ |
67
|
|
|
public static $TABLE_OPTIONS = [ |
68
|
|
|
'ENGINE' => [ |
69
|
|
|
1, |
70
|
|
|
'var=', |
71
|
|
|
], |
72
|
|
|
'AUTO_INCREMENT' => [ |
73
|
|
|
1, |
74
|
|
|
'var=', |
75
|
|
|
], |
76
|
|
|
'AVG_ROW_LENGTH' => [ |
77
|
|
|
1, |
78
|
|
|
'var', |
79
|
|
|
], |
80
|
|
|
'MAX_ROWS' => [ |
81
|
|
|
1, |
82
|
|
|
'var', |
83
|
|
|
], |
84
|
|
|
'ROW_FORMAT' => [ |
85
|
|
|
1, |
86
|
|
|
'var', |
87
|
|
|
], |
88
|
|
|
'COMMENT' => [ |
89
|
|
|
1, |
90
|
|
|
'var', |
91
|
|
|
], |
92
|
|
|
'ADD' => 1, |
93
|
|
|
'ALTER' => 1, |
94
|
|
|
'ANALYZE' => 1, |
95
|
|
|
'CHANGE' => 1, |
96
|
|
|
'CHARSET' => 1, |
97
|
|
|
'CHECK' => 1, |
98
|
|
|
'COALESCE' => 1, |
99
|
|
|
'CONVERT' => 1, |
100
|
|
|
'DEFAULT CHARSET' => 1, |
101
|
|
|
'DISABLE' => 1, |
102
|
|
|
'DISCARD' => 1, |
103
|
|
|
'DROP' => 1, |
104
|
|
|
'ENABLE' => 1, |
105
|
|
|
'IMPORT' => 1, |
106
|
|
|
'MODIFY' => 1, |
107
|
|
|
'OPTIMIZE' => 1, |
108
|
|
|
'ORDER' => 1, |
109
|
|
|
'REBUILD' => 1, |
110
|
|
|
'REMOVE' => 1, |
111
|
|
|
'RENAME' => 1, |
112
|
|
|
'REORGANIZE' => 1, |
113
|
|
|
'REPAIR' => 1, |
114
|
|
|
'UPGRADE' => 1, |
115
|
|
|
|
116
|
|
|
'COLUMN' => 2, |
117
|
|
|
'CONSTRAINT' => 2, |
118
|
|
|
'DEFAULT' => 2, |
119
|
|
|
'BY' => 2, |
120
|
|
|
'FOREIGN' => 2, |
121
|
|
|
'FULLTEXT' => 2, |
122
|
|
|
'KEY' => 2, |
123
|
|
|
'KEYS' => 2, |
124
|
|
|
'PARTITION' => 2, |
125
|
|
|
'PARTITION BY' => 2, |
126
|
|
|
'PARTITIONING' => 2, |
127
|
|
|
'PRIMARY KEY' => 2, |
128
|
|
|
'SPATIAL' => 2, |
129
|
|
|
'TABLESPACE' => 2, |
130
|
|
|
'INDEX' => [ |
131
|
|
|
2, |
132
|
|
|
'var', |
133
|
|
|
], |
134
|
|
|
|
135
|
|
|
'CHARACTER SET' => 3, |
136
|
|
|
'TO' => [ |
137
|
|
|
3, |
138
|
|
|
'var', |
139
|
|
|
], |
140
|
|
|
]; |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* All user options. |
144
|
|
|
* |
145
|
|
|
* @var array<string, int|array<int, int|string>> |
146
|
|
|
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})> |
147
|
|
|
*/ |
148
|
|
|
public static $USER_OPTIONS = [ |
149
|
|
|
'ATTRIBUTE' => [ |
150
|
|
|
1, |
151
|
|
|
'var', |
152
|
|
|
], |
153
|
|
|
'COMMENT' => [ |
154
|
|
|
1, |
155
|
|
|
'var', |
156
|
|
|
], |
157
|
|
|
'REQUIRE' => [ |
158
|
|
|
1, |
159
|
|
|
'var', |
160
|
|
|
], |
161
|
|
|
'BY' => [ |
162
|
|
|
2, |
163
|
|
|
'expr', |
164
|
|
|
], |
165
|
|
|
'PASSWORD' => [ |
166
|
|
|
2, |
167
|
|
|
'var', |
168
|
|
|
], |
169
|
|
|
'WITH' => [ |
170
|
|
|
2, |
171
|
|
|
'var', |
172
|
|
|
], |
173
|
|
|
|
174
|
|
|
'ACCOUNT' => 1, |
175
|
|
|
'DEFAULT' => 1, |
176
|
|
|
|
177
|
|
|
'LOCK' => 2, |
178
|
|
|
'UNLOCK' => 2, |
179
|
|
|
|
180
|
|
|
'IDENTIFIED' => 3, |
181
|
|
|
]; |
182
|
|
|
|
183
|
|
|
/** |
184
|
|
|
* All view options. |
185
|
|
|
* |
186
|
|
|
* @var array<string, int|array<int, int|string>> |
187
|
|
|
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})> |
188
|
|
|
*/ |
189
|
|
|
public static $VIEW_OPTIONS = ['AS' => 1]; |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* All event options. |
193
|
|
|
* |
194
|
|
|
* @var array<string, int|array<int, int|string>> |
195
|
|
|
* @psalm-var array<string, (positive-int|array{positive-int, ('var'|'var='|'expr'|'expr=')})> |
196
|
|
|
*/ |
197
|
|
|
public static $EVENT_OPTIONS = [ |
198
|
|
|
'ON SCHEDULE' => 1, |
199
|
|
|
'EVERY' => [ |
200
|
|
|
2, |
201
|
|
|
'expr', |
202
|
|
|
], |
203
|
|
|
'AT' => [ |
204
|
|
|
2, |
205
|
|
|
'expr', |
206
|
|
|
], |
207
|
|
|
'STARTS' => [ |
208
|
|
|
3, |
209
|
|
|
'expr', |
210
|
|
|
], |
211
|
|
|
'ENDS' => [ |
212
|
|
|
4, |
213
|
|
|
'expr', |
214
|
|
|
], |
215
|
|
|
'ON COMPLETION PRESERVE' => 5, |
216
|
|
|
'ON COMPLETION NOT PRESERVE' => 5, |
217
|
|
|
'RENAME' => 6, |
218
|
|
|
'TO' => [ |
219
|
|
|
7, |
220
|
|
|
'expr', |
221
|
|
|
['parseField' => 'table'], |
222
|
|
|
], |
223
|
|
|
'ENABLE' => 8, |
224
|
|
|
'DISABLE' => 8, |
225
|
|
|
'DISABLE ON SLAVE' => 8, |
226
|
|
|
'COMMENT' => [ |
227
|
|
|
9, |
228
|
|
|
'var', |
229
|
|
|
], |
230
|
|
|
'DO' => 10, |
231
|
|
|
]; |
232
|
|
|
|
233
|
|
|
/** |
234
|
|
|
* Options of this operation. |
235
|
|
|
* |
236
|
|
|
* @var OptionsArray |
237
|
|
|
*/ |
238
|
|
|
public $options; |
239
|
|
|
|
240
|
|
|
/** |
241
|
|
|
* The altered field. |
242
|
|
|
* |
243
|
|
|
* @var Expression|string|null |
244
|
|
|
*/ |
245
|
|
|
public $field; |
246
|
|
|
|
247
|
|
|
/** |
248
|
|
|
* The partitions. |
249
|
|
|
* |
250
|
|
|
* @var Component[]|ArrayObj|null |
251
|
|
|
*/ |
252
|
|
|
public $partitions; |
253
|
|
|
|
254
|
|
|
/** |
255
|
|
|
* Unparsed tokens. |
256
|
|
|
* |
257
|
|
|
* @var Token[]|string |
258
|
|
|
*/ |
259
|
|
|
public $unknown = []; |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* @param OptionsArray $options options of alter operation |
263
|
|
|
* @param Expression|string|null $field altered field |
264
|
|
|
* @param Component[]|ArrayObj|null $partitions partitions definition found in the operation |
265
|
|
|
* @param Token[] $unknown unparsed tokens found at the end of operation |
266
|
|
|
*/ |
267
|
146 |
|
public function __construct( |
268
|
|
|
$options = null, |
269
|
|
|
$field = null, |
270
|
|
|
$partitions = null, |
271
|
|
|
$unknown = [] |
272
|
|
|
) { |
273
|
146 |
|
$this->partitions = $partitions; |
274
|
146 |
|
$this->options = $options; |
275
|
146 |
|
$this->field = $field; |
276
|
146 |
|
$this->unknown = $unknown; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @param Parser $parser the parser that serves as context |
281
|
|
|
* @param TokensList $list the list of tokens that are being parsed |
282
|
|
|
* @param array<string, mixed> $options parameters for parsing |
283
|
|
|
* |
284
|
|
|
* @return AlterOperation |
285
|
|
|
*/ |
286
|
146 |
|
public static function parse(Parser $parser, TokensList $list, array $options = []) |
287
|
|
|
{ |
288
|
146 |
|
$ret = new static(); |
289
|
|
|
|
290
|
|
|
/** |
291
|
|
|
* Counts brackets. |
292
|
|
|
* |
293
|
|
|
* @var int |
294
|
|
|
*/ |
295
|
146 |
|
$brackets = 0; |
296
|
|
|
|
297
|
|
|
/** |
298
|
|
|
* The state of the parser. |
299
|
|
|
* |
300
|
|
|
* Below are the states of the parser. |
301
|
|
|
* |
302
|
|
|
* 0 ---------------------[ options ]---------------------> 1 |
303
|
|
|
* |
304
|
|
|
* 1 ----------------------[ field ]----------------------> 2 |
305
|
|
|
* |
306
|
|
|
* 1 -------------[ PARTITION / PARTITION BY ]------------> 3 |
307
|
|
|
* |
308
|
|
|
* 2 -------------------------[ , ]-----------------------> 0 |
309
|
|
|
* |
310
|
|
|
* @var int |
311
|
|
|
*/ |
312
|
146 |
|
$state = 0; |
313
|
|
|
|
314
|
|
|
/** |
315
|
|
|
* partition state. |
316
|
|
|
* |
317
|
|
|
* @var int |
318
|
|
|
*/ |
319
|
146 |
|
$partitionState = 0; |
320
|
|
|
|
321
|
146 |
|
for (; $list->idx < $list->count; ++$list->idx) { |
322
|
|
|
/** |
323
|
|
|
* Token parsed at this moment. |
324
|
|
|
*/ |
325
|
146 |
|
$token = $list->tokens[$list->idx]; |
326
|
|
|
|
327
|
|
|
// End of statement. |
328
|
146 |
|
if ($token->type === Token::TYPE_DELIMITER) { |
329
|
130 |
|
break; |
330
|
|
|
} |
331
|
|
|
|
332
|
|
|
// Skipping comments. |
333
|
146 |
|
if ($token->type === Token::TYPE_COMMENT) { |
334
|
2 |
|
continue; |
335
|
|
|
} |
336
|
|
|
|
337
|
|
|
// Skipping whitespaces. |
338
|
146 |
|
if ($token->type === Token::TYPE_WHITESPACE) { |
339
|
48 |
|
if ($state === 2) { |
340
|
|
|
// When parsing the unknown part, the whitespaces are |
341
|
|
|
// included to not break anything. |
342
|
44 |
|
$ret->unknown[] = $token; |
343
|
44 |
|
continue; |
344
|
|
|
} |
345
|
|
|
} |
346
|
|
|
|
347
|
146 |
|
if ($state === 0) { |
348
|
146 |
|
$ret->options = OptionsArray::parse($parser, $list, $options); |
349
|
|
|
|
350
|
|
|
// Not only when aliasing but also when parsing the body of an event, we just list the tokens of the |
351
|
|
|
// body in the unknown tokens list, as they define their own statements. |
352
|
146 |
|
if ($ret->options->has('AS') || $ret->options->has('DO')) { |
353
|
6 |
|
for (; $list->idx < $list->count; ++$list->idx) { |
354
|
6 |
|
if ($list->tokens[$list->idx]->type === Token::TYPE_DELIMITER) { |
355
|
6 |
|
break; |
356
|
|
|
} |
357
|
|
|
|
358
|
6 |
|
$ret->unknown[] = $list->tokens[$list->idx]; |
359
|
|
|
} |
360
|
|
|
|
361
|
6 |
|
break; |
362
|
|
|
} |
363
|
|
|
|
364
|
140 |
|
$state = 1; |
365
|
140 |
|
if ($ret->options->has('PARTITION') || $token->value === 'PARTITION BY') { |
366
|
4 |
|
$state = 3; |
367
|
140 |
|
$list->getPrevious(); // in order to check whether it's partition or partition by. |
368
|
|
|
} |
369
|
84 |
|
} elseif ($state === 1) { |
370
|
80 |
|
$ret->field = Expression::parse( |
371
|
80 |
|
$parser, |
372
|
80 |
|
$list, |
373
|
80 |
|
[ |
374
|
80 |
|
'breakOnAlias' => true, |
375
|
80 |
|
'parseField' => 'column', |
376
|
80 |
|
] |
377
|
80 |
|
); |
378
|
80 |
|
if ($ret->field === null) { |
379
|
|
|
// No field was read. We go back one token so the next |
380
|
|
|
// iteration will parse the same token, but in state 2. |
381
|
24 |
|
--$list->idx; |
382
|
|
|
} |
383
|
|
|
|
384
|
|
|
// If the operation is a RENAME COLUMN, now we have detected the field to rename, we need to parse |
385
|
|
|
// again the options to get the new name of the column. |
386
|
80 |
|
if ($ret->options->has('RENAME') && $ret->options->has('COLUMN')) { |
387
|
8 |
|
$nextOptions = OptionsArray::parse($parser, $list, $options); |
388
|
8 |
|
$ret->options->merge($nextOptions); |
389
|
|
|
} |
390
|
|
|
|
391
|
80 |
|
$state = 2; |
392
|
70 |
|
} elseif ($state === 2) { |
393
|
66 |
|
if (is_string($token->value) || is_numeric($token->value)) { |
394
|
66 |
|
$arrayKey = $token->value; |
395
|
|
|
} else { |
396
|
2 |
|
$arrayKey = $token->token; |
397
|
|
|
} |
398
|
|
|
|
399
|
66 |
|
if ($token->type === Token::TYPE_OPERATOR) { |
400
|
40 |
|
if ($token->value === '(') { |
401
|
28 |
|
++$brackets; |
402
|
40 |
|
} elseif ($token->value === ')') { |
403
|
28 |
|
--$brackets; |
404
|
26 |
|
} elseif (($token->value === ',') && ($brackets === 0)) { |
405
|
40 |
|
break; |
406
|
|
|
} |
407
|
62 |
|
} elseif (! self::checkIfTokenQuotedSymbol($token)) { |
408
|
54 |
|
if (! empty(Parser::$STATEMENT_PARSERS[$token->value])) { |
409
|
12 |
|
$list->idx++; // Ignore the current token |
410
|
12 |
|
$nextToken = $list->getNext(); |
411
|
|
|
|
412
|
12 |
|
if ($token->value === 'SET' && $nextToken !== null && $nextToken->value === '(') { |
413
|
|
|
// To avoid adding the tokens between the SET() parentheses to the unknown tokens |
414
|
4 |
|
$list->getNextOfTypeAndValue(Token::TYPE_OPERATOR, ')'); |
415
|
8 |
|
} elseif ($token->value === 'SET' && $nextToken !== null && $nextToken->value === 'DEFAULT') { |
416
|
|
|
// to avoid adding the `DEFAULT` token to the unknown tokens. |
417
|
4 |
|
++$list->idx; |
418
|
|
|
} else { |
419
|
|
|
// We have reached the end of ALTER operation and suddenly found |
420
|
|
|
// a start to new statement, but have not find a delimiter between them |
421
|
4 |
|
$parser->error( |
422
|
4 |
|
'A new statement was found, but no delimiter between it and the previous one.', |
423
|
4 |
|
$token |
424
|
4 |
|
); |
425
|
12 |
|
break; |
426
|
|
|
} |
427
|
|
|
} elseif ( |
428
|
48 |
|
(array_key_exists($arrayKey, self::$DB_OPTIONS) |
429
|
48 |
|
|| array_key_exists($arrayKey, self::$TABLE_OPTIONS)) |
430
|
48 |
|
&& ! self::checkIfColumnDefinitionKeyword($arrayKey) |
431
|
|
|
) { |
432
|
|
|
// This alter operation has finished, which means a comma |
433
|
|
|
// was missing before start of new alter operation |
434
|
4 |
|
$parser->error('Missing comma before start of a new alter operation.', $token); |
435
|
4 |
|
break; |
436
|
|
|
} |
437
|
|
|
} |
438
|
|
|
|
439
|
60 |
|
$ret->unknown[] = $token; |
440
|
4 |
|
} elseif ($state === 3) { |
441
|
4 |
|
if ($partitionState === 0) { |
442
|
4 |
|
$list->idx++; // Ignore the current token |
443
|
4 |
|
$nextToken = $list->getNext(); |
444
|
|
|
if ( |
445
|
4 |
|
($token->type === Token::TYPE_KEYWORD) |
446
|
4 |
|
&& (($token->keyword === 'PARTITION BY') |
447
|
4 |
|
|| ($token->keyword === 'PARTITION' && $nextToken && $nextToken->value !== '(')) |
448
|
|
|
) { |
449
|
4 |
|
$partitionState = 1; |
450
|
2 |
|
} elseif (($token->type === Token::TYPE_KEYWORD) && ($token->keyword === 'PARTITION')) { |
451
|
2 |
|
$partitionState = 2; |
452
|
|
|
} |
453
|
|
|
|
454
|
4 |
|
--$list->idx; // to decrease the idx by one, because the last getNext returned and increased it. |
455
|
|
|
|
456
|
|
|
// reverting the effect of the getNext |
457
|
4 |
|
$list->getPrevious(); |
458
|
4 |
|
$list->getPrevious(); |
459
|
|
|
|
460
|
4 |
|
++$list->idx; // to index the idx by one, because the last getPrevious returned and decreased it. |
461
|
4 |
|
} elseif ($partitionState === 1) { |
462
|
|
|
// Building the expression used for partitioning. |
463
|
4 |
|
if (empty($ret->field)) { |
464
|
4 |
|
$ret->field = ''; |
465
|
|
|
} |
466
|
|
|
|
467
|
4 |
|
$ret->field .= $token->type === Token::TYPE_WHITESPACE ? ' ' : $token->token; |
468
|
2 |
|
} elseif ($partitionState === 2) { |
469
|
2 |
|
$ret->partitions = ArrayObj::parse( |
470
|
2 |
|
$parser, |
471
|
2 |
|
$list, |
472
|
2 |
|
['type' => PartitionDefinition::class] |
473
|
2 |
|
); |
474
|
|
|
} |
475
|
|
|
} |
476
|
|
|
} |
477
|
|
|
|
478
|
146 |
|
if ($ret->options->isEmpty()) { |
479
|
2 |
|
$parser->error('Unrecognized alter operation.', $list->tokens[$list->idx]); |
480
|
|
|
} |
481
|
|
|
|
482
|
146 |
|
--$list->idx; |
483
|
|
|
|
484
|
146 |
|
return $ret; |
485
|
|
|
} |
486
|
|
|
|
487
|
|
|
/** |
488
|
|
|
* @param AlterOperation $component the component to be built |
489
|
|
|
* @param array<string, mixed> $options parameters for building |
490
|
|
|
* |
491
|
|
|
* @return string |
492
|
|
|
*/ |
493
|
18 |
|
public static function build($component, array $options = []) |
494
|
|
|
{ |
495
|
|
|
// Specific case of RENAME COLUMN that insert the field between 2 options. |
496
|
18 |
|
$afterFieldsOptions = new OptionsArray(); |
497
|
18 |
|
if ($component->options->has('RENAME') && $component->options->has('COLUMN')) { |
498
|
4 |
|
$afterFieldsOptions = clone $component->options; |
499
|
4 |
|
$afterFieldsOptions->remove('RENAME'); |
500
|
4 |
|
$afterFieldsOptions->remove('COLUMN'); |
501
|
4 |
|
$component->options->remove('TO'); |
502
|
|
|
} |
503
|
|
|
|
504
|
18 |
|
$ret = $component->options . ' '; |
505
|
18 |
|
if (isset($component->field) && ($component->field !== '')) { |
506
|
12 |
|
$ret .= $component->field . ' '; |
507
|
|
|
} |
508
|
|
|
|
509
|
18 |
|
$ret .= $afterFieldsOptions . TokensList::build($component->unknown); |
510
|
|
|
|
511
|
18 |
|
if (isset($component->partitions)) { |
512
|
2 |
|
$ret .= PartitionDefinition::build($component->partitions); |
|
|
|
|
513
|
|
|
} |
514
|
|
|
|
515
|
18 |
|
return $ret; |
516
|
|
|
} |
517
|
|
|
|
518
|
|
|
/** |
519
|
|
|
* Check if token's value is one of the common keywords |
520
|
|
|
* between column and table alteration |
521
|
|
|
* |
522
|
|
|
* @param string $tokenValue Value of current token |
523
|
|
|
* |
524
|
|
|
* @return bool |
525
|
|
|
*/ |
526
|
28 |
|
private static function checkIfColumnDefinitionKeyword($tokenValue) |
527
|
|
|
{ |
528
|
28 |
|
$commonOptions = [ |
529
|
28 |
|
'AUTO_INCREMENT', |
530
|
28 |
|
'COMMENT', |
531
|
28 |
|
'DEFAULT', |
532
|
28 |
|
'CHARACTER SET', |
533
|
28 |
|
'COLLATE', |
534
|
28 |
|
'PRIMARY', |
535
|
28 |
|
'UNIQUE', |
536
|
28 |
|
'PRIMARY KEY', |
537
|
28 |
|
'UNIQUE KEY', |
538
|
28 |
|
]; |
539
|
|
|
|
540
|
|
|
// Since these options can be used for |
541
|
|
|
// both table as well as a specific column in the table |
542
|
28 |
|
return in_array($tokenValue, $commonOptions); |
543
|
|
|
} |
544
|
|
|
|
545
|
|
|
/** |
546
|
|
|
* Check if token is symbol and quoted with backtick |
547
|
|
|
* |
548
|
|
|
* @param Token $token token to check |
549
|
|
|
* |
550
|
|
|
* @return bool |
551
|
|
|
*/ |
552
|
62 |
|
private static function checkIfTokenQuotedSymbol($token) |
553
|
|
|
{ |
554
|
62 |
|
return $token->type === Token::TYPE_SYMBOL && $token->flags === Token::FLAG_SYMBOL_BACKTICK; |
555
|
|
|
} |
556
|
|
|
} |
557
|
|
|
|