1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace Doctrine\DBAL\Platforms; |
6
|
|
|
|
7
|
|
|
use Doctrine\DBAL\LockMode; |
8
|
|
|
use Doctrine\DBAL\Platforms\Exception\NotSupported; |
9
|
|
|
use Doctrine\DBAL\Schema\Column; |
10
|
|
|
use Doctrine\DBAL\Schema\ColumnDiff; |
11
|
|
|
use Doctrine\DBAL\Schema\Constraint; |
12
|
|
|
use Doctrine\DBAL\Schema\ForeignKeyConstraint; |
13
|
|
|
use Doctrine\DBAL\Schema\Identifier; |
14
|
|
|
use Doctrine\DBAL\Schema\Index; |
15
|
|
|
use Doctrine\DBAL\Schema\Sequence; |
16
|
|
|
use Doctrine\DBAL\Schema\Table; |
17
|
|
|
use Doctrine\DBAL\Schema\TableDiff; |
18
|
|
|
use Doctrine\DBAL\TransactionIsolationLevel; |
19
|
|
|
use InvalidArgumentException; |
20
|
|
|
use UnexpectedValueException; |
21
|
|
|
use function array_merge; |
22
|
|
|
use function array_unique; |
23
|
|
|
use function array_values; |
24
|
|
|
use function count; |
25
|
|
|
use function explode; |
26
|
|
|
use function get_class; |
27
|
|
|
use function implode; |
28
|
|
|
use function in_array; |
29
|
|
|
use function is_string; |
30
|
|
|
use function preg_match; |
31
|
|
|
use function sprintf; |
32
|
|
|
use function strlen; |
33
|
|
|
use function strpos; |
34
|
|
|
use function strtoupper; |
35
|
|
|
use function substr; |
36
|
|
|
|
37
|
|
|
/** |
38
|
|
|
* The SQLAnywherePlatform provides the behavior, features and SQL dialect of the |
39
|
|
|
* SAP Sybase SQL Anywhere 12 database platform. |
40
|
|
|
*/ |
41
|
|
|
class SQLAnywherePlatform extends AbstractPlatform |
42
|
|
|
{ |
43
|
|
|
public const FOREIGN_KEY_MATCH_SIMPLE = 1; |
44
|
|
|
public const FOREIGN_KEY_MATCH_FULL = 2; |
45
|
|
|
public const FOREIGN_KEY_MATCH_SIMPLE_UNIQUE = 129; |
46
|
|
|
public const FOREIGN_KEY_MATCH_FULL_UNIQUE = 130; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* {@inheritdoc} |
50
|
|
|
*/ |
51
|
2580 |
|
public function appendLockHint(string $fromClause, ?int $lockMode) : string |
52
|
|
|
{ |
53
|
2580 |
|
switch (true) { |
54
|
|
|
case $lockMode === LockMode::NONE: |
55
|
2551 |
|
return $fromClause . ' WITH (NOLOCK)'; |
56
|
|
|
|
57
|
2579 |
|
case $lockMode === LockMode::PESSIMISTIC_READ: |
58
|
2501 |
|
return $fromClause . ' WITH (UPDLOCK)'; |
59
|
|
|
|
60
|
2578 |
|
case $lockMode === LockMode::PESSIMISTIC_WRITE: |
61
|
2476 |
|
return $fromClause . ' WITH (XLOCK)'; |
62
|
|
|
|
63
|
|
|
default: |
64
|
2577 |
|
return $fromClause; |
65
|
|
|
} |
66
|
|
|
} |
67
|
|
|
|
68
|
|
|
/** |
69
|
|
|
* {@inheritdoc} |
70
|
|
|
* |
71
|
|
|
* SQL Anywhere supports a maximum length of 128 bytes for identifiers. |
72
|
|
|
*/ |
73
|
2426 |
|
public function fixSchemaElementName(string $schemaElementName) : string |
74
|
|
|
{ |
75
|
2426 |
|
$maxIdentifierLength = $this->getMaxIdentifierLength(); |
76
|
|
|
|
77
|
2426 |
|
if (strlen($schemaElementName) > $maxIdentifierLength) { |
78
|
2426 |
|
return substr($schemaElementName, 0, $maxIdentifierLength); |
79
|
|
|
} |
80
|
|
|
|
81
|
2426 |
|
return $schemaElementName; |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
/** |
85
|
|
|
* {@inheritdoc} |
86
|
|
|
*/ |
87
|
2657 |
|
public function getAdvancedForeignKeyOptionsSQL(ForeignKeyConstraint $foreignKey) : string |
88
|
|
|
{ |
89
|
2657 |
|
$query = ''; |
90
|
|
|
|
91
|
2657 |
|
if ($foreignKey->hasOption('match')) { |
92
|
2226 |
|
$query = ' MATCH ' . $this->getForeignKeyMatchClauseSQL($foreignKey->getOption('match')); |
93
|
|
|
} |
94
|
|
|
|
95
|
2657 |
|
$query .= parent::getAdvancedForeignKeyOptionsSQL($foreignKey); |
96
|
|
|
|
97
|
2657 |
|
if ($foreignKey->hasOption('check_on_commit') && (bool) $foreignKey->getOption('check_on_commit')) { |
98
|
2226 |
|
$query .= ' CHECK ON COMMIT'; |
99
|
|
|
} |
100
|
|
|
|
101
|
2657 |
|
if ($foreignKey->hasOption('clustered') && (bool) $foreignKey->getOption('clustered')) { |
102
|
2226 |
|
$query .= ' CLUSTERED'; |
103
|
|
|
} |
104
|
|
|
|
105
|
2657 |
|
if ($foreignKey->hasOption('for_olap_workload') && (bool) $foreignKey->getOption('for_olap_workload')) { |
106
|
2226 |
|
$query .= ' FOR OLAP WORKLOAD'; |
107
|
|
|
} |
108
|
|
|
|
109
|
2657 |
|
return $query; |
110
|
|
|
} |
111
|
|
|
|
112
|
|
|
/** |
113
|
|
|
* {@inheritdoc} |
114
|
|
|
*/ |
115
|
2615 |
|
public function getAlterTableSQL(TableDiff $diff) : array |
116
|
|
|
{ |
117
|
2615 |
|
$sql = []; |
118
|
2615 |
|
$columnSql = []; |
119
|
2615 |
|
$commentsSQL = []; |
120
|
2615 |
|
$tableSql = []; |
121
|
2615 |
|
$alterClauses = []; |
122
|
|
|
|
123
|
2615 |
|
foreach ($diff->addedColumns as $column) { |
124
|
804 |
|
if ($this->onSchemaAlterTableAddColumn($column, $diff, $columnSql)) { |
125
|
|
|
continue; |
126
|
|
|
} |
127
|
|
|
|
128
|
804 |
|
$alterClauses[] = $this->getAlterTableAddColumnClause($column); |
129
|
|
|
|
130
|
804 |
|
$comment = $this->getColumnComment($column); |
131
|
|
|
|
132
|
804 |
|
if ($comment === null || $comment === '') { |
133
|
803 |
|
continue; |
134
|
|
|
} |
135
|
|
|
|
136
|
701 |
|
$commentsSQL[] = $this->getCommentOnColumnSQL( |
137
|
701 |
|
$diff->getName($this)->getQuotedName($this), |
138
|
701 |
|
$column->getQuotedName($this), |
139
|
1 |
|
$comment |
140
|
|
|
); |
141
|
|
|
} |
142
|
|
|
|
143
|
2615 |
|
foreach ($diff->removedColumns as $column) { |
144
|
803 |
|
if ($this->onSchemaAlterTableRemoveColumn($column, $diff, $columnSql)) { |
145
|
|
|
continue; |
146
|
|
|
} |
147
|
|
|
|
148
|
803 |
|
$alterClauses[] = $this->getAlterTableRemoveColumnClause($column); |
149
|
|
|
} |
150
|
|
|
|
151
|
2615 |
|
foreach ($diff->changedColumns as $columnDiff) { |
152
|
2608 |
|
if ($this->onSchemaAlterTableChangeColumn($columnDiff, $diff, $columnSql)) { |
153
|
|
|
continue; |
154
|
|
|
} |
155
|
|
|
|
156
|
2608 |
|
$alterClause = $this->getAlterTableChangeColumnClause($columnDiff); |
157
|
|
|
|
158
|
2608 |
|
if ($alterClause !== null) { |
159
|
805 |
|
$alterClauses[] = $alterClause; |
160
|
|
|
} |
161
|
|
|
|
162
|
2608 |
|
if (! $columnDiff->hasChanged('comment')) { |
163
|
805 |
|
continue; |
164
|
|
|
} |
165
|
|
|
|
166
|
2603 |
|
$column = $columnDiff->column; |
167
|
|
|
|
168
|
2603 |
|
$commentsSQL[] = $this->getCommentOnColumnSQL( |
169
|
2603 |
|
$diff->getName($this)->getQuotedName($this), |
170
|
2603 |
|
$column->getQuotedName($this), |
171
|
2603 |
|
$this->getColumnComment($column) |
172
|
|
|
); |
173
|
|
|
} |
174
|
|
|
|
175
|
2615 |
|
foreach ($diff->renamedColumns as $oldColumnName => $column) { |
176
|
754 |
|
if ($this->onSchemaAlterTableRenameColumn($oldColumnName, $column, $diff, $columnSql)) { |
177
|
|
|
continue; |
178
|
|
|
} |
179
|
|
|
|
180
|
754 |
|
$sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' . |
181
|
754 |
|
$this->getAlterTableRenameColumnClause($oldColumnName, $column); |
182
|
|
|
} |
183
|
|
|
|
184
|
2615 |
|
if (! $this->onSchemaAlterTable($diff, $tableSql)) { |
185
|
2615 |
|
if (! empty($alterClauses)) { |
186
|
806 |
|
$sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' . implode(', ', $alterClauses); |
187
|
|
|
} |
188
|
|
|
|
189
|
2615 |
|
$sql = array_merge($sql, $commentsSQL); |
190
|
|
|
|
191
|
2615 |
|
$newName = $diff->getNewName(); |
192
|
|
|
|
193
|
2615 |
|
if ($newName !== null) { |
194
|
802 |
|
$sql[] = $this->getAlterTableClause($diff->getName($this)) . ' ' . |
195
|
802 |
|
$this->getAlterTableRenameTableClause($newName); |
196
|
|
|
} |
197
|
|
|
|
198
|
2615 |
|
$sql = array_merge( |
199
|
2615 |
|
$this->getPreAlterTableIndexForeignKeySQL($diff), |
200
|
2615 |
|
$sql, |
201
|
2615 |
|
$this->getPostAlterTableIndexForeignKeySQL($diff) |
202
|
|
|
); |
203
|
|
|
} |
204
|
|
|
|
205
|
2615 |
|
return array_merge($sql, $tableSql, $columnSql); |
206
|
|
|
} |
207
|
|
|
|
208
|
|
|
/** |
209
|
|
|
* Returns the SQL clause for creating a column in a table alteration. |
210
|
|
|
* |
211
|
|
|
* @param Column $column The column to add. |
212
|
|
|
*/ |
213
|
804 |
|
protected function getAlterTableAddColumnClause(Column $column) : string |
214
|
|
|
{ |
215
|
804 |
|
return 'ADD ' . $this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); |
216
|
|
|
} |
217
|
|
|
|
218
|
|
|
/** |
219
|
|
|
* Returns the SQL clause for altering a table. |
220
|
|
|
* |
221
|
|
|
* @param Identifier $tableName The quoted name of the table to alter. |
222
|
|
|
*/ |
223
|
808 |
|
protected function getAlterTableClause(Identifier $tableName) : string |
224
|
|
|
{ |
225
|
808 |
|
return 'ALTER TABLE ' . $tableName->getQuotedName($this); |
226
|
|
|
} |
227
|
|
|
|
228
|
|
|
/** |
229
|
|
|
* Returns the SQL clause for dropping a column in a table alteration. |
230
|
|
|
* |
231
|
|
|
* @param Column $column The column to drop. |
232
|
|
|
*/ |
233
|
803 |
|
protected function getAlterTableRemoveColumnClause(Column $column) : string |
234
|
|
|
{ |
235
|
803 |
|
return 'DROP ' . $column->getQuotedName($this); |
236
|
|
|
} |
237
|
|
|
|
238
|
|
|
/** |
239
|
|
|
* Returns the SQL clause for renaming a column in a table alteration. |
240
|
|
|
* |
241
|
|
|
* @param string $oldColumnName The quoted name of the column to rename. |
242
|
|
|
* @param Column $column The column to rename to. |
243
|
|
|
*/ |
244
|
754 |
|
protected function getAlterTableRenameColumnClause(string $oldColumnName, Column $column) : string |
245
|
|
|
{ |
246
|
754 |
|
$oldColumnName = new Identifier($oldColumnName); |
247
|
|
|
|
248
|
754 |
|
return 'RENAME ' . $oldColumnName->getQuotedName($this) . ' TO ' . $column->getQuotedName($this); |
249
|
|
|
} |
250
|
|
|
|
251
|
|
|
/** |
252
|
|
|
* Returns the SQL clause for renaming a table in a table alteration. |
253
|
|
|
* |
254
|
|
|
* @param Identifier $newTableName The quoted name of the table to rename to. |
255
|
|
|
*/ |
256
|
802 |
|
protected function getAlterTableRenameTableClause(Identifier $newTableName) : string |
257
|
|
|
{ |
258
|
802 |
|
return 'RENAME ' . $newTableName->getQuotedName($this); |
259
|
|
|
} |
260
|
|
|
|
261
|
|
|
/** |
262
|
|
|
* Returns the SQL clause for altering a column in a table alteration. |
263
|
|
|
* |
264
|
|
|
* This method returns null in case that only the column comment has changed. |
265
|
|
|
* Changes in column comments have to be handled differently. |
266
|
|
|
* |
267
|
|
|
* @param ColumnDiff $columnDiff The diff of the column to alter. |
268
|
|
|
*/ |
269
|
2608 |
|
protected function getAlterTableChangeColumnClause(ColumnDiff $columnDiff) : ?string |
270
|
|
|
{ |
271
|
2608 |
|
$column = $columnDiff->column; |
272
|
|
|
|
273
|
|
|
// Do not return alter clause if only comment has changed. |
274
|
2608 |
|
if (! ($columnDiff->hasChanged('comment') && count($columnDiff->changedProperties) === 1)) { |
275
|
|
|
$columnAlterationClause = 'ALTER ' . |
276
|
805 |
|
$this->getColumnDeclarationSQL($column->getQuotedName($this), $column->toArray()); |
277
|
|
|
|
278
|
805 |
|
if ($columnDiff->hasChanged('default') && $column->getDefault() === null) { |
279
|
|
|
$columnAlterationClause .= ', ALTER ' . $column->getQuotedName($this) . ' DROP DEFAULT'; |
280
|
|
|
} |
281
|
|
|
|
282
|
805 |
|
return $columnAlterationClause; |
283
|
|
|
} |
284
|
|
|
|
285
|
2603 |
|
return null; |
286
|
|
|
} |
287
|
|
|
|
288
|
|
|
/** |
289
|
|
|
* {@inheritdoc} |
290
|
|
|
*/ |
291
|
2401 |
|
public function getBigIntTypeDeclarationSQL(array $columnDef) : string |
292
|
|
|
{ |
293
|
2401 |
|
$columnDef['integer_type'] = 'BIGINT'; |
294
|
|
|
|
295
|
2401 |
|
return $this->_getCommonIntegerTypeDeclarationSQL($columnDef); |
296
|
|
|
} |
297
|
|
|
|
298
|
|
|
/** |
299
|
|
|
* {@inheritdoc} |
300
|
|
|
*/ |
301
|
2401 |
|
public function getBlobTypeDeclarationSQL(array $field) : string |
302
|
|
|
{ |
303
|
2401 |
|
return 'LONG BINARY'; |
304
|
|
|
} |
305
|
|
|
|
306
|
|
|
/** |
307
|
|
|
* {@inheritdoc} |
308
|
|
|
* |
309
|
|
|
* BIT type columns require an explicit NULL declaration |
310
|
|
|
* in SQL Anywhere if they shall be nullable. |
311
|
|
|
* Otherwise by just omitting the NOT NULL clause, |
312
|
|
|
* SQL Anywhere will declare them NOT NULL nonetheless. |
313
|
|
|
*/ |
314
|
2402 |
|
public function getBooleanTypeDeclarationSQL(array $columnDef) : string |
315
|
|
|
{ |
316
|
2402 |
|
$nullClause = isset($columnDef['notnull']) && (bool) $columnDef['notnull'] === false ? ' NULL' : ''; |
317
|
|
|
|
318
|
2402 |
|
return 'BIT' . $nullClause; |
319
|
|
|
} |
320
|
|
|
|
321
|
|
|
/** |
322
|
|
|
* {@inheritdoc} |
323
|
|
|
*/ |
324
|
2403 |
|
public function getClobTypeDeclarationSQL(array $field) : string |
325
|
|
|
{ |
326
|
2403 |
|
return 'TEXT'; |
327
|
|
|
} |
328
|
|
|
|
329
|
|
|
/** |
330
|
|
|
* {@inheritdoc} |
331
|
|
|
*/ |
332
|
2608 |
|
public function getCommentOnColumnSQL(string $tableName, string $columnName, ?string $comment) : string |
333
|
|
|
{ |
334
|
2608 |
|
$tableName = new Identifier($tableName); |
335
|
2608 |
|
$columnName = new Identifier($columnName); |
336
|
2608 |
|
$comment = $comment === null ? 'NULL' : $this->quoteStringLiteral($comment); |
337
|
|
|
|
338
|
2608 |
|
return sprintf( |
339
|
8 |
|
'COMMENT ON COLUMN %s.%s IS %s', |
340
|
2608 |
|
$tableName->getQuotedName($this), |
341
|
2608 |
|
$columnName->getQuotedName($this), |
342
|
2608 |
|
$comment |
343
|
|
|
); |
344
|
|
|
} |
345
|
|
|
|
346
|
|
|
/** |
347
|
|
|
* {@inheritdoc} |
348
|
|
|
*/ |
349
|
1876 |
|
public function getConcatExpression(string ...$string) : string |
350
|
|
|
{ |
351
|
1876 |
|
return 'STRING(' . implode(', ', $string) . ')'; |
352
|
|
|
} |
353
|
|
|
|
354
|
|
|
/** |
355
|
|
|
* {@inheritdoc} |
356
|
|
|
*/ |
357
|
2078 |
|
public function getCreateConstraintSQL(Constraint $constraint, $table) : string |
358
|
|
|
{ |
359
|
2078 |
|
if ($constraint instanceof ForeignKeyConstraint) { |
360
|
851 |
|
return $this->getCreateForeignKeySQL($constraint, $table); |
361
|
|
|
} |
362
|
|
|
|
363
|
2078 |
|
if ($table instanceof Table) { |
364
|
2076 |
|
$table = $table->getQuotedName($this); |
365
|
|
|
} |
366
|
|
|
|
367
|
2078 |
|
return 'ALTER TABLE ' . $table . |
368
|
2078 |
|
' ADD ' . $this->getTableConstraintDeclarationSQL($constraint, $constraint->getQuotedName($this)); |
369
|
|
|
} |
370
|
|
|
|
371
|
|
|
/** |
372
|
|
|
* {@inheritdoc} |
373
|
|
|
*/ |
374
|
2351 |
|
public function getCreateDatabaseSQL(string $database) : string |
375
|
|
|
{ |
376
|
2351 |
|
$database = new Identifier($database); |
377
|
|
|
|
378
|
2351 |
|
return "CREATE DATABASE '" . $database->getName() . "'"; |
379
|
|
|
} |
380
|
|
|
|
381
|
|
|
/** |
382
|
|
|
* {@inheritdoc} |
383
|
|
|
* |
384
|
|
|
* Appends SQL Anywhere specific flags if given. |
385
|
|
|
*/ |
386
|
2684 |
|
public function getCreateIndexSQL(Index $index, $table) : string |
387
|
|
|
{ |
388
|
2684 |
|
return parent::getCreateIndexSQL($index, $table) . $this->getAdvancedIndexOptionsSQL($index); |
389
|
|
|
} |
390
|
|
|
|
391
|
|
|
/** |
392
|
|
|
* {@inheritdoc} |
393
|
|
|
*/ |
394
|
2277 |
|
public function getCreatePrimaryKeySQL(Index $index, $table) : string |
395
|
|
|
{ |
396
|
2277 |
|
if ($table instanceof Table) { |
397
|
2276 |
|
$table = $table->getQuotedName($this); |
398
|
|
|
} |
399
|
|
|
|
400
|
2277 |
|
return 'ALTER TABLE ' . $table . ' ADD ' . $this->getPrimaryKeyDeclarationSQL($index); |
401
|
|
|
} |
402
|
|
|
|
403
|
|
|
/** |
404
|
|
|
* {@inheritdoc} |
405
|
|
|
*/ |
406
|
2351 |
|
public function getCreateTemporaryTableSnippetSQL() : string |
407
|
|
|
{ |
408
|
2351 |
|
return 'CREATE ' . $this->getTemporaryTableSQL() . ' TABLE'; |
409
|
|
|
} |
410
|
|
|
|
411
|
|
|
/** |
412
|
|
|
* {@inheritdoc} |
413
|
|
|
*/ |
414
|
2351 |
|
public function getCreateViewSQL(string $name, string $sql) : string |
415
|
|
|
{ |
416
|
2351 |
|
return 'CREATE VIEW ' . $name . ' AS ' . $sql; |
417
|
|
|
} |
418
|
|
|
|
419
|
|
|
/** |
420
|
|
|
* {@inheritdoc} |
421
|
|
|
*/ |
422
|
1877 |
|
public function getCurrentDateSQL() : string |
423
|
|
|
{ |
424
|
1877 |
|
return 'CURRENT DATE'; |
425
|
|
|
} |
426
|
|
|
|
427
|
|
|
/** |
428
|
|
|
* {@inheritdoc} |
429
|
|
|
*/ |
430
|
1876 |
|
public function getCurrentTimeSQL() : string |
431
|
|
|
{ |
432
|
1876 |
|
return 'CURRENT TIME'; |
433
|
|
|
} |
434
|
|
|
|
435
|
|
|
/** |
436
|
|
|
* {@inheritdoc} |
437
|
|
|
*/ |
438
|
1877 |
|
public function getCurrentTimestampSQL() : string |
439
|
|
|
{ |
440
|
1877 |
|
return 'CURRENT TIMESTAMP'; |
441
|
|
|
} |
442
|
|
|
|
443
|
|
|
/** |
444
|
|
|
* {@inheritdoc} |
445
|
|
|
*/ |
446
|
1876 |
|
protected function getDateArithmeticIntervalExpression(string $date, string $operator, string $interval, string $unit) : string |
447
|
|
|
{ |
448
|
1876 |
|
$factorClause = ''; |
449
|
|
|
|
450
|
1876 |
|
if ($operator === '-') { |
451
|
1876 |
|
$factorClause = '-1 * '; |
452
|
|
|
} |
453
|
|
|
|
454
|
1876 |
|
return 'DATEADD(' . $unit . ', ' . $factorClause . $interval . ', ' . $date . ')'; |
455
|
|
|
} |
456
|
|
|
|
457
|
|
|
/** |
458
|
|
|
* {@inheritdoc} |
459
|
|
|
*/ |
460
|
1876 |
|
public function getDateDiffExpression(string $date1, string $date2) : string |
461
|
|
|
{ |
462
|
1876 |
|
return 'DATEDIFF(day, ' . $date2 . ', ' . $date1 . ')'; |
463
|
|
|
} |
464
|
|
|
|
465
|
|
|
/** |
466
|
|
|
* {@inheritdoc} |
467
|
|
|
*/ |
468
|
1876 |
|
public function getDateTimeFormatString() : string |
469
|
|
|
{ |
470
|
1876 |
|
return 'Y-m-d H:i:s.u'; |
471
|
|
|
} |
472
|
|
|
|
473
|
|
|
/** |
474
|
|
|
* {@inheritdoc} |
475
|
|
|
*/ |
476
|
2401 |
|
public function getDateTimeTypeDeclarationSQL(array $fieldDeclaration) : string |
477
|
|
|
{ |
478
|
2401 |
|
return 'DATETIME'; |
479
|
|
|
} |
480
|
|
|
|
481
|
|
|
/** |
482
|
|
|
* {@inheritdoc} |
483
|
|
|
*/ |
484
|
1851 |
|
public function getDateTimeTzFormatString() : string |
485
|
|
|
{ |
486
|
1851 |
|
return 'Y-m-d H:i:s.uP'; |
487
|
|
|
} |
488
|
|
|
|
489
|
|
|
/** |
490
|
|
|
* {@inheritdoc} |
491
|
|
|
*/ |
492
|
2401 |
|
public function getDateTypeDeclarationSQL(array $fieldDeclaration) : string |
493
|
|
|
{ |
494
|
2401 |
|
return 'DATE'; |
495
|
|
|
} |
496
|
|
|
|
497
|
|
|
/** |
498
|
|
|
* {@inheritdoc} |
499
|
|
|
*/ |
500
|
1776 |
|
public function getDefaultTransactionIsolationLevel() : int |
501
|
|
|
{ |
502
|
1776 |
|
return TransactionIsolationLevel::READ_UNCOMMITTED; |
503
|
|
|
} |
504
|
|
|
|
505
|
|
|
/** |
506
|
|
|
* {@inheritdoc} |
507
|
|
|
*/ |
508
|
2351 |
|
public function getDropDatabaseSQL(string $database) : string |
509
|
|
|
{ |
510
|
2351 |
|
$database = new Identifier($database); |
511
|
|
|
|
512
|
2351 |
|
return "DROP DATABASE '" . $database->getName() . "'"; |
513
|
|
|
} |
514
|
|
|
|
515
|
|
|
/** |
516
|
|
|
* {@inheritdoc} |
517
|
|
|
*/ |
518
|
1953 |
|
public function getDropIndexSQL($index, $table = null) : string |
519
|
|
|
{ |
520
|
1953 |
|
if ($index instanceof Index) { |
521
|
1951 |
|
$index = $index->getQuotedName($this); |
522
|
|
|
} |
523
|
|
|
|
524
|
1953 |
|
if (! is_string($index)) { |
525
|
1926 |
|
throw new InvalidArgumentException( |
526
|
1926 |
|
sprintf('SQLAnywherePlatform::getDropIndexSQL() expects $index parameter to be a string or an instance of %s.', Index::class) |
527
|
|
|
); |
528
|
|
|
} |
529
|
|
|
|
530
|
1952 |
|
if (! isset($table)) { |
531
|
1951 |
|
return 'DROP INDEX ' . $index; |
532
|
|
|
} |
533
|
|
|
|
534
|
1952 |
|
if ($table instanceof Table) { |
535
|
1951 |
|
$table = $table->getQuotedName($this); |
536
|
|
|
} |
537
|
|
|
|
538
|
1952 |
|
if (! is_string($table)) { |
539
|
1901 |
|
throw new InvalidArgumentException( |
540
|
1901 |
|
sprintf('SQLAnywherePlatform::getDropIndexSQL() expects $table parameter to be a string or an instance of %s.', Index::class) |
541
|
|
|
); |
542
|
|
|
} |
543
|
|
|
|
544
|
1951 |
|
return 'DROP INDEX ' . $table . '.' . $index; |
545
|
|
|
} |
546
|
|
|
|
547
|
|
|
/** |
548
|
|
|
* {@inheritdoc} |
549
|
|
|
*/ |
550
|
2351 |
|
public function getDropViewSQL(string $name) : string |
551
|
|
|
{ |
552
|
2351 |
|
return 'DROP VIEW ' . $name; |
553
|
|
|
} |
554
|
|
|
|
555
|
|
|
/** |
556
|
|
|
* {@inheritdoc} |
557
|
|
|
*/ |
558
|
2660 |
|
public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey) : string |
559
|
|
|
{ |
560
|
2660 |
|
$sql = ''; |
561
|
2660 |
|
$foreignKeyName = $foreignKey->getName(); |
562
|
2660 |
|
$localColumns = $foreignKey->getQuotedLocalColumns($this); |
563
|
2660 |
|
$foreignColumns = $foreignKey->getQuotedForeignColumns($this); |
564
|
2660 |
|
$foreignTableName = $foreignKey->getQuotedForeignTableName($this); |
565
|
|
|
|
566
|
2660 |
|
if (! empty($foreignKeyName)) { |
567
|
2656 |
|
$sql .= 'CONSTRAINT ' . $foreignKey->getQuotedName($this) . ' '; |
568
|
|
|
} |
569
|
|
|
|
570
|
2660 |
|
if (empty($localColumns)) { |
571
|
2151 |
|
throw new InvalidArgumentException('Incomplete definition. "local" required.'); |
572
|
|
|
} |
573
|
|
|
|
574
|
2659 |
|
if (empty($foreignColumns)) { |
575
|
2126 |
|
throw new InvalidArgumentException('Incomplete definition. "foreign" required.'); |
576
|
|
|
} |
577
|
|
|
|
578
|
2658 |
|
if (empty($foreignTableName)) { |
579
|
2101 |
|
throw new InvalidArgumentException('Incomplete definition. "foreignTable" required.'); |
580
|
|
|
} |
581
|
|
|
|
582
|
2657 |
|
if ($foreignKey->hasOption('notnull') && (bool) $foreignKey->getOption('notnull')) { |
583
|
2226 |
|
$sql .= 'NOT NULL '; |
584
|
|
|
} |
585
|
|
|
|
586
|
|
|
return $sql . |
587
|
2657 |
|
'FOREIGN KEY (' . $this->getIndexFieldDeclarationListSQL($localColumns) . ') ' . |
588
|
2657 |
|
'REFERENCES ' . $foreignKey->getQuotedForeignTableName($this) . |
589
|
2657 |
|
' (' . $this->getIndexFieldDeclarationListSQL($foreignColumns) . ')'; |
590
|
|
|
} |
591
|
|
|
|
592
|
|
|
/** |
593
|
|
|
* Returns foreign key MATCH clause for given type. |
594
|
|
|
* |
595
|
|
|
* @param int $type The foreign key match type |
596
|
|
|
* |
597
|
|
|
* @throws InvalidArgumentException If unknown match type given. |
598
|
|
|
*/ |
599
|
2228 |
|
public function getForeignKeyMatchClauseSQL(int $type) : string |
600
|
|
|
{ |
601
|
|
|
switch ($type) { |
602
|
2228 |
|
case self::FOREIGN_KEY_MATCH_SIMPLE: |
603
|
2201 |
|
return 'SIMPLE'; |
604
|
|
|
|
605
|
|
|
break; |
|
|
|
|
606
|
2228 |
|
case self::FOREIGN_KEY_MATCH_FULL: |
607
|
2201 |
|
return 'FULL'; |
608
|
|
|
|
609
|
|
|
break; |
610
|
2228 |
|
case self::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE: |
611
|
2227 |
|
return 'UNIQUE SIMPLE'; |
612
|
|
|
|
613
|
|
|
break; |
614
|
2202 |
|
case self::FOREIGN_KEY_MATCH_FULL_UNIQUE: |
615
|
2201 |
|
return 'UNIQUE FULL'; |
616
|
|
|
default: |
617
|
2176 |
|
throw new InvalidArgumentException(sprintf('Invalid foreign key match type "%s".', $type)); |
618
|
|
|
} |
619
|
|
|
} |
620
|
|
|
|
621
|
|
|
/** |
622
|
|
|
* {@inheritdoc} |
623
|
|
|
*/ |
624
|
2233 |
|
public function getForeignKeyReferentialActionSQL(string $action) : string |
625
|
|
|
{ |
626
|
|
|
// NO ACTION is not supported, therefore falling back to RESTRICT. |
627
|
2233 |
|
if (strtoupper($action) === 'NO ACTION') { |
628
|
1201 |
|
return 'RESTRICT'; |
629
|
|
|
} |
630
|
|
|
|
631
|
2232 |
|
return parent::getForeignKeyReferentialActionSQL($action); |
632
|
|
|
} |
633
|
|
|
|
634
|
|
|
/** |
635
|
|
|
* {@inheritdoc} |
636
|
|
|
*/ |
637
|
1876 |
|
public function getForUpdateSQL() : string |
638
|
|
|
{ |
639
|
1876 |
|
return ''; |
640
|
|
|
} |
641
|
|
|
|
642
|
|
|
/** |
643
|
|
|
* {@inheritdoc} |
644
|
|
|
*/ |
645
|
2402 |
|
public function getGuidTypeDeclarationSQL(array $column) : string |
646
|
|
|
{ |
647
|
2402 |
|
return 'UNIQUEIDENTIFIER'; |
648
|
|
|
} |
649
|
|
|
|
650
|
|
|
/** |
651
|
|
|
* {@inheritdoc} |
652
|
|
|
*/ |
653
|
1977 |
|
public function getIndexDeclarationSQL(string $name, Index $index) : string |
654
|
|
|
{ |
655
|
|
|
// Index declaration in statements like CREATE TABLE is not supported. |
656
|
1977 |
|
throw NotSupported::new(__METHOD__); |
657
|
|
|
} |
658
|
|
|
|
659
|
|
|
/** |
660
|
|
|
* {@inheritdoc} |
661
|
|
|
*/ |
662
|
2686 |
|
public function getIntegerTypeDeclarationSQL(array $columnDef) : string |
663
|
|
|
{ |
664
|
2686 |
|
$columnDef['integer_type'] = 'INT'; |
665
|
|
|
|
666
|
2686 |
|
return $this->_getCommonIntegerTypeDeclarationSQL($columnDef); |
667
|
|
|
} |
668
|
|
|
|
669
|
|
|
/** |
670
|
|
|
* {@inheritdoc} |
671
|
|
|
*/ |
672
|
|
|
public function getListDatabasesSQL() : string |
673
|
|
|
{ |
674
|
|
|
return 'SELECT db_name(number) AS name FROM sa_db_list()'; |
675
|
|
|
} |
676
|
|
|
|
677
|
|
|
/** |
678
|
|
|
* {@inheritdoc} |
679
|
|
|
*/ |
680
|
1451 |
|
public function getListTableColumnsSQL(string $table, ?string $database = null) : string |
681
|
|
|
{ |
682
|
1451 |
|
$user = 'USER_NAME()'; |
683
|
|
|
|
684
|
1451 |
|
if (strpos($table, '.') !== false) { |
685
|
1451 |
|
[$user, $table] = explode('.', $table); |
686
|
1451 |
|
$user = $this->quoteStringLiteral($user); |
687
|
|
|
} |
688
|
|
|
|
689
|
1451 |
|
return sprintf( |
690
|
|
|
<<<'SQL' |
691
|
1 |
|
SELECT col.column_name, |
692
|
|
|
COALESCE(def.user_type_name, def.domain_name) AS 'type', |
693
|
|
|
def.declared_width AS 'length', |
694
|
|
|
def.scale, |
695
|
|
|
CHARINDEX('unsigned', def.domain_name) AS 'unsigned', |
696
|
|
|
IF col.nulls = 'Y' THEN 0 ELSE 1 ENDIF AS 'notnull', |
697
|
|
|
col."default", |
698
|
|
|
def.is_autoincrement AS 'autoincrement', |
699
|
|
|
rem.remarks AS 'comment' |
700
|
|
|
FROM sa_describe_query('SELECT * FROM "%s"') AS def |
701
|
|
|
JOIN SYS.SYSTABCOL AS col |
702
|
|
|
ON col.table_id = def.base_table_id AND col.column_id = def.base_column_id |
703
|
|
|
LEFT JOIN SYS.SYSREMARK AS rem |
704
|
|
|
ON col.object_id = rem.object_id |
705
|
|
|
WHERE def.base_owner_name = %s |
706
|
|
|
ORDER BY def.base_column_id ASC |
707
|
|
|
SQL |
708
|
|
|
, |
709
|
1451 |
|
$table, |
710
|
1451 |
|
$user |
711
|
|
|
); |
712
|
|
|
} |
713
|
|
|
|
714
|
|
|
/** |
715
|
|
|
* {@inheritdoc} |
716
|
|
|
* |
717
|
|
|
* @todo Where is this used? Which information should be retrieved? |
718
|
|
|
*/ |
719
|
1427 |
|
public function getListTableConstraintsSQL(string $table) : string |
720
|
|
|
{ |
721
|
1427 |
|
$user = ''; |
722
|
|
|
|
723
|
1427 |
|
if (strpos($table, '.') !== false) { |
724
|
1401 |
|
[$user, $table] = explode('.', $table); |
725
|
1401 |
|
$user = $this->quoteStringLiteral($user); |
726
|
1401 |
|
$table = $this->quoteStringLiteral($table); |
727
|
|
|
} else { |
728
|
1426 |
|
$table = $this->quoteStringLiteral($table); |
729
|
|
|
} |
730
|
|
|
|
731
|
1427 |
|
return sprintf( |
732
|
|
|
<<<'SQL' |
733
|
2 |
|
SELECT con.* |
734
|
|
|
FROM SYS.SYSCONSTRAINT AS con |
735
|
|
|
JOIN SYS.SYSTAB AS tab ON con.table_object_id = tab.object_id |
736
|
|
|
WHERE tab.table_name = %s |
737
|
|
|
AND tab.creator = USER_ID(%s) |
738
|
|
|
SQL |
739
|
|
|
, |
740
|
1427 |
|
$table, |
741
|
1427 |
|
$user |
742
|
|
|
); |
743
|
|
|
} |
744
|
|
|
|
745
|
|
|
/** |
746
|
|
|
* {@inheritdoc} |
747
|
|
|
*/ |
748
|
1377 |
|
public function getListTableForeignKeysSQL(string $table, ?string $database = null) : string |
749
|
|
|
{ |
750
|
1377 |
|
$user = ''; |
751
|
|
|
|
752
|
1377 |
|
if (strpos($table, '.') !== false) { |
753
|
1351 |
|
[$user, $table] = explode('.', $table); |
754
|
1351 |
|
$user = $this->quoteStringLiteral($user); |
755
|
1351 |
|
$table = $this->quoteStringLiteral($table); |
756
|
|
|
} else { |
757
|
1376 |
|
$table = $this->quoteStringLiteral($table); |
758
|
|
|
} |
759
|
|
|
|
760
|
1377 |
|
return sprintf( |
761
|
|
|
<<<'SQL' |
762
|
2 |
|
SELECT fcol.column_name AS local_column, |
763
|
|
|
ptbl.table_name AS foreign_table, |
764
|
|
|
pcol.column_name AS foreign_column, |
765
|
|
|
idx.index_name, |
766
|
|
|
IF fk.nulls = 'N' |
767
|
|
|
THEN 1 |
768
|
|
|
ELSE NULL |
769
|
|
|
ENDIF AS notnull, |
770
|
|
|
CASE ut.referential_action |
771
|
|
|
WHEN 'C' THEN 'CASCADE' |
772
|
|
|
WHEN 'D' THEN 'SET DEFAULT' |
773
|
|
|
WHEN 'N' THEN 'SET NULL' |
774
|
|
|
WHEN 'R' THEN 'RESTRICT' |
775
|
|
|
ELSE NULL |
776
|
|
|
END AS on_update, |
777
|
|
|
CASE dt.referential_action |
778
|
|
|
WHEN 'C' THEN 'CASCADE' |
779
|
|
|
WHEN 'D' THEN 'SET DEFAULT' |
780
|
|
|
WHEN 'N' THEN 'SET NULL' |
781
|
|
|
WHEN 'R' THEN 'RESTRICT' |
782
|
|
|
ELSE NULL |
783
|
|
|
END AS on_delete, |
784
|
|
|
IF fk.check_on_commit = 'Y' |
785
|
|
|
THEN 1 |
786
|
|
|
ELSE NULL |
787
|
|
|
ENDIF AS check_on_commit, -- check_on_commit flag |
788
|
|
|
IF ftbl.clustered_index_id = idx.index_id |
789
|
|
|
THEN 1 |
790
|
|
|
ELSE NULL |
791
|
|
|
ENDIF AS 'clustered', -- clustered flag |
792
|
|
|
IF fk.match_type = 0 |
793
|
|
|
THEN NULL |
794
|
|
|
ELSE fk.match_type |
795
|
|
|
ENDIF AS 'match', -- match option |
796
|
|
|
IF pidx.max_key_distance = 1 |
797
|
|
|
THEN 1 |
798
|
|
|
ELSE NULL |
799
|
|
|
ENDIF AS for_olap_workload -- for_olap_workload flag |
800
|
|
|
FROM SYS.SYSFKEY AS fk |
801
|
|
|
JOIN SYS.SYSIDX AS idx |
802
|
|
|
ON fk.foreign_table_id = idx.table_id |
803
|
|
|
AND fk.foreign_index_id = idx.index_id |
804
|
|
|
JOIN SYS.SYSPHYSIDX pidx |
805
|
|
|
ON idx.table_id = pidx.table_id |
806
|
|
|
AND idx.phys_index_id = pidx.phys_index_id |
807
|
|
|
JOIN SYS.SYSTAB AS ptbl |
808
|
|
|
ON fk.primary_table_id = ptbl.table_id |
809
|
|
|
JOIN SYS.SYSTAB AS ftbl |
810
|
|
|
ON fk.foreign_table_id = ftbl.table_id |
811
|
|
|
JOIN SYS.SYSIDXCOL AS idxcol |
812
|
|
|
ON idx.table_id = idxcol.table_id |
813
|
|
|
AND idx.index_id = idxcol.index_id |
814
|
|
|
JOIN SYS.SYSTABCOL AS pcol |
815
|
|
|
ON ptbl.table_id = pcol.table_id |
816
|
|
|
AND idxcol.primary_column_id = pcol.column_id |
817
|
|
|
JOIN SYS.SYSTABCOL AS fcol |
818
|
|
|
ON ftbl.table_id = fcol.table_id |
819
|
|
|
AND idxcol.column_id = fcol.column_id |
820
|
|
|
LEFT JOIN SYS.SYSTRIGGER ut |
821
|
|
|
ON fk.foreign_table_id = ut.foreign_table_id |
822
|
|
|
AND fk.foreign_index_id = ut.foreign_key_id |
823
|
|
|
AND ut.event = 'C' |
824
|
|
|
LEFT JOIN SYS.SYSTRIGGER dt |
825
|
|
|
ON fk.foreign_table_id = dt.foreign_table_id |
826
|
|
|
AND fk.foreign_index_id = dt.foreign_key_id |
827
|
|
|
AND dt.event = 'D' |
828
|
|
|
WHERE ftbl.table_name = %s |
829
|
|
|
AND ftbl.creator = USER_ID(%s) |
830
|
|
|
ORDER BY fk.foreign_index_id ASC, idxcol.sequence ASC |
831
|
|
|
SQL |
832
|
|
|
, |
833
|
1377 |
|
$table, |
834
|
1377 |
|
$user |
835
|
|
|
); |
836
|
|
|
} |
837
|
|
|
|
838
|
|
|
/** |
839
|
|
|
* {@inheritdoc} |
840
|
|
|
*/ |
841
|
1327 |
|
public function getListTableIndexesSQL(string $table, ?string $currentDatabase = null) : string |
842
|
|
|
{ |
843
|
1327 |
|
$user = ''; |
844
|
|
|
|
845
|
1327 |
|
if (strpos($table, '.') !== false) { |
846
|
1301 |
|
[$user, $table] = explode('.', $table); |
847
|
1301 |
|
$user = $this->quoteStringLiteral($user); |
848
|
1301 |
|
$table = $this->quoteStringLiteral($table); |
849
|
|
|
} else { |
850
|
1326 |
|
$table = $this->quoteStringLiteral($table); |
851
|
|
|
} |
852
|
|
|
|
853
|
1327 |
|
return sprintf( |
854
|
|
|
<<<'SQL' |
855
|
2 |
|
SELECT idx.index_name AS key_name, |
856
|
|
|
IF idx.index_category = 1 |
857
|
|
|
THEN 1 |
858
|
|
|
ELSE 0 |
859
|
|
|
ENDIF AS 'primary', |
860
|
|
|
col.column_name, |
861
|
|
|
IF idx."unique" IN(1, 2, 5) |
862
|
|
|
THEN 0 |
863
|
|
|
ELSE 1 |
864
|
|
|
ENDIF AS non_unique, |
865
|
|
|
IF tbl.clustered_index_id = idx.index_id |
866
|
|
|
THEN 1 |
867
|
|
|
ELSE NULL |
868
|
|
|
ENDIF AS 'clustered', -- clustered flag |
869
|
|
|
IF idx."unique" = 5 |
870
|
|
|
THEN 1 |
871
|
|
|
ELSE NULL |
872
|
|
|
ENDIF AS with_nulls_not_distinct, -- with_nulls_not_distinct flag |
873
|
|
|
IF pidx.max_key_distance = 1 |
874
|
|
|
THEN 1 |
875
|
|
|
ELSE NULL |
876
|
|
|
ENDIF AS for_olap_workload -- for_olap_workload flag |
877
|
|
|
FROM SYS.SYSIDX AS idx |
878
|
|
|
JOIN SYS.SYSPHYSIDX pidx |
879
|
|
|
ON idx.table_id = pidx.table_id |
880
|
|
|
AND idx.phys_index_id = pidx.phys_index_id |
881
|
|
|
JOIN SYS.SYSIDXCOL AS idxcol |
882
|
|
|
ON idx.table_id = idxcol.table_id AND idx.index_id = idxcol.index_id |
883
|
|
|
JOIN SYS.SYSTABCOL AS col |
884
|
|
|
ON idxcol.table_id = col.table_id AND idxcol.column_id = col.column_id |
885
|
|
|
JOIN SYS.SYSTAB AS tbl |
886
|
|
|
ON idx.table_id = tbl.table_id |
887
|
|
|
WHERE tbl.table_name = %s |
888
|
|
|
AND tbl.creator = USER_ID(%s) |
889
|
|
|
AND idx.index_category != 2 -- exclude indexes implicitly created by foreign key constraints |
890
|
|
|
ORDER BY idx.index_id ASC, idxcol.sequence ASC |
891
|
|
|
SQL |
892
|
|
|
, |
893
|
1327 |
|
$table, |
894
|
1327 |
|
$user |
895
|
|
|
); |
896
|
|
|
} |
897
|
|
|
|
898
|
|
|
/** |
899
|
|
|
* {@inheritdoc} |
900
|
|
|
*/ |
901
|
|
|
public function getListTablesSQL() : string |
902
|
|
|
{ |
903
|
|
|
return "SELECT tbl.table_name |
904
|
|
|
FROM SYS.SYSTAB AS tbl |
905
|
|
|
JOIN SYS.SYSUSER AS usr ON tbl.creator = usr.user_id |
906
|
|
|
JOIN dbo.SYSOBJECTS AS obj ON tbl.object_id = obj.id |
907
|
|
|
WHERE tbl.table_type IN(1, 3) -- 'BASE', 'GBL TEMP' |
908
|
|
|
AND usr.user_name NOT IN('SYS', 'dbo', 'rs_systabgroup') -- exclude system users |
909
|
|
|
AND obj.type = 'U' -- user created tables only |
910
|
|
|
ORDER BY tbl.table_name ASC"; |
911
|
|
|
} |
912
|
|
|
|
913
|
|
|
/** |
914
|
|
|
* {@inheritdoc} |
915
|
|
|
* |
916
|
|
|
* @todo Where is this used? Which information should be retrieved? |
917
|
|
|
*/ |
918
|
|
|
public function getListUsersSQL() : string |
919
|
|
|
{ |
920
|
|
|
return 'SELECT * FROM SYS.SYSUSER ORDER BY user_name ASC'; |
921
|
|
|
} |
922
|
|
|
|
923
|
|
|
/** |
924
|
|
|
* {@inheritdoc} |
925
|
|
|
*/ |
926
|
|
|
public function getListViewsSQL(string $database) : string |
927
|
|
|
{ |
928
|
|
|
return "SELECT tbl.table_name, v.view_def |
929
|
|
|
FROM SYS.SYSVIEW v |
930
|
|
|
JOIN SYS.SYSTAB tbl ON v.view_object_id = tbl.object_id |
931
|
|
|
JOIN SYS.SYSUSER usr ON tbl.creator = usr.user_id |
932
|
|
|
JOIN dbo.SYSOBJECTS obj ON tbl.object_id = obj.id |
933
|
|
|
WHERE usr.user_name NOT IN('SYS', 'dbo', 'rs_systabgroup') -- exclude system users |
934
|
|
|
ORDER BY tbl.table_name ASC"; |
935
|
|
|
} |
936
|
|
|
|
937
|
|
|
/** |
938
|
|
|
* {@inheritdoc} |
939
|
|
|
*/ |
940
|
1876 |
|
public function getLocateExpression(string $string, string $substring, ?string $start = null) : string |
941
|
|
|
{ |
942
|
1876 |
|
if ($start === null) { |
943
|
1876 |
|
return sprintf('LOCATE(%s, %s)', $string, $substring); |
944
|
|
|
} |
945
|
|
|
|
946
|
1876 |
|
return sprintf('LOCATE(%s, %s, %s)', $string, $substring, $start); |
947
|
|
|
} |
948
|
|
|
|
949
|
|
|
/** |
950
|
|
|
* {@inheritdoc} |
951
|
|
|
*/ |
952
|
2452 |
|
public function getMaxIdentifierLength() : int |
953
|
|
|
{ |
954
|
2452 |
|
return 128; |
955
|
|
|
} |
956
|
|
|
|
957
|
|
|
/** |
958
|
|
|
* {@inheritdoc} |
959
|
|
|
*/ |
960
|
1876 |
|
public function getMd5Expression(string $string) : string |
961
|
|
|
{ |
962
|
1876 |
|
return 'HASH(' . $string . ", 'MD5')"; |
963
|
|
|
} |
964
|
|
|
|
965
|
|
|
/** |
966
|
|
|
* {@inheritdoc} |
967
|
|
|
*/ |
968
|
|
|
public function getRegexpExpression() : string |
969
|
|
|
{ |
970
|
|
|
return 'REGEXP'; |
971
|
|
|
} |
972
|
|
|
|
973
|
|
|
/** |
974
|
|
|
* {@inheritdoc} |
975
|
|
|
*/ |
976
|
2705 |
|
public function getName() : string |
977
|
|
|
{ |
978
|
2705 |
|
return 'sqlanywhere'; |
979
|
|
|
} |
980
|
|
|
|
981
|
|
|
/** |
982
|
|
|
* Obtain DBMS specific SQL code portion needed to set a primary key |
983
|
|
|
* declaration to be used in statements like ALTER TABLE. |
984
|
|
|
* |
985
|
|
|
* @param Index $index Index definition |
986
|
|
|
* @param string $name Name of the primary key |
987
|
|
|
* |
988
|
|
|
* @return string DBMS specific SQL code portion needed to set a primary key |
989
|
|
|
* |
990
|
|
|
* @throws InvalidArgumentException If the given index is not a primary key. |
991
|
|
|
*/ |
992
|
2329 |
|
public function getPrimaryKeyDeclarationSQL(Index $index, ?string $name = null) : string |
993
|
|
|
{ |
994
|
2329 |
|
if (! $index->isPrimary()) { |
995
|
|
|
throw new InvalidArgumentException( |
996
|
|
|
'Can only create primary key declarations with getPrimaryKeyDeclarationSQL()' |
997
|
|
|
); |
998
|
|
|
} |
999
|
|
|
|
1000
|
2329 |
|
return $this->getTableConstraintDeclarationSQL($index, $name); |
1001
|
|
|
} |
1002
|
|
|
|
1003
|
|
|
/** |
1004
|
|
|
* {@inheritdoc} |
1005
|
|
|
*/ |
1006
|
1751 |
|
public function getSetTransactionIsolationSQL(int $level) : string |
1007
|
|
|
{ |
1008
|
1751 |
|
return 'SET TEMPORARY OPTION isolation_level = ' . $this->_getTransactionIsolationLevelSQL($level); |
1009
|
|
|
} |
1010
|
|
|
|
1011
|
|
|
/** |
1012
|
|
|
* {@inheritdoc} |
1013
|
|
|
*/ |
1014
|
2401 |
|
public function getSmallIntTypeDeclarationSQL(array $columnDef) : string |
1015
|
|
|
{ |
1016
|
2401 |
|
$columnDef['integer_type'] = 'SMALLINT'; |
1017
|
|
|
|
1018
|
2401 |
|
return $this->_getCommonIntegerTypeDeclarationSQL($columnDef); |
1019
|
|
|
} |
1020
|
|
|
|
1021
|
|
|
/** |
1022
|
|
|
* Returns the SQL statement for starting an existing database. |
1023
|
|
|
* |
1024
|
|
|
* In SQL Anywhere you can start and stop databases on a |
1025
|
|
|
* database server instance. |
1026
|
|
|
* This is a required statement after having created a new database |
1027
|
|
|
* as it has to be explicitly started to be usable. |
1028
|
|
|
* SQL Anywhere does not automatically start a database after creation! |
1029
|
|
|
* |
1030
|
|
|
* @param string $database Name of the database to start. |
1031
|
|
|
*/ |
1032
|
2351 |
|
public function getStartDatabaseSQL(string $database) : string |
1033
|
|
|
{ |
1034
|
2351 |
|
$database = new Identifier($database); |
1035
|
|
|
|
1036
|
2351 |
|
return "START DATABASE '" . $database->getName() . "' AUTOSTOP OFF"; |
1037
|
|
|
} |
1038
|
|
|
|
1039
|
|
|
/** |
1040
|
|
|
* Returns the SQL statement for stopping a running database. |
1041
|
|
|
* |
1042
|
|
|
* In SQL Anywhere you can start and stop databases on a |
1043
|
|
|
* database server instance. |
1044
|
|
|
* This is a required statement before dropping an existing database |
1045
|
|
|
* as it has to be explicitly stopped before it can be dropped. |
1046
|
|
|
* |
1047
|
|
|
* @param string $database Name of the database to stop. |
1048
|
|
|
*/ |
1049
|
2351 |
|
public function getStopDatabaseSQL(string $database) : string |
1050
|
|
|
{ |
1051
|
2351 |
|
$database = new Identifier($database); |
1052
|
|
|
|
1053
|
2351 |
|
return 'STOP DATABASE "' . $database->getName() . '" UNCONDITIONALLY'; |
1054
|
|
|
} |
1055
|
|
|
|
1056
|
|
|
/** |
1057
|
|
|
* {@inheritdoc} |
1058
|
|
|
*/ |
1059
|
1876 |
|
public function getSubstringExpression(string $string, string $start, ?string $length = null) : string |
1060
|
|
|
{ |
1061
|
1876 |
|
if ($length === null) { |
1062
|
1876 |
|
return sprintf('SUBSTRING(%s, %s)', $string, $start); |
1063
|
|
|
} |
1064
|
|
|
|
1065
|
1876 |
|
return sprintf('SUBSTRING(%s, %s, %s)', $string, $start, $length); |
1066
|
|
|
} |
1067
|
|
|
|
1068
|
|
|
/** |
1069
|
|
|
* {@inheritdoc} |
1070
|
|
|
*/ |
1071
|
2352 |
|
public function getTemporaryTableSQL() : string |
1072
|
|
|
{ |
1073
|
2352 |
|
return 'GLOBAL TEMPORARY'; |
1074
|
|
|
} |
1075
|
|
|
|
1076
|
|
|
/** |
1077
|
|
|
* {@inheritdoc} |
1078
|
|
|
*/ |
1079
|
1876 |
|
public function getTimeFormatString() : string |
1080
|
|
|
{ |
1081
|
1876 |
|
return 'H:i:s.u'; |
1082
|
|
|
} |
1083
|
|
|
|
1084
|
|
|
/** |
1085
|
|
|
* {@inheritdoc} |
1086
|
|
|
*/ |
1087
|
2401 |
|
public function getTimeTypeDeclarationSQL(array $fieldDeclaration) : string |
1088
|
|
|
{ |
1089
|
2401 |
|
return 'TIME'; |
1090
|
|
|
} |
1091
|
|
|
|
1092
|
|
|
/** |
1093
|
|
|
* {@inheritdoc} |
1094
|
|
|
*/ |
1095
|
1876 |
|
public function getTrimExpression(string $str, int $mode = TrimMode::UNSPECIFIED, ?string $char = null) : string |
1096
|
|
|
{ |
1097
|
1876 |
|
if (! in_array($mode, [TrimMode::UNSPECIFIED, TrimMode::LEADING, TrimMode::TRAILING, TrimMode::BOTH], true)) { |
1098
|
|
|
throw new InvalidArgumentException( |
1099
|
|
|
sprintf('The value of $mode is expected to be one of the TrimMode constants, %d given', $mode) |
1100
|
|
|
); |
1101
|
|
|
} |
1102
|
|
|
|
1103
|
1876 |
|
if ($char === null) { |
1104
|
1876 |
|
switch ($mode) { |
1105
|
|
|
case TrimMode::LEADING: |
1106
|
1876 |
|
return $this->getLtrimExpression($str); |
1107
|
|
|
case TrimMode::TRAILING: |
1108
|
1876 |
|
return $this->getRtrimExpression($str); |
1109
|
|
|
default: |
1110
|
1876 |
|
return 'TRIM(' . $str . ')'; |
1111
|
|
|
} |
1112
|
|
|
} |
1113
|
|
|
|
1114
|
1876 |
|
$pattern = "'%[^' + " . $char . " + ']%'"; |
1115
|
|
|
|
1116
|
1876 |
|
switch ($mode) { |
1117
|
|
|
case TrimMode::LEADING: |
1118
|
1876 |
|
return 'SUBSTR(' . $str . ', PATINDEX(' . $pattern . ', ' . $str . '))'; |
1119
|
|
|
case TrimMode::TRAILING: |
1120
|
1876 |
|
return 'REVERSE(SUBSTR(REVERSE(' . $str . '), PATINDEX(' . $pattern . ', REVERSE(' . $str . '))))'; |
1121
|
|
|
default: |
1122
|
1876 |
|
return 'REVERSE(SUBSTR(REVERSE(SUBSTR(' . $str . ', PATINDEX(' . $pattern . ', ' . $str . '))), ' . |
1123
|
1876 |
|
'PATINDEX(' . $pattern . ', REVERSE(SUBSTR(' . $str . ', PATINDEX(' . $pattern . ', ' . $str . '))))))'; |
1124
|
|
|
} |
1125
|
|
|
} |
1126
|
|
|
|
1127
|
|
|
/** |
1128
|
|
|
* {@inheritDoc} |
1129
|
|
|
*/ |
1130
|
2352 |
|
public function getCurrentDatabaseExpression() : string |
1131
|
|
|
{ |
1132
|
2352 |
|
return 'DB_NAME()'; |
1133
|
|
|
} |
1134
|
2352 |
|
|
1135
|
|
|
/** |
1136
|
|
|
* {@inheritdoc} |
1137
|
|
|
*/ |
1138
|
|
|
public function getTruncateTableSQL(string $tableName, bool $cascade = false) : string |
1139
|
|
|
{ |
1140
|
1576 |
|
$tableIdentifier = new Identifier($tableName); |
1141
|
|
|
|
1142
|
1576 |
|
return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this); |
1143
|
1576 |
|
} |
1144
|
1576 |
|
|
1145
|
1576 |
|
/** |
1146
|
|
|
* {@inheritdoc} |
1147
|
|
|
*/ |
1148
|
|
|
public function getCreateSequenceSQL(Sequence $sequence) : string |
1149
|
|
|
{ |
1150
|
|
|
return 'CREATE SEQUENCE ' . $sequence->getQuotedName($this) . |
1151
|
1576 |
|
' INCREMENT BY ' . $sequence->getAllocationSize() . |
1152
|
|
|
' START WITH ' . $sequence->getInitialValue() . |
1153
|
1576 |
|
' MINVALUE ' . $sequence->getInitialValue(); |
1154
|
1576 |
|
} |
1155
|
|
|
|
1156
|
|
|
/** |
1157
|
|
|
* {@inheritdoc} |
1158
|
|
|
*/ |
1159
|
|
|
public function getAlterSequenceSQL(Sequence $sequence) : string |
1160
|
1576 |
|
{ |
1161
|
|
|
return 'ALTER SEQUENCE ' . $sequence->getQuotedName($this) . |
1162
|
1576 |
|
' INCREMENT BY ' . $sequence->getAllocationSize(); |
1163
|
1576 |
|
} |
1164
|
|
|
|
1165
|
|
|
/** |
1166
|
1576 |
|
* {@inheritdoc} |
1167
|
|
|
*/ |
1168
|
|
|
public function getDropSequenceSQL($sequence) : string |
1169
|
|
|
{ |
1170
|
|
|
if ($sequence instanceof Sequence) { |
1171
|
|
|
$sequence = $sequence->getQuotedName($this); |
1172
|
|
|
} |
1173
|
|
|
|
1174
|
|
|
return 'DROP SEQUENCE ' . $sequence; |
1175
|
|
|
} |
1176
|
|
|
|
1177
|
|
|
/** |
1178
|
|
|
* {@inheritdoc} |
1179
|
|
|
*/ |
1180
|
1576 |
|
public function getListSequencesSQL(string $database) : string |
1181
|
|
|
{ |
1182
|
1576 |
|
return 'SELECT sequence_name, increment_by, start_with, min_value FROM SYS.SYSSEQUENCE'; |
1183
|
|
|
} |
1184
|
|
|
|
1185
|
|
|
/** |
1186
|
|
|
* {@inheritdoc} |
1187
|
|
|
*/ |
1188
|
1601 |
|
public function getSequenceNextValSQL(string $sequenceName) : string |
1189
|
|
|
{ |
1190
|
1601 |
|
return 'SELECT ' . $sequenceName . '.NEXTVAL'; |
1191
|
|
|
} |
1192
|
|
|
|
1193
|
|
|
/** |
1194
|
|
|
* {@inheritdoc} |
1195
|
|
|
*/ |
1196
|
1826 |
|
public function supportsSequences() : bool |
1197
|
|
|
{ |
1198
|
1826 |
|
return true; |
1199
|
|
|
} |
1200
|
|
|
|
1201
|
|
|
/** |
1202
|
|
|
* {@inheritdoc} |
1203
|
|
|
*/ |
1204
|
2719 |
|
public function getDateTimeTzTypeDeclarationSQL(array $fieldDeclaration) : string |
1205
|
|
|
{ |
1206
|
2719 |
|
return 'TIMESTAMP WITH TIME ZONE'; |
1207
|
|
|
} |
1208
|
|
|
|
1209
|
|
|
/** |
1210
|
|
|
* {@inheritdoc} |
1211
|
|
|
*/ |
1212
|
1626 |
|
public function hasNativeGuidType() : bool |
1213
|
|
|
{ |
1214
|
1626 |
|
return true; |
1215
|
|
|
} |
1216
|
|
|
|
1217
|
|
|
/** |
1218
|
|
|
* {@inheritdoc} |
1219
|
|
|
*/ |
1220
|
2688 |
|
public function prefersIdentityColumns() : bool |
1221
|
|
|
{ |
1222
|
2688 |
|
return true; |
1223
|
|
|
} |
1224
|
|
|
|
1225
|
|
|
/** |
1226
|
|
|
* {@inheritdoc} |
1227
|
|
|
*/ |
1228
|
1 |
|
public function supportsCommentOnStatement() : bool |
1229
|
|
|
{ |
1230
|
1 |
|
return true; |
1231
|
|
|
} |
1232
|
|
|
|
1233
|
|
|
/** |
1234
|
|
|
* {@inheritdoc} |
1235
|
|
|
*/ |
1236
|
2686 |
|
public function supportsIdentityColumns() : bool |
1237
|
|
|
{ |
1238
|
2686 |
|
return true; |
1239
|
2686 |
|
} |
1240
|
|
|
|
1241
|
2686 |
|
/** |
1242
|
|
|
* {@inheritdoc} |
1243
|
|
|
*/ |
1244
|
|
|
protected function _getCommonIntegerTypeDeclarationSQL(array $columnDef) : string |
1245
|
|
|
{ |
1246
|
|
|
$unsigned = ! empty($columnDef['unsigned']) ? 'UNSIGNED ' : ''; |
1247
|
2687 |
|
$autoincrement = ! empty($columnDef['autoincrement']) ? ' IDENTITY' : ''; |
1248
|
|
|
|
1249
|
2687 |
|
return $unsigned . $columnDef['integer_type'] . $autoincrement; |
1250
|
2687 |
|
} |
1251
|
|
|
|
1252
|
2687 |
|
/** |
1253
|
|
|
* {@inheritdoc} |
1254
|
|
|
*/ |
1255
|
|
|
protected function _getCreateTableSQL(string $tableName, array $columns, array $options = []) : array |
1256
|
|
|
{ |
1257
|
|
|
$columnListSql = $this->getColumnDeclarationListSQL($columns); |
1258
|
2687 |
|
$indexSql = []; |
1259
|
|
|
|
1260
|
2679 |
|
if (! empty($options['uniqueConstraints'])) { |
1261
|
2679 |
|
foreach ((array) $options['uniqueConstraints'] as $name => $definition) { |
1262
|
|
|
$columnListSql .= ', ' . $this->getUniqueConstraintDeclarationSQL($name, $definition); |
1263
|
|
|
} |
1264
|
|
|
} |
1265
|
2687 |
|
|
1266
|
2681 |
|
if (! empty($options['indexes'])) { |
1267
|
|
|
/** @var Index $index */ |
1268
|
2681 |
|
foreach ((array) $options['indexes'] as $index) { |
1269
|
|
|
$indexSql[] = $this->getCreateIndexSQL($index, $tableName); |
1270
|
|
|
} |
1271
|
|
|
} |
1272
|
2681 |
|
|
1273
|
|
|
if (! empty($options['primary'])) { |
1274
|
|
|
$flags = ''; |
1275
|
2687 |
|
|
1276
|
2652 |
|
if (isset($options['primary_index']) && $options['primary_index']->hasFlag('clustered')) { |
1277
|
2652 |
|
$flags = ' CLUSTERED '; |
1278
|
|
|
} |
1279
|
|
|
|
1280
|
|
|
$columnListSql .= ', PRIMARY KEY' . $flags . ' (' . implode(', ', array_unique(array_values((array) $options['primary']))) . ')'; |
1281
|
2687 |
|
} |
1282
|
2687 |
|
|
1283
|
|
|
if (! empty($options['foreignKeys'])) { |
1284
|
2687 |
|
foreach ((array) $options['foreignKeys'] as $definition) { |
1285
|
2626 |
|
$columnListSql .= ', ' . $this->getForeignKeyDeclarationSQL($definition); |
1286
|
|
|
} |
1287
|
|
|
} |
1288
|
2687 |
|
|
1289
|
|
|
$query = 'CREATE TABLE ' . $tableName . ' (' . $columnListSql; |
1290
|
2687 |
|
$check = $this->getCheckDeclarationSQL($columns); |
1291
|
|
|
|
1292
|
|
|
if (! empty($check)) { |
1293
|
|
|
$query .= ', ' . $check; |
1294
|
|
|
} |
1295
|
|
|
|
1296
|
1751 |
|
$query .= ')'; |
1297
|
|
|
|
1298
|
|
|
return array_merge([$query], $indexSql); |
1299
|
1751 |
|
} |
1300
|
1751 |
|
|
1301
|
1751 |
|
/** |
1302
|
1751 |
|
* {@inheritdoc} |
1303
|
1751 |
|
*/ |
1304
|
1751 |
|
protected function _getTransactionIsolationLevelSQL(int $level) : string |
1305
|
1751 |
|
{ |
1306
|
1751 |
|
switch ($level) { |
1307
|
|
|
case TransactionIsolationLevel::READ_UNCOMMITTED: |
1308
|
|
|
return '0'; |
1309
|
|
|
case TransactionIsolationLevel::READ_COMMITTED: |
1310
|
|
|
return '1'; |
1311
|
|
|
case TransactionIsolationLevel::REPEATABLE_READ: |
1312
|
|
|
return '2'; |
1313
|
|
|
case TransactionIsolationLevel::SERIALIZABLE: |
1314
|
|
|
return '3'; |
1315
|
1731 |
|
default: |
1316
|
|
|
throw new InvalidArgumentException(sprintf('Invalid isolation level %d.', $level)); |
1317
|
1731 |
|
} |
1318
|
|
|
} |
1319
|
1731 |
|
|
1320
|
26 |
|
/** |
1321
|
|
|
* {@inheritdoc} |
1322
|
|
|
*/ |
1323
|
1730 |
|
protected function doModifyLimitQuery(string $query, ?int $limit, int $offset) : string |
1324
|
|
|
{ |
1325
|
|
|
$limitOffsetClause = $this->getTopClauseSQL($limit, $offset); |
1326
|
|
|
|
1327
|
1730 |
|
if ($limitOffsetClause === '') { |
1328
|
|
|
return $query; |
1329
|
|
|
} |
1330
|
1731 |
|
|
1331
|
|
|
if (! preg_match('/^\s*(SELECT\s+(DISTINCT\s+)?)(.*)/i', $query, $matches)) { |
1332
|
1731 |
|
return $query; |
1333
|
1702 |
|
} |
1334
|
|
|
|
1335
|
|
|
return $matches[1] . $limitOffsetClause . ' ' . $matches[3]; |
1336
|
1729 |
|
} |
1337
|
|
|
|
1338
|
|
|
private function getTopClauseSQL(?int $limit, ?int $offset) : string |
1339
|
|
|
{ |
1340
|
|
|
if ($offset > 0) { |
1341
|
|
|
return sprintf('TOP %s START AT %d', $limit ?? 'ALL', $offset + 1); |
1342
|
|
|
} |
1343
|
|
|
|
1344
|
|
|
return $limit === null ? '' : 'TOP ' . $limit; |
1345
|
2684 |
|
} |
1346
|
|
|
|
1347
|
2684 |
|
/** |
1348
|
2001 |
|
* Return the INDEX query section dealing with non-standard |
1349
|
2001 |
|
* SQL Anywhere options. |
1350
|
|
|
* |
1351
|
|
|
* @param Index $index Index definition |
1352
|
|
|
*/ |
1353
|
2683 |
|
protected function getAdvancedIndexOptionsSQL(Index $index) : string |
1354
|
|
|
{ |
1355
|
2683 |
|
if ($index->hasFlag('with_nulls_distinct') && $index->hasFlag('with_nulls_not_distinct')) { |
1356
|
2026 |
|
throw new UnexpectedValueException( |
1357
|
|
|
'An Index can either have a "with_nulls_distinct" or "with_nulls_not_distinct" flag but not both.' |
1358
|
|
|
); |
1359
|
2683 |
|
} |
1360
|
2026 |
|
|
1361
|
|
|
$sql = ''; |
1362
|
|
|
|
1363
|
2683 |
|
if (! $index->isPrimary() && $index->hasFlag('for_olap_workload')) { |
1364
|
2026 |
|
$sql .= ' FOR OLAP WORKLOAD'; |
1365
|
|
|
} |
1366
|
|
|
|
1367
|
2683 |
|
if (! $index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_not_distinct')) { |
1368
|
|
|
return ' WITH NULLS NOT DISTINCT' . $sql; |
1369
|
|
|
} |
1370
|
|
|
|
1371
|
|
|
if (! $index->isPrimary() && $index->isUnique() && $index->hasFlag('with_nulls_distinct')) { |
1372
|
|
|
return ' WITH NULLS DISTINCT' . $sql; |
1373
|
|
|
} |
1374
|
|
|
|
1375
|
|
|
return $sql; |
1376
|
|
|
} |
1377
|
|
|
|
1378
|
2332 |
|
/** |
1379
|
|
|
* Returns the SQL snippet for creating a table constraint. |
1380
|
2332 |
|
* |
1381
|
|
|
* @param Constraint $constraint The table constraint to create the SQL snippet for. |
1382
|
|
|
* @param string|null $name The table constraint name to use if any. |
1383
|
|
|
* |
1384
|
2332 |
|
* @throws InvalidArgumentException If the given table constraint type is not supported by this method. |
1385
|
2051 |
|
*/ |
1386
|
|
|
protected function getTableConstraintDeclarationSQL(Constraint $constraint, ?string $name = null) : string |
1387
|
|
|
{ |
1388
|
2331 |
|
if ($constraint instanceof ForeignKeyConstraint) { |
1389
|
2076 |
|
return $this->getForeignKeyDeclarationSQL($constraint); |
1390
|
|
|
} |
1391
|
2076 |
|
|
1392
|
|
|
if (! $constraint instanceof Index) { |
1393
|
|
|
throw new InvalidArgumentException(sprintf('Unsupported constraint type %s.', get_class($constraint))); |
1394
|
|
|
} |
1395
|
2330 |
|
|
1396
|
|
|
if (! $constraint->isPrimary() && ! $constraint->isUnique()) { |
1397
|
2330 |
|
throw new InvalidArgumentException( |
1398
|
2301 |
|
'Can only create primary, unique or foreign key constraint declarations, no common index declarations ' . |
1399
|
|
|
'with getTableConstraintDeclarationSQL().' |
1400
|
|
|
); |
1401
|
2329 |
|
} |
1402
|
2329 |
|
|
1403
|
|
|
$constraintColumns = $constraint->getQuotedColumns($this); |
1404
|
2329 |
|
|
1405
|
2327 |
|
if (empty($constraintColumns)) { |
1406
|
2327 |
|
throw new InvalidArgumentException('Incomplete definition. "columns" required.'); |
1407
|
|
|
} |
1408
|
|
|
|
1409
|
2329 |
|
$sql = ''; |
1410
|
2327 |
|
$flags = ''; |
1411
|
|
|
|
1412
|
|
|
if (! empty($name)) { |
1413
|
2329 |
|
$name = new Identifier($name); |
1414
|
2329 |
|
$sql .= 'CONSTRAINT ' . $name->getQuotedName($this) . ' '; |
1415
|
|
|
} |
1416
|
|
|
|
1417
|
851 |
|
if ($constraint->hasFlag('clustered')) { |
1418
|
|
|
$flags = 'CLUSTERED '; |
1419
|
|
|
} |
1420
|
|
|
|
1421
|
|
|
if ($constraint->isPrimary()) { |
1422
|
|
|
return $sql . 'PRIMARY KEY ' . $flags . '(' . $this->getIndexFieldDeclarationListSQL($constraintColumns) . ')'; |
1423
|
2684 |
|
} |
1424
|
|
|
|
1425
|
2684 |
|
return $sql . 'UNIQUE ' . $flags . '(' . $this->getIndexFieldDeclarationListSQL($constraintColumns) . ')'; |
1426
|
2684 |
|
} |
1427
|
2026 |
|
|
1428
|
|
|
/** |
1429
|
|
|
* {@inheritdoc} |
1430
|
2684 |
|
*/ |
1431
|
2028 |
|
protected function getCreateIndexSQLFlags(Index $index) : string |
1432
|
|
|
{ |
1433
|
|
|
$type = ''; |
1434
|
2684 |
|
if ($index->hasFlag('virtual')) { |
1435
|
2026 |
|
$type .= 'VIRTUAL '; |
1436
|
|
|
} |
1437
|
|
|
|
1438
|
2684 |
|
if ($index->isUnique()) { |
1439
|
|
|
$type .= 'UNIQUE '; |
1440
|
|
|
} |
1441
|
|
|
|
1442
|
|
|
if ($index->hasFlag('clustered')) { |
1443
|
|
|
$type .= 'CLUSTERED '; |
1444
|
355 |
|
} |
1445
|
|
|
|
1446
|
355 |
|
return $type; |
1447
|
|
|
} |
1448
|
|
|
|
1449
|
|
|
/** |
1450
|
|
|
* {@inheritdoc} |
1451
|
|
|
*/ |
1452
|
2729 |
|
protected function getRenameIndexSQL(string $oldIndexName, Index $index, string $tableName) : array |
1453
|
|
|
{ |
1454
|
2729 |
|
return ['ALTER INDEX ' . $oldIndexName . ' ON ' . $tableName . ' RENAME TO ' . $index->getQuotedName($this)]; |
1455
|
|
|
} |
1456
|
|
|
|
1457
|
|
|
/** |
1458
|
|
|
* {@inheritdoc} |
1459
|
|
|
*/ |
1460
|
1806 |
|
protected function getReservedKeywordsClass() : string |
1461
|
|
|
{ |
1462
|
1806 |
|
return Keywords\SQLAnywhereKeywords::class; |
1463
|
|
|
} |
1464
|
|
|
|
1465
|
|
|
/** |
1466
|
|
|
* {@inheritdoc} |
1467
|
|
|
*/ |
1468
|
|
|
protected function initializeDoctrineTypeMappings() : void |
1469
|
|
|
{ |
1470
|
|
|
$this->doctrineTypeMapping = [ |
1471
|
|
|
'bigint' => 'bigint', |
1472
|
|
|
'binary' => 'binary', |
1473
|
|
|
'bit' => 'boolean', |
1474
|
|
|
'char' => 'string', |
1475
|
|
|
'decimal' => 'decimal', |
1476
|
|
|
'date' => 'date', |
1477
|
|
|
'datetime' => 'datetime', |
1478
|
|
|
'double' => 'float', |
1479
|
|
|
'float' => 'float', |
1480
|
|
|
'image' => 'blob', |
1481
|
|
|
'int' => 'integer', |
1482
|
|
|
'integer' => 'integer', |
1483
|
|
|
'long binary' => 'blob', |
1484
|
|
|
'long nvarchar' => 'text', |
1485
|
|
|
'long varbit' => 'text', |
1486
|
|
|
'long varchar' => 'text', |
1487
|
|
|
'money' => 'decimal', |
1488
|
|
|
'nchar' => 'string', |
1489
|
|
|
'ntext' => 'text', |
1490
|
|
|
'numeric' => 'decimal', |
1491
|
|
|
'nvarchar' => 'string', |
1492
|
|
|
'smalldatetime' => 'datetime', |
1493
|
|
|
'smallint' => 'smallint', |
1494
|
|
|
'smallmoney' => 'decimal', |
1495
|
|
|
'text' => 'text', |
1496
|
|
|
'time' => 'time', |
1497
|
|
|
'timestamp' => 'datetime', |
1498
|
|
|
'timestamp with time zone' => 'datetime', |
1499
|
|
|
'tinyint' => 'smallint', |
1500
|
|
|
'uniqueidentifier' => 'guid', |
1501
|
|
|
'uniqueidentifierstr' => 'guid', |
1502
|
|
|
'unsigned bigint' => 'bigint', |
1503
|
1806 |
|
'unsigned int' => 'integer', |
1504
|
|
|
'unsigned smallint' => 'smallint', |
1505
|
|
|
'unsigned tinyint' => 'smallint', |
1506
|
|
|
'varbinary' => 'binary', |
1507
|
|
|
'varbit' => 'string', |
1508
|
|
|
'varchar' => 'string', |
1509
|
|
|
'xml' => 'text', |
1510
|
|
|
]; |
1511
|
|
|
} |
1512
|
|
|
} |
1513
|
|
|
|
The
break
statement is not necessary if it is preceded for example by areturn
statement:If you would like to keep this construct to be consistent with other
case
statements, you can safely mark this issue as a false-positive.