Completed
Pull Request — develop (#3562)
by Sergei
72:46 queued 07:36
created

getQuotesReservedKeywordInTruncateTableSQL()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Tests\DBAL\Platforms;
6
7
use Doctrine\DBAL\DBALException;
8
use Doctrine\DBAL\LockMode;
9
use Doctrine\DBAL\Platforms\AbstractPlatform;
10
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
11
use Doctrine\DBAL\Platforms\TrimMode;
12
use Doctrine\DBAL\Schema\Column;
13
use Doctrine\DBAL\Schema\ColumnDiff;
14
use Doctrine\DBAL\Schema\Comparator;
15
use Doctrine\DBAL\Schema\Constraint;
16
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
17
use Doctrine\DBAL\Schema\Index;
18
use Doctrine\DBAL\Schema\Sequence;
19
use Doctrine\DBAL\Schema\Table;
20
use Doctrine\DBAL\Schema\TableDiff;
21
use Doctrine\DBAL\Schema\UniqueConstraint;
22
use Doctrine\DBAL\TransactionIsolationLevel;
23
use Doctrine\DBAL\Types\Type;
24
use InvalidArgumentException;
25
use function mt_rand;
26
use function strlen;
27
use function substr;
28
29
class SQLAnywherePlatformTest extends AbstractPlatformTestCase
30
{
31
    /** @var SQLAnywherePlatform */
32
    protected $platform;
33
34
    public function createPlatform()
35
    {
36
        return new SQLAnywherePlatform();
37
    }
38
39
    public function getGenerateAlterTableSql()
40
    {
41
        return [
42
            "ALTER TABLE mytable ADD quota INT DEFAULT NULL, DROP foo, ALTER baz VARCHAR(1) DEFAULT 'def' NOT NULL, ALTER bloo BIT DEFAULT '0' NOT NULL",
43
            'ALTER TABLE mytable RENAME userlist',
44
        ];
45
    }
46
47
    public function getGenerateForeignKeySql()
48
    {
49
        return 'ALTER TABLE test ADD FOREIGN KEY (fk_name_id) REFERENCES other_table (id)';
50
    }
51
52
    public function getGenerateIndexSql()
53
    {
54
        return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
55
    }
56
57
    public function getGenerateTableSql()
58
    {
59
        return 'CREATE TABLE test (id INT IDENTITY NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY (id))';
60
    }
61
62
    public function getGenerateTableWithMultiColumnUniqueIndexSql()
63
    {
64
        return [
65
            'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
66
            'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
67
        ];
68
    }
69
70
    public function getGenerateUniqueIndexSql()
71
    {
72
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
73
    }
74
75
    protected function getQuotedColumnInForeignKeySQL()
76
    {
77
        return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL, CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar"), CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar"))'];
78
    }
79
80
    protected function getQuotedColumnInIndexSQL()
81
    {
82
        return [
83
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)',
84
            'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")',
85
        ];
86
    }
87
88
    protected function getQuotedNameInIndexSQL()
89
    {
90
        return [
91
            'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
92
            'CREATE INDEX "key" ON test (column1)',
93
        ];
94
    }
95
96
    protected function getQuotedColumnInPrimaryKeySQL()
97
    {
98
        return ['CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY ("create"))'];
99
    }
100
101
    public function getCreateTableColumnCommentsSQL()
102
    {
103
        return [
104
            'CREATE TABLE test (id INT NOT NULL, PRIMARY KEY (id))',
105
            "COMMENT ON COLUMN test.id IS 'This is a comment'",
106
        ];
107
    }
108
109
    public function getAlterTableColumnCommentsSQL()
110
    {
111
        return [
112
            'ALTER TABLE mytable ADD quota INT NOT NULL',
113
            "COMMENT ON COLUMN mytable.quota IS 'A comment'",
114
            'COMMENT ON COLUMN mytable.foo IS NULL',
115
            "COMMENT ON COLUMN mytable.baz IS 'B comment'",
116
        ];
117
    }
118
119
    public function getCreateTableColumnTypeCommentsSQL()
120
    {
121
        return [
122
            'CREATE TABLE test (id INT NOT NULL, data TEXT NOT NULL, PRIMARY KEY (id))',
123
            "COMMENT ON COLUMN test.data IS '(DC2Type:array)'",
124
        ];
125
    }
126
127
    public function testHasCorrectPlatformName()
128
    {
129
        self::assertEquals('sqlanywhere', $this->platform->getName());
130
    }
131
132
    public function testGeneratesCreateTableSQLWithCommonIndexes()
133
    {
134
        $table = new Table('test');
135
        $table->addColumn('id', 'integer');
136
        $table->addColumn('name', 'string', ['length' => 50]);
137
        $table->setPrimaryKey(['id']);
138
        $table->addIndex(['name']);
139
        $table->addIndex(['id', 'name'], 'composite_idx');
140
141
        self::assertEquals(
142
            [
143
                'CREATE TABLE test (id INT NOT NULL, name VARCHAR(50) NOT NULL, PRIMARY KEY (id))',
144
                'CREATE INDEX IDX_D87F7E0C5E237E06 ON test (name)',
145
                'CREATE INDEX composite_idx ON test (id, name)',
146
            ],
147
            $this->platform->getCreateTableSQL($table)
148
        );
149
    }
150
151
    public function testGeneratesCreateTableSQLWithForeignKeyConstraints()
152
    {
153
        $table = new Table('test');
154
        $table->addColumn('id', 'integer');
155
        $table->addColumn('fk_1', 'integer');
156
        $table->addColumn('fk_2', 'integer');
157
        $table->setPrimaryKey(['id']);
158
        $table->addForeignKeyConstraint('foreign_table', ['fk_1', 'fk_2'], ['pk_1', 'pk_2']);
159
        $table->addForeignKeyConstraint(
160
            'foreign_table2',
161
            ['fk_1', 'fk_2'],
162
            ['pk_1', 'pk_2'],
163
            [],
164
            'named_fk'
165
        );
166
167
        self::assertEquals(
168
            ['CREATE TABLE test (id INT NOT NULL, fk_1 INT NOT NULL, fk_2 INT NOT NULL, ' .
169
                'CONSTRAINT FK_D87F7E0C177612A38E7F4319 FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table (pk_1, pk_2), ' .
170
                'CONSTRAINT named_fk FOREIGN KEY (fk_1, fk_2) REFERENCES foreign_table2 (pk_1, pk_2))',
171
            ],
172
            $this->platform->getCreateTableSQL($table, AbstractPlatform::CREATE_FOREIGNKEYS)
173
        );
174
    }
175
176
    public function testGeneratesCreateTableSQLWithCheckConstraints()
177
    {
178
        $table = new Table('test');
179
        $table->addColumn('id', 'integer');
180
        $table->addColumn('check_max', 'integer', ['platformOptions' => ['max' => 10]]);
181
        $table->addColumn('check_min', 'integer', ['platformOptions' => ['min' => 10]]);
182
        $table->setPrimaryKey(['id']);
183
184
        self::assertEquals(
185
            ['CREATE TABLE test (id INT NOT NULL, check_max INT NOT NULL, check_min INT NOT NULL, PRIMARY KEY (id), CHECK (check_max <= 10), CHECK (check_min >= 10))'],
186
            $this->platform->getCreateTableSQL($table)
187
        );
188
    }
189
190
    public function testGeneratesTableAlterationWithRemovedColumnCommentSql()
191
    {
192
        $table = new Table('mytable');
193
        $table->addColumn('foo', 'string', ['comment' => 'foo comment']);
194
195
        $tableDiff                        = new TableDiff('mytable');
196
        $tableDiff->fromTable             = $table;
197
        $tableDiff->changedColumns['foo'] = new ColumnDiff(
198
            'foo',
199
            new Column('foo', Type::getType('string')),
200
            ['comment']
201
        );
202
203
        self::assertEquals(
204
            ['COMMENT ON COLUMN mytable.foo IS NULL'],
205
            $this->platform->getAlterTableSQL($tableDiff)
206
        );
207
    }
208
209
    /**
210
     * @dataProvider getLockHints
211
     */
212
    public function testAppendsLockHint($lockMode, $lockHint)
213
    {
214
        $fromClause     = 'FROM users';
215
        $expectedResult = $fromClause . $lockHint;
216
217
        self::assertSame($expectedResult, $this->platform->appendLockHint($fromClause, $lockMode));
218
    }
219
220
    public function getLockHints()
221
    {
222
        return [
223
            [null, ''],
224
            [LockMode::NONE, ' WITH (NOLOCK)'],
225
            [LockMode::OPTIMISTIC, ''],
226
            [LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'],
227
            [LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'],
228
        ];
229
    }
230
231
    public function testHasCorrectMaxIdentifierLength()
232
    {
233
        self::assertEquals(128, $this->platform->getMaxIdentifierLength());
234
    }
235
236
    public function testFixesSchemaElementNames()
237
    {
238
        $maxIdentifierLength = $this->platform->getMaxIdentifierLength();
239
        $characters          = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
240
        $schemaElementName   = '';
241
242
        for ($i = 0; $i < $maxIdentifierLength + 100; $i++) {
243
            $schemaElementName .= $characters[mt_rand(0, strlen($characters) - 1)];
244
        }
245
246
        $fixedSchemaElementName = substr($schemaElementName, 0, $maxIdentifierLength);
247
248
        self::assertEquals(
249
            $fixedSchemaElementName,
250
            $this->platform->fixSchemaElementName($schemaElementName)
251
        );
252
        self::assertEquals(
253
            $fixedSchemaElementName,
254
            $this->platform->fixSchemaElementName($fixedSchemaElementName)
255
        );
256
    }
257
258
    public function testGeneratesColumnTypesDeclarationSQL()
259
    {
260
        $fullColumnDef = [
261
            'length' => 10,
262
            'fixed' => true,
263
            'unsigned' => true,
264
            'autoincrement' => true,
265
        ];
266
267
        self::assertEquals('SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL([]));
268
        self::assertEquals('UNSIGNED SMALLINT', $this->platform->getSmallIntTypeDeclarationSQL(['unsigned' => true]));
269
        self::assertEquals('UNSIGNED SMALLINT IDENTITY', $this->platform->getSmallIntTypeDeclarationSQL($fullColumnDef));
270
        self::assertEquals('INT', $this->platform->getIntegerTypeDeclarationSQL([]));
271
        self::assertEquals('UNSIGNED INT', $this->platform->getIntegerTypeDeclarationSQL(['unsigned' => true]));
272
        self::assertEquals('UNSIGNED INT IDENTITY', $this->platform->getIntegerTypeDeclarationSQL($fullColumnDef));
273
        self::assertEquals('BIGINT', $this->platform->getBigIntTypeDeclarationSQL([]));
274
        self::assertEquals('UNSIGNED BIGINT', $this->platform->getBigIntTypeDeclarationSQL(['unsigned' => true]));
275
        self::assertEquals('UNSIGNED BIGINT IDENTITY', $this->platform->getBigIntTypeDeclarationSQL($fullColumnDef));
276
        self::assertEquals('LONG BINARY', $this->platform->getBlobTypeDeclarationSQL($fullColumnDef));
277
        self::assertEquals('BIT', $this->platform->getBooleanTypeDeclarationSQL($fullColumnDef));
278
        self::assertEquals('TEXT', $this->platform->getClobTypeDeclarationSQL($fullColumnDef));
279
        self::assertEquals('DATE', $this->platform->getDateTypeDeclarationSQL($fullColumnDef));
280
        self::assertEquals('DATETIME', $this->platform->getDateTimeTypeDeclarationSQL($fullColumnDef));
281
        self::assertEquals('TIME', $this->platform->getTimeTypeDeclarationSQL($fullColumnDef));
282
        self::assertEquals('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL($fullColumnDef));
283
284
        self::assertEquals(1, $this->platform->getVarcharDefaultLength());
285
        self::assertEquals(32767, $this->platform->getVarcharMaxLength());
286
    }
287
288
    public function testHasNativeGuidType()
289
    {
290
        self::assertTrue($this->platform->hasNativeGuidType());
291
    }
292
293
    public function testGeneratesDDLSnippets()
294
    {
295
        self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('foobar'));
296
        self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('"foobar"'));
297
        self::assertEquals("CREATE DATABASE 'create'", $this->platform->getCreateDatabaseSQL('create'));
298
        self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('foobar'));
299
        self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('"foobar"'));
300
        self::assertEquals("DROP DATABASE 'create'", $this->platform->getDropDatabaseSQL('create'));
301
        self::assertEquals('CREATE GLOBAL TEMPORARY TABLE', $this->platform->getCreateTemporaryTableSnippetSQL());
302
        self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('foobar'));
303
        self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('"foobar"'));
304
        self::assertEquals("START DATABASE 'create' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('create'));
305
        self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('foobar'));
306
        self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('"foobar"'));
307
        self::assertEquals('STOP DATABASE "create" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('create'));
308
        self::assertEquals('TRUNCATE TABLE foobar', $this->platform->getTruncateTableSQL('foobar'));
309
310
        $viewSql = 'SELECT * FROM footable';
311
        self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->platform->getCreateViewSQL('fooview', $viewSql));
312
        self::assertEquals('DROP VIEW fooview', $this->platform->getDropViewSQL('fooview'));
313
    }
314
315
    public function testGeneratesPrimaryKeyDeclarationSQL()
316
    {
317
        self::assertEquals(
318
            'CONSTRAINT pk PRIMARY KEY CLUSTERED (a, b)',
319
            $this->platform->getPrimaryKeyDeclarationSQL(
320
                new Index(null, ['a', 'b'], true, true, ['clustered']),
321
                'pk'
322
            )
323
        );
324
        self::assertEquals(
325
            'PRIMARY KEY (a, b)',
326
            $this->platform->getPrimaryKeyDeclarationSQL(
327
                new Index(null, ['a', 'b'], true, true)
328
            )
329
        );
330
    }
331
332
    public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns()
333
    {
334
        $this->expectException(InvalidArgumentException::class);
335
336
        $this->platform->getPrimaryKeyDeclarationSQL(new Index('pk', [], true, true));
337
    }
338
339
    public function testGeneratesCreateUnnamedPrimaryKeySQL()
340
    {
341
        self::assertEquals(
342
            'ALTER TABLE foo ADD PRIMARY KEY CLUSTERED (a, b)',
343
            $this->platform->getCreatePrimaryKeySQL(
344
                new Index('pk', ['a', 'b'], true, true, ['clustered']),
345
                'foo'
346
            )
347
        );
348
        self::assertEquals(
349
            'ALTER TABLE foo ADD PRIMARY KEY (a, b)',
350
            $this->platform->getCreatePrimaryKeySQL(
351
                new Index('any_pk_name', ['a', 'b'], true, true),
352
                new Table('foo')
353
            )
354
        );
355
    }
356
357
    public function testGeneratesUniqueConstraintDeclarationSQL()
358
    {
359
        self::assertEquals(
360
            'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)',
361
            $this->platform->getUniqueConstraintDeclarationSQL(
362
                'unique_constraint',
363
                new UniqueConstraint('', ['a', 'b'], ['clustered'])
364
            )
365
        );
366
        self::assertEquals(
367
            'CONSTRAINT UNIQUE (a, b)',
368
            $this->platform->getUniqueConstraintDeclarationSQL('', new UniqueConstraint('', ['a', 'b']))
369
        );
370
    }
371
372
    public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns()
373
    {
374
        $this->expectException(InvalidArgumentException::class);
375
376
        $this->platform->getUniqueConstraintDeclarationSQL('constr', new UniqueConstraint('constr', []));
377
    }
378
379
    public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL()
380
    {
381
        self::assertEquals(
382
            'CONSTRAINT fk ' .
383
                'NOT NULL FOREIGN KEY (a, b) ' .
384
                'REFERENCES foreign_table (c, d) ' .
385
                'MATCH UNIQUE SIMPLE ON UPDATE CASCADE ON DELETE SET NULL CHECK ON COMMIT CLUSTERED FOR OLAP WORKLOAD',
386
            $this->platform->getForeignKeyDeclarationSQL(
387
                new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd'], 'fk', [
388
                    'notnull' => true,
389
                    'match' => SQLAnywherePlatform::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE,
390
                    'onUpdate' => 'CASCADE',
391
                    'onDelete' => 'SET NULL',
392
                    'check_on_commit' => true,
393
                    'clustered' => true,
394
                    'for_olap_workload' => true,
395
                ])
396
            )
397
        );
398
        self::assertEquals(
399
            'FOREIGN KEY (a, b) REFERENCES foreign_table (c, d)',
400
            $this->platform->getForeignKeyDeclarationSQL(
401
                new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd'])
402
            )
403
        );
404
    }
405
406
    public function testGeneratesForeignKeyMatchClausesSQL()
407
    {
408
        self::assertEquals('SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(1));
409
        self::assertEquals('FULL', $this->platform->getForeignKeyMatchClauseSQL(2));
410
        self::assertEquals('UNIQUE SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(129));
411
        self::assertEquals('UNIQUE FULL', $this->platform->getForeignKeyMatchClauseSQL(130));
412
    }
413
414
    public function testCannotGenerateInvalidForeignKeyMatchClauseSQL()
415
    {
416
        $this->expectException(InvalidArgumentException::class);
417
418
        $this->platform->getForeignKeyMatchCLauseSQL(3);
419
    }
420
421
    public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns()
422
    {
423
        $this->expectException(InvalidArgumentException::class);
424
        $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint([], 'foreign_tbl', ['c', 'd']));
425
    }
426
427
    public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns()
428
    {
429
        $this->expectException(InvalidArgumentException::class);
430
        $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], 'foreign_tbl', []));
431
    }
432
433
    public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName()
434
    {
435
        $this->expectException(InvalidArgumentException::class);
436
        $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], '', ['c', 'd']));
437
    }
438
439
    public function testCannotGenerateCommonIndexWithCreateConstraintSQL()
440
    {
441
        $this->expectException(InvalidArgumentException::class);
442
443
        $this->platform->getCreateConstraintSQL(new Index('fooindex', []), new Table('footable'));
444
    }
445
446
    public function testCannotGenerateCustomConstraintWithCreateConstraintSQL()
447
    {
448
        $this->expectException(InvalidArgumentException::class);
449
450
        $this->platform->getCreateConstraintSQL($this->createMock(Constraint::class), 'footable');
451
    }
452
453
    public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL()
454
    {
455
        self::assertEquals(
456
            'CREATE UNIQUE INDEX fooindex ON footable (a, b) WITH NULLS DISTINCT',
457
            $this->platform->getCreateIndexSQL(
458
                new Index(
459
                    'fooindex',
460
                    ['a', 'b'],
461
                    true,
462
                    false,
463
                    ['with_nulls_distinct']
464
                ),
465
                'footable'
466
            )
467
        );
468
469
        // WITH NULLS DISTINCT clause not available on primary indexes.
470
        self::assertEquals(
471
            'ALTER TABLE footable ADD PRIMARY KEY (a, b)',
472
            $this->platform->getCreateIndexSQL(
473
                new Index(
474
                    'fooindex',
475
                    ['a', 'b'],
476
                    false,
477
                    true,
478
                    ['with_nulls_distinct']
479
                ),
480
                'footable'
481
            )
482
        );
483
484
        // WITH NULLS DISTINCT clause not available on non-unique indexes.
485
        self::assertEquals(
486
            'CREATE INDEX fooindex ON footable (a, b)',
487
            $this->platform->getCreateIndexSQL(
488
                new Index(
489
                    'fooindex',
490
                    ['a', 'b'],
491
                    false,
492
                    false,
493
                    ['with_nulls_distinct']
494
                ),
495
                'footable'
496
            )
497
        );
498
499
        self::assertEquals(
500
            'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) WITH NULLS NOT DISTINCT FOR OLAP WORKLOAD',
501
            $this->platform->getCreateIndexSQL(
502
                new Index(
503
                    'fooindex',
504
                    ['a', 'b'],
505
                    true,
506
                    false,
507
                    ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload']
508
                ),
509
                'footable'
510
            )
511
        );
512
        self::assertEquals(
513
            'CREATE VIRTUAL CLUSTERED INDEX fooindex ON footable (a, b) FOR OLAP WORKLOAD',
514
            $this->platform->getCreateIndexSQL(
515
                new Index(
516
                    'fooindex',
517
                    ['a', 'b'],
518
                    false,
519
                    false,
520
                    ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload']
521
                ),
522
                'footable'
523
            )
524
        );
525
526
        // WITH NULLS NOT DISTINCT clause not available on primary indexes.
527
        self::assertEquals(
528
            'ALTER TABLE footable ADD PRIMARY KEY (a, b)',
529
            $this->platform->getCreateIndexSQL(
530
                new Index(
531
                    'fooindex',
532
                    ['a', 'b'],
533
                    false,
534
                    true,
535
                    ['with_nulls_not_distinct']
536
                ),
537
                'footable'
538
            )
539
        );
540
541
        // WITH NULLS NOT DISTINCT clause not available on non-unique indexes.
542
        self::assertEquals(
543
            'CREATE INDEX fooindex ON footable (a, b)',
544
            $this->platform->getCreateIndexSQL(
545
                new Index(
546
                    'fooindex',
547
                    ['a', 'b'],
548
                    false,
549
                    false,
550
                    ['with_nulls_not_distinct']
551
                ),
552
                'footable'
553
            )
554
        );
555
    }
556
557
    public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions()
558
    {
559
        $this->expectException('UnexpectedValueException');
560
561
        $this->platform->getCreateIndexSQL(
562
            new Index(
563
                'fooindex',
564
                ['a', 'b'],
565
                false,
566
                false,
567
                ['with_nulls_distinct', 'with_nulls_not_distinct']
568
            ),
569
            'footable'
570
        );
571
    }
572
573
    public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements()
574
    {
575
        $this->expectException(DBALException::class);
576
577
        $this->platform->getIndexDeclarationSQL('index', new Index('index', []));
578
    }
579
580
    public function testGeneratesDropIndexSQL()
581
    {
582
        $index = new Index('fooindex', []);
583
584
        self::assertEquals('DROP INDEX fooindex', $this->platform->getDropIndexSQL($index));
585
        self::assertEquals('DROP INDEX footable.fooindex', $this->platform->getDropIndexSQL($index, 'footable'));
586
        self::assertEquals('DROP INDEX footable.fooindex', $this->platform->getDropIndexSQL(
587
            $index,
588
            new Table('footable')
589
        ));
590
    }
591
592
    public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter()
593
    {
594
        $this->expectException(InvalidArgumentException::class);
595
596
        $this->platform->getDropIndexSQL(['index'], 'table');
597
    }
598
599
    public function testCannotGenerateDropIndexSQLWithInvalidTableParameter()
600
    {
601
        $this->expectException(InvalidArgumentException::class);
602
603
        $this->platform->getDropIndexSQL('index', ['table']);
604
    }
605
606
    public function testGeneratesSQLSnippets()
607
    {
608
        self::assertEquals('STRING(column1, "string1", column2, "string2")', $this->platform->getConcatExpression(
609
            'column1',
610
            '"string1"',
611
            'column2',
612
            '"string2"'
613
        ));
614
        self::assertEquals('CURRENT DATE', $this->platform->getCurrentDateSQL());
615
        self::assertEquals('CURRENT TIME', $this->platform->getCurrentTimeSQL());
616
        self::assertEquals('CURRENT TIMESTAMP', $this->platform->getCurrentTimestampSQL());
617
        self::assertEquals("DATEADD(DAY, 4, '1987/05/02')", $this->platform->getDateAddDaysExpression("'1987/05/02'", '4'));
618
        self::assertEquals("DATEADD(HOUR, 12, '1987/05/02')", $this->platform->getDateAddHourExpression("'1987/05/02'", '12'));
619
        self::assertEquals("DATEADD(MINUTE, 2, '1987/05/02')", $this->platform->getDateAddMinutesExpression("'1987/05/02'", '2'));
620
        self::assertEquals("DATEADD(MONTH, 102, '1987/05/02')", $this->platform->getDateAddMonthExpression("'1987/05/02'", '102'));
621
        self::assertEquals("DATEADD(QUARTER, 5, '1987/05/02')", $this->platform->getDateAddQuartersExpression("'1987/05/02'", '5'));
622
        self::assertEquals("DATEADD(SECOND, 1, '1987/05/02')", $this->platform->getDateAddSecondsExpression("'1987/05/02'", '1'));
623
        self::assertEquals("DATEADD(WEEK, 3, '1987/05/02')", $this->platform->getDateAddWeeksExpression("'1987/05/02'", '3'));
624
        self::assertEquals("DATEADD(YEAR, 10, '1987/05/02')", $this->platform->getDateAddYearsExpression("'1987/05/02'", '10'));
625
        self::assertEquals("DATEDIFF(day, '1987/04/01', '1987/05/02')", $this->platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'"));
626
        self::assertEquals("DATEADD(DAY, -1 * 4, '1987/05/02')", $this->platform->getDateSubDaysExpression("'1987/05/02'", '4'));
627
        self::assertEquals("DATEADD(HOUR, -1 * 12, '1987/05/02')", $this->platform->getDateSubHourExpression("'1987/05/02'", '12'));
628
        self::assertEquals("DATEADD(MINUTE, -1 * 2, '1987/05/02')", $this->platform->getDateSubMinutesExpression("'1987/05/02'", '2'));
629
        self::assertEquals("DATEADD(MONTH, -1 * 102, '1987/05/02')", $this->platform->getDateSubMonthExpression("'1987/05/02'", '102'));
630
        self::assertEquals("DATEADD(QUARTER, -1 * 5, '1987/05/02')", $this->platform->getDateSubQuartersExpression("'1987/05/02'", '5'));
631
        self::assertEquals("DATEADD(SECOND, -1 * 1, '1987/05/02')", $this->platform->getDateSubSecondsExpression("'1987/05/02'", '1'));
632
        self::assertEquals("DATEADD(WEEK, -1 * 3, '1987/05/02')", $this->platform->getDateSubWeeksExpression("'1987/05/02'", '3'));
633
        self::assertEquals("DATEADD(YEAR, -1 * 10, '1987/05/02')", $this->platform->getDateSubYearsExpression("'1987/05/02'", '10'));
634
        self::assertEquals('Y-m-d H:i:s.u', $this->platform->getDateTimeFormatString());
635
        self::assertEquals('H:i:s.u', $this->platform->getTimeFormatString());
636
        self::assertEquals('', $this->platform->getForUpdateSQL());
637
        self::assertEquals('LOCATE(string_column, substring_column)', $this->platform->getLocateExpression('string_column', 'substring_column'));
638
        self::assertEquals('LOCATE(string_column, substring_column, 1)', $this->platform->getLocateExpression('string_column', 'substring_column', '1'));
639
        self::assertEquals("HASH(column, 'MD5')", $this->platform->getMd5Expression('column'));
640
        self::assertEquals('SUBSTRING(column, 5)', $this->platform->getSubstringExpression('column', '5'));
641
        self::assertEquals('SUBSTRING(column, 5, 2)', $this->platform->getSubstringExpression('column', '5', '2'));
642
        self::assertEquals('GLOBAL TEMPORARY', $this->platform->getTemporaryTableSQL());
643
        self::assertEquals(
644
            'LTRIM(column)',
645
            $this->platform->getTrimExpression('column', TrimMode::LEADING)
646
        );
647
        self::assertEquals(
648
            'RTRIM(column)',
649
            $this->platform->getTrimExpression('column', TrimMode::TRAILING)
650
        );
651
        self::assertEquals(
652
            'TRIM(column)',
653
            $this->platform->getTrimExpression('column')
654
        );
655
        self::assertEquals(
656
            'TRIM(column)',
657
            $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED)
658
        );
659
        self::assertEquals(
660
            "SUBSTR(column, PATINDEX('%[^' + c + ']%', column))",
661
            $this->platform->getTrimExpression('column', TrimMode::LEADING, 'c')
662
        );
663
        self::assertEquals(
664
            "REVERSE(SUBSTR(REVERSE(column), PATINDEX('%[^' + c + ']%', REVERSE(column))))",
665
            $this->platform->getTrimExpression('column', TrimMode::TRAILING, 'c')
666
        );
667
        self::assertEquals(
668
            "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " .
669
            "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))",
670
            $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED, 'c')
671
        );
672
    }
673
674
    public function testHasCorrectDateTimeTzFormatString()
675
    {
676
        self::assertEquals('Y-m-d H:i:s.uP', $this->platform->getDateTimeTzFormatString());
677
    }
678
679
    public function testGeneratesDateTimeTzColumnTypeDeclarationSQL()
680
    {
681
        self::assertEquals(
682
            'TIMESTAMP WITH TIME ZONE',
683
            $this->platform->getDateTimeTzTypeDeclarationSQL([
684
                'length' => 10,
685
                'fixed' => true,
686
                'unsigned' => true,
687
                'autoincrement' => true,
688
            ])
689
        );
690
    }
691
692
    public function testInitializesDateTimeTzTypeMapping()
693
    {
694
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('timestamp with time zone'));
695
        self::assertEquals('datetime', $this->platform->getDoctrineTypeMapping('timestamp with time zone'));
696
    }
697
698
    public function testHasCorrectDefaultTransactionIsolationLevel()
699
    {
700
        self::assertEquals(
701
            TransactionIsolationLevel::READ_UNCOMMITTED,
702
            $this->platform->getDefaultTransactionIsolationLevel()
703
        );
704
    }
705
706
    public function testGeneratesTransactionsCommands()
707
    {
708
        self::assertEquals(
709
            'SET TEMPORARY OPTION isolation_level = 0',
710
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED)
711
        );
712
        self::assertEquals(
713
            'SET TEMPORARY OPTION isolation_level = 1',
714
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED)
715
        );
716
        self::assertEquals(
717
            'SET TEMPORARY OPTION isolation_level = 2',
718
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ)
719
        );
720
        self::assertEquals(
721
            'SET TEMPORARY OPTION isolation_level = 3',
722
            $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE)
723
        );
724
    }
725
726
    public function testModifiesLimitQuery()
727
    {
728
        self::assertEquals(
729
            'SELECT TOP 10 * FROM user',
730
            $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0)
731
        );
732
    }
733
734
    public function testModifiesLimitQueryWithEmptyOffset()
735
    {
736
        self::assertEquals(
737
            'SELECT TOP 10 * FROM user',
738
            $this->platform->modifyLimitQuery('SELECT * FROM user', 10)
739
        );
740
    }
741
742
    public function testModifiesLimitQueryWithOffset()
743
    {
744
        self::assertEquals(
745
            'SELECT TOP 10 START AT 6 * FROM user',
746
            $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5)
747
        );
748
        self::assertEquals(
749
            'SELECT TOP 0 START AT 6 * FROM user',
750
            $this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5)
751
        );
752
    }
753
754
    public function testModifiesLimitQueryWithSubSelect()
755
    {
756
        self::assertEquals(
757
            'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl',
758
            $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl', 10)
759
        );
760
    }
761
762
    public function testModifiesLimitQueryWithoutLimit()
763
    {
764
        self::assertEquals(
765
            'SELECT TOP ALL START AT 11 n FROM Foo',
766
            $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10)
767
        );
768
    }
769
770
    public function testPrefersIdentityColumns()
771
    {
772
        self::assertTrue($this->platform->prefersIdentityColumns());
773
    }
774
775
    public function testDoesNotPreferSequences()
776
    {
777
        self::assertFalse($this->platform->prefersSequences());
778
    }
779
780
    public function testSupportsIdentityColumns()
781
    {
782
        self::assertTrue($this->platform->supportsIdentityColumns());
783
    }
784
785
    public function testSupportsPrimaryConstraints()
786
    {
787
        self::assertTrue($this->platform->supportsPrimaryConstraints());
788
    }
789
790
    public function testSupportsForeignKeyConstraints()
791
    {
792
        self::assertTrue($this->platform->supportsForeignKeyConstraints());
793
    }
794
795
    public function testSupportsForeignKeyOnUpdate()
796
    {
797
        self::assertTrue($this->platform->supportsForeignKeyOnUpdate());
798
    }
799
800
    public function testSupportsAlterTable()
801
    {
802
        self::assertTrue($this->platform->supportsAlterTable());
803
    }
804
805
    public function testSupportsTransactions()
806
    {
807
        self::assertTrue($this->platform->supportsTransactions());
808
    }
809
810
    public function testSupportsSchemas()
811
    {
812
        self::assertFalse($this->platform->supportsSchemas());
813
    }
814
815
    public function testSupportsIndexes()
816
    {
817
        self::assertTrue($this->platform->supportsIndexes());
818
    }
819
820
    public function testSupportsCommentOnStatement()
821
    {
822
        self::assertTrue($this->platform->supportsCommentOnStatement());
823
    }
824
825
    public function testSupportsSavePoints()
826
    {
827
        self::assertTrue($this->platform->supportsSavepoints());
828
    }
829
830
    public function testSupportsReleasePoints()
831
    {
832
        self::assertTrue($this->platform->supportsReleaseSavepoints());
833
    }
834
835
    public function testSupportsCreateDropDatabase()
836
    {
837
        self::assertTrue($this->platform->supportsCreateDropDatabase());
838
    }
839
840
    public function testSupportsGettingAffectedRows()
841
    {
842
        self::assertTrue($this->platform->supportsGettingAffectedRows());
843
    }
844
845
    public function testDoesNotSupportSequences()
846
    {
847
        self::markTestSkipped('This version of the platform now supports sequences.');
848
    }
849
850
    public function testSupportsSequences()
851
    {
852
        self::assertTrue($this->platform->supportsSequences());
853
    }
854
855
    public function testGeneratesSequenceSqlCommands()
856
    {
857
        $sequence = new Sequence('myseq', 20, 1);
858
        self::assertEquals(
859
            'CREATE SEQUENCE myseq INCREMENT BY 20 START WITH 1 MINVALUE 1',
860
            $this->platform->getCreateSequenceSQL($sequence)
861
        );
862
        self::assertEquals(
863
            'ALTER SEQUENCE myseq INCREMENT BY 20',
864
            $this->platform->getAlterSequenceSQL($sequence)
865
        );
866
        self::assertEquals(
867
            'DROP SEQUENCE myseq',
868
            $this->platform->getDropSequenceSQL('myseq')
869
        );
870
        self::assertEquals(
871
            'DROP SEQUENCE myseq',
872
            $this->platform->getDropSequenceSQL($sequence)
873
        );
874
        self::assertEquals(
875
            'SELECT myseq.NEXTVAL',
876
            $this->platform->getSequenceNextValSQL('myseq')
877
        );
878
    }
879
880
    public function testDoesNotSupportInlineColumnComments()
881
    {
882
        self::assertFalse($this->platform->supportsInlineColumnComments());
883
    }
884
885
    public function testCannotEmulateSchemas()
886
    {
887
        self::assertFalse($this->platform->canEmulateSchemas());
888
    }
889
890
    public function testInitializesDoctrineTypeMappings()
891
    {
892
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('integer'));
893
        self::assertSame('integer', $this->platform->getDoctrineTypeMapping('integer'));
894
895
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('binary'));
896
        self::assertSame('binary', $this->platform->getDoctrineTypeMapping('binary'));
897
898
        self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varbinary'));
899
        self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary'));
900
    }
901
902
    protected function getBinaryDefaultLength()
903
    {
904
        return 1;
905
    }
906
907
    protected function getBinaryMaxLength()
908
    {
909
        return 32767;
910
    }
911
912
    public function testReturnsBinaryTypeDeclarationSQL()
913
    {
914
        self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([]));
915
        self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0]));
916
        self::assertSame('VARBINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32767]));
917
918
        self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true]));
919
        self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([
920
            'fixed' => true,
921
            'length' => 0,
922
        ]));
923
        self::assertSame('BINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL([
924
            'fixed' => true,
925
            'length' => 32767,
926
        ]));
927
    }
928
929
    /**
930
     * @group DBAL-234
931
     */
932
    protected function getAlterTableRenameIndexSQL()
933
    {
934
        return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_bar'];
935
    }
936
937
    /**
938
     * @group DBAL-234
939
     */
940
    protected function getQuotedAlterTableRenameIndexSQL()
941
    {
942
        return [
943
            'ALTER INDEX "create" ON "table" RENAME TO "select"',
944
            'ALTER INDEX "foo" ON "table" RENAME TO "bar"',
945
        ];
946
    }
947
948
    /**
949
     * {@inheritdoc}
950
     */
951
    protected function getQuotedAlterTableRenameColumnSQL()
952
    {
953
        return [
954
            'ALTER TABLE mytable RENAME unquoted1 TO unquoted',
955
            'ALTER TABLE mytable RENAME unquoted2 TO "where"',
956
            'ALTER TABLE mytable RENAME unquoted3 TO "foo"',
957
            'ALTER TABLE mytable RENAME "create" TO reserved_keyword',
958
            'ALTER TABLE mytable RENAME "table" TO "from"',
959
            'ALTER TABLE mytable RENAME "select" TO "bar"',
960
            'ALTER TABLE mytable RENAME quoted1 TO quoted',
961
            'ALTER TABLE mytable RENAME quoted2 TO "and"',
962
            'ALTER TABLE mytable RENAME quoted3 TO "baz"',
963
        ];
964
    }
965
966
    /**
967
     * {@inheritdoc}
968
     */
969
    protected function getQuotedAlterTableChangeColumnLengthSQL()
970
    {
971
        $this->markTestIncomplete('Not implemented yet');
972
    }
973
974
    /**
975
     * @group DBAL-807
976
     */
977
    protected function getAlterTableRenameIndexInSchemaSQL()
978
    {
979
        return ['ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar'];
980
    }
981
982
    /**
983
     * @group DBAL-807
984
     */
985
    protected function getQuotedAlterTableRenameIndexInSchemaSQL()
986
    {
987
        return [
988
            'ALTER INDEX "create" ON "schema"."table" RENAME TO "select"',
989
            'ALTER INDEX "foo" ON "schema"."table" RENAME TO "bar"',
990
        ];
991
    }
992
993
    /**
994
     * @group DBAL-423
995
     */
996
    public function testReturnsGuidTypeDeclarationSQL()
997
    {
998
        self::assertSame('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL([]));
999
    }
1000
1001
    /**
1002
     * {@inheritdoc}
1003
     */
1004
    public function getAlterTableRenameColumnSQL()
1005
    {
1006
        return ['ALTER TABLE foo RENAME bar TO baz'];
1007
    }
1008
1009
    /**
1010
     * {@inheritdoc}
1011
     */
1012
    protected function getQuotesTableIdentifiersInAlterTableSQL()
1013
    {
1014
        return [
1015
            'ALTER TABLE "foo" DROP FOREIGN KEY fk1',
1016
            'ALTER TABLE "foo" DROP FOREIGN KEY fk2',
1017
            'ALTER TABLE "foo" RENAME id TO war',
1018
            'ALTER TABLE "foo" ADD bloo INT NOT NULL, DROP baz, ALTER bar INT DEFAULT NULL',
1019
            'ALTER TABLE "foo" RENAME "table"',
1020
            'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)',
1021
            'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
1022
        ];
1023
    }
1024
1025
    /**
1026
     * {@inheritdoc}
1027
     */
1028
    protected function getCommentOnColumnSQL()
1029
    {
1030
        return [
1031
            'COMMENT ON COLUMN foo.bar IS \'comment\'',
1032
            'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'',
1033
            'COMMENT ON COLUMN "select"."from" IS \'comment\'',
1034
        ];
1035
    }
1036
1037
    /**
1038
     * @group DBAL-1004
1039
     */
1040
    public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers()
1041
    {
1042
        $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]);
1043
        $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]);
1044
1045
        $comparator = new Comparator();
1046
1047
        $tableDiff = $comparator->diffTable($table1, $table2);
1048
1049
        self::assertInstanceOf(TableDiff::class, $tableDiff);
1050
        self::assertSame(
1051
            ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''],
1052
            $this->platform->getAlterTableSQL($tableDiff)
0 ignored issues
show
Bug introduced by
It seems like $tableDiff can also be of type false; however, parameter $diff of Doctrine\DBAL\Platforms\...orm::getAlterTableSQL() does only seem to accept Doctrine\DBAL\Schema\TableDiff, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

1052
            $this->platform->getAlterTableSQL(/** @scrutinizer ignore-type */ $tableDiff)
Loading history...
1053
        );
1054
    }
1055
1056
    /**
1057
     * {@inheritdoc}
1058
     */
1059
    public function getReturnsForeignKeyReferentialActionSQL()
1060
    {
1061
        return [
1062
            ['CASCADE', 'CASCADE'],
1063
            ['SET NULL', 'SET NULL'],
1064
            ['NO ACTION', 'RESTRICT'],
1065
            ['RESTRICT', 'RESTRICT'],
1066
            ['SET DEFAULT', 'SET DEFAULT'],
1067
            ['CaScAdE', 'CASCADE'],
1068
        ];
1069
    }
1070
1071
    /**
1072
     * {@inheritdoc}
1073
     */
1074
    protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
1075
    {
1076
        return 'CONSTRAINT "select" UNIQUE (foo)';
1077
    }
1078
1079
    /**
1080
     * {@inheritdoc}
1081
     */
1082
    protected function getQuotesReservedKeywordInIndexDeclarationSQL()
1083
    {
1084
        return ''; // not supported by this platform
1085
    }
1086
1087
    /**
1088
     * {@inheritdoc}
1089
     */
1090
    protected function getQuotesReservedKeywordInTruncateTableSQL()
1091
    {
1092
        return 'TRUNCATE TABLE "select"';
1093
    }
1094
1095
    /**
1096
     * {@inheritdoc}
1097
     */
1098
    protected function supportsInlineIndexDeclaration()
1099
    {
1100
        return false;
1101
    }
1102
1103
    /**
1104
     * {@inheritdoc}
1105
     */
1106
    protected function getAlterStringToFixedStringSQL()
1107
    {
1108
        return ['ALTER TABLE mytable ALTER name CHAR(2) NOT NULL'];
1109
    }
1110
1111
    /**
1112
     * {@inheritdoc}
1113
     */
1114
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
1115
    {
1116
        return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed'];
1117
    }
1118
1119
    /**
1120
     * @group DBAL-2436
1121
     */
1122
    public function testQuotesSchemaNameInListTableColumnsSQL()
1123
    {
1124
        self::assertStringContainsStringIgnoringCase(
1125
            "'Foo''Bar\\'",
1126
            $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table")
1127
        );
1128
    }
1129
1130
    /**
1131
     * @group DBAL-2436
1132
     */
1133
    public function testQuotesTableNameInListTableConstraintsSQL()
1134
    {
1135
        self::assertStringContainsStringIgnoringCase("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
0 ignored issues
show
Unused Code introduced by
The call to PHPUnit\Framework\Assert...insStringIgnoringCase() has too many arguments starting with true. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

1135
        self::/** @scrutinizer ignore-call */ 
1136
              assertStringContainsStringIgnoringCase("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
1136
    }
1137
1138
    /**
1139
     * @group DBAL-2436
1140
     */
1141
    public function testQuotesSchemaNameInListTableConstraintsSQL()
1142
    {
1143
        self::assertStringContainsStringIgnoringCase(
1144
            "'Foo''Bar\\'",
1145
            $this->platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table")
1146
        );
1147
    }
1148
1149
    /**
1150
     * @group DBAL-2436
1151
     */
1152
    public function testQuotesTableNameInListTableForeignKeysSQL()
1153
    {
1154
        self::assertStringContainsStringIgnoringCase(
1155
            "'Foo''Bar\\'",
1156
            $this->platform->getListTableForeignKeysSQL("Foo'Bar\\")
1157
        );
1158
    }
1159
1160
    /**
1161
     * @group DBAL-2436
1162
     */
1163
    public function testQuotesSchemaNameInListTableForeignKeysSQL()
1164
    {
1165
        self::assertStringContainsStringIgnoringCase(
1166
            "'Foo''Bar\\'",
1167
            $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table")
1168
        );
1169
    }
1170
1171
    /**
1172
     * @group DBAL-2436
1173
     */
1174
    public function testQuotesTableNameInListTableIndexesSQL()
1175
    {
1176
        self::assertStringContainsStringIgnoringCase(
1177
            "'Foo''Bar\\'",
1178
            $this->platform->getListTableIndexesSQL("Foo'Bar\\")
1179
        );
1180
    }
1181
1182
    /**
1183
     * @group DBAL-2436
1184
     */
1185
    public function testQuotesSchemaNameInListTableIndexesSQL()
1186
    {
1187
        self::assertStringContainsStringIgnoringCase(
1188
            "'Foo''Bar\\'",
1189
            $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table")
1190
        );
1191
    }
1192
}
1193