Completed
Push — master ( c7757e...39cb21 )
by Luís
16s
created

Tests/DBAL/Platforms/SqlitePlatformTest.php (3 issues)

1
<?php
2
3
namespace Doctrine\Tests\DBAL\Platforms;
4
5
use Doctrine\DBAL\DBALException;
6
use Doctrine\DBAL\Platforms\SqlitePlatform;
7
use Doctrine\DBAL\Schema\Column;
8
use Doctrine\DBAL\Schema\Table;
9
use Doctrine\DBAL\Schema\TableDiff;
10
use Doctrine\DBAL\Types\Type;
11
12
class SqlitePlatformTest extends AbstractPlatformTestCase
13
{
14
    public function createPlatform()
15
    {
16
        return new SqlitePlatform;
17
    }
18
19
    public function getGenerateTableSql()
20
    {
21
        return 'CREATE TABLE test (id INTEGER NOT NULL, test VARCHAR(255) DEFAULT NULL, PRIMARY KEY(id))';
22
    }
23
24
    public function getGenerateTableWithMultiColumnUniqueIndexSql()
25
    {
26
        return array(
27
            'CREATE TABLE test (foo VARCHAR(255) DEFAULT NULL, bar VARCHAR(255) DEFAULT NULL)',
28
            'CREATE UNIQUE INDEX UNIQ_D87F7E0C8C73652176FF8CAA ON test (foo, bar)',
29
        );
30
    }
31
32
    public function testGeneratesSqlSnippets()
33
    {
34
        self::assertEquals('REGEXP', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
35
        self::assertEquals('SUBSTR(column, 5, LENGTH(column))', $this->_platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct');
36
        self::assertEquals('SUBSTR(column, 0, 5)', $this->_platform->getSubstringExpression('column', 0, 5), 'Substring expression with length is not correct');
37
    }
38
39 View Code Duplication
    public function testGeneratesTransactionCommands()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
40
    {
41
        self::assertEquals(
42
            'PRAGMA read_uncommitted = 0',
43
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
44
        );
45
        self::assertEquals(
46
            'PRAGMA read_uncommitted = 1',
47
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
48
        );
49
        self::assertEquals(
50
            'PRAGMA read_uncommitted = 1',
51
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
52
        );
53
        self::assertEquals(
54
            'PRAGMA read_uncommitted = 1',
55
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
56
        );
57
    }
58
59
    public function testPrefersIdentityColumns()
60
    {
61
        self::assertTrue($this->_platform->prefersIdentityColumns());
62
    }
63
64
    public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers()
65
    {
66
        self::assertSame(
67
            'INTEGER',
68
            $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
69
        );
70
    }
71
72
    /**
73
     * @group DBAL-752
74
     * @group DBAL-924
75
     */
76
    public function testGeneratesTypeDeclarationForTinyIntegers()
77
    {
78
        self::assertEquals(
79
            'TINYINT',
80
            $this->_platform->getTinyIntTypeDeclarationSQL(array())
81
        );
82
        self::assertEquals(
83
            'INTEGER',
84
            $this->_platform->getTinyIntTypeDeclarationSQL(array('autoincrement' => true))
85
        );
86
        self::assertEquals(
87
            'INTEGER',
88
            $this->_platform->getTinyIntTypeDeclarationSQL(
89
                array('autoincrement' => true, 'primary' => true))
90
        );
91
        self::assertEquals(
92
            'TINYINT',
93
            $this->_platform->getTinyIntTypeDeclarationSQL(array('unsigned' => false))
94
        );
95
        self::assertEquals(
96
            'TINYINT UNSIGNED',
97
            $this->_platform->getTinyIntTypeDeclarationSQL(array('unsigned' => true))
98
        );
99
    }
100
101
    /**
102
     * @group DBAL-752
103
     * @group DBAL-924
104
     */
105 View Code Duplication
    public function testGeneratesTypeDeclarationForSmallIntegers()
106
    {
107
        self::assertEquals(
108
            'SMALLINT',
109
            $this->_platform->getSmallIntTypeDeclarationSQL(array())
110
        );
111
        self::assertEquals(
112
            'INTEGER',
113
            $this->_platform->getSmallIntTypeDeclarationSQL(array('autoincrement' => true))
114
        );
115
        self::assertEquals(
116
            'INTEGER',
117
            $this->_platform->getTinyIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
118
        );
119
        self::assertEquals(
120
            'INTEGER',
121
            $this->_platform->getSmallIntTypeDeclarationSQL(
122
                array('autoincrement' => true, 'primary' => true))
123
        );
124
        self::assertEquals(
125
            'SMALLINT',
126
            $this->_platform->getSmallIntTypeDeclarationSQL(array('unsigned' => false))
127
        );
128
        self::assertEquals(
129
            'SMALLINT UNSIGNED',
130
            $this->_platform->getSmallIntTypeDeclarationSQL(array('unsigned' => true))
131
        );
132
    }
133
134
    /**
135
     * @group DBAL-752
136
     * @group DBAL-924
137
     */
138 View Code Duplication
    public function testGeneratesTypeDeclarationForMediumIntegers()
139
    {
140
        self::assertEquals(
141
            'MEDIUMINT',
142
            $this->_platform->getMediumIntTypeDeclarationSQL(array())
143
        );
144
        self::assertEquals(
145
            'INTEGER',
146
            $this->_platform->getMediumIntTypeDeclarationSQL(array('autoincrement' => true))
147
        );
148
        self::assertEquals(
149
            'INTEGER',
150
            $this->_platform->getMediumIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
151
        );
152
        self::assertEquals(
153
            'INTEGER',
154
            $this->_platform->getMediumIntTypeDeclarationSQL(
155
                array('autoincrement' => true, 'primary' => true))
156
        );
157
        self::assertEquals(
158
            'MEDIUMINT',
159
            $this->_platform->getMediumIntTypeDeclarationSQL(array('unsigned' => false))
160
        );
161
        self::assertEquals(
162
            'MEDIUMINT UNSIGNED',
163
            $this->_platform->getMediumIntTypeDeclarationSQL(array('unsigned' => true))
164
        );
165
    }
166
167 View Code Duplication
    public function testGeneratesTypeDeclarationForIntegers()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
168
    {
169
        self::assertEquals(
170
            'INTEGER',
171
            $this->_platform->getIntegerTypeDeclarationSQL(array())
172
        );
173
        self::assertEquals(
174
            'INTEGER',
175
            $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true))
176
        );
177
        self::assertEquals(
178
            'INTEGER',
179
            $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
180
        );
181
        self::assertEquals(
182
            'INTEGER',
183
            $this->_platform->getIntegerTypeDeclarationSQL(
184
                array('autoincrement' => true, 'primary' => true))
185
        );
186
        self::assertEquals(
187
            'INTEGER',
188
            $this->_platform->getIntegerTypeDeclarationSQL(array('unsigned' => false))
189
        );
190
        self::assertEquals(
191
            'INTEGER UNSIGNED',
192
            $this->_platform->getIntegerTypeDeclarationSQL(array('unsigned' => true))
193
        );
194
    }
195
196
    /**
197
     * @group DBAL-752
198
     * @group DBAL-924
199
     */
200 View Code Duplication
    public function testGeneratesTypeDeclarationForBigIntegers()
201
    {
202
        self::assertEquals(
203
            'BIGINT',
204
            $this->_platform->getBigIntTypeDeclarationSQL(array())
205
        );
206
        self::assertEquals(
207
            'INTEGER',
208
            $this->_platform->getBigIntTypeDeclarationSQL(array('autoincrement' => true))
209
        );
210
        self::assertEquals(
211
            'INTEGER',
212
            $this->_platform->getBigIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
213
        );
214
        self::assertEquals(
215
            'INTEGER',
216
            $this->_platform->getBigIntTypeDeclarationSQL(
217
                array('autoincrement' => true, 'primary' => true))
218
        );
219
        self::assertEquals(
220
            'BIGINT',
221
            $this->_platform->getBigIntTypeDeclarationSQL(array('unsigned' => false))
222
        );
223
        self::assertEquals(
224
            'BIGINT UNSIGNED',
225
            $this->_platform->getBigIntTypeDeclarationSQL(array('unsigned' => true))
226
        );
227
    }
228
229 View Code Duplication
    public function testGeneratesTypeDeclarationForStrings()
0 ignored issues
show
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
230
    {
231
        self::assertEquals(
232
            'CHAR(10)',
233
            $this->_platform->getVarcharTypeDeclarationSQL(
234
                array('length' => 10, 'fixed' => true))
235
        );
236
        self::assertEquals(
237
            'VARCHAR(50)',
238
            $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
239
            'Variable string declaration is not correct'
240
        );
241
        self::assertEquals(
242
            'VARCHAR(255)',
243
            $this->_platform->getVarcharTypeDeclarationSQL(array()),
244
            'Long string declaration is not correct'
245
        );
246
    }
247
248
    public function getGenerateIndexSql()
249
    {
250
        return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
251
    }
252
253
    public function getGenerateUniqueIndexSql()
254
    {
255
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
256
    }
257
258
    /**
259
     * @expectedException \Doctrine\DBAL\DBALException
260
     */
261
    public function testGeneratesForeignKeyCreationSql()
262
    {
263
        parent::testGeneratesForeignKeyCreationSql();
264
    }
265
266
    /**
267
     * @expectedException \Doctrine\DBAL\DBALException
268
     */
269
    public function testGeneratesConstraintCreationSql()
270
    {
271
        parent::testGeneratesConstraintCreationSql();
272
    }
273
274
    public function getGenerateForeignKeySql()
275
    {
276
        return null;
277
    }
278
279
    public function testModifyLimitQuery()
280
    {
281
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
282
        self::assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
283
    }
284
285
    public function testModifyLimitQueryWithEmptyOffset()
286
    {
287
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
288
        self::assertEquals('SELECT * FROM user LIMIT 10', $sql);
289
    }
290
291
    public function testModifyLimitQueryWithOffsetAndEmptyLimit()
292
    {
293
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', null, 10);
294
        self::assertEquals('SELECT * FROM user LIMIT -1 OFFSET 10', $sql);
295
    }
296
297
    public function getGenerateAlterTableSql()
298
    {
299
        return array(
300
            "CREATE TEMPORARY TABLE __temp__mytable AS SELECT id, bar, bloo FROM mytable",
301
            "DROP TABLE mytable",
302
            "CREATE TABLE mytable (id INTEGER NOT NULL, baz VARCHAR(255) DEFAULT 'def' NOT NULL, bloo BOOLEAN DEFAULT '0' NOT NULL, quota INTEGER DEFAULT NULL, PRIMARY KEY(id))",
303
            "INSERT INTO mytable (id, baz, bloo) SELECT id, bar, bloo FROM __temp__mytable",
304
            "DROP TABLE __temp__mytable",
305
            "ALTER TABLE mytable RENAME TO userlist",
306
        );
307
    }
308
309
    /**
310
     * @group DDC-1845
311
     */
312
    public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey()
313
    {
314
        $table = new \Doctrine\DBAL\Schema\Table('test');
315
        $table->addColumn('"like"', 'integer', array('notnull' => true, 'autoincrement' => true));
316
        $table->setPrimaryKey(array('"like"'));
317
318
        $createTableSQL = $this->_platform->getCreateTableSQL($table);
319
        self::assertEquals(
320
            'CREATE TABLE test ("like" INTEGER NOT NULL, PRIMARY KEY("like"))',
321
            $createTableSQL[0]
322
        );
323
    }
324
325 View Code Duplication
    public function testAlterTableAddColumns()
326
    {
327
        $diff = new TableDiff('user');
328
        $diff->addedColumns['foo'] = new Column('foo', Type::getType('string'));
329
        $diff->addedColumns['count'] = new Column('count', Type::getType('integer'), array('notnull' => false, 'default' => 1));
330
331
        $expected = array(
332
            'ALTER TABLE user ADD COLUMN foo VARCHAR(255) NOT NULL',
333
            'ALTER TABLE user ADD COLUMN count INTEGER DEFAULT 1',
334
        );
335
336
        self::assertEquals($expected, $this->_platform->getAlterTableSQL($diff));
337
    }
338
339
    /**
340
     * @dataProvider complexDiffProvider
341
     */
342
    public function testAlterTableAddComplexColumns(TableDiff $diff) : void
343
    {
344
        $this->expectException(DBALException::class);
345
346
        $this->_platform->getAlterTableSQL($diff);
347
    }
348
349
    public function complexDiffProvider() : array
350
    {
351
        $date = new TableDiff('user');
352
        $date->addedColumns['time'] = new Column('time', Type::getType('date'), array('default' => 'CURRENT_DATE'));
353
354
355
        $id = new TableDiff('user');
356
        $id->addedColumns['id'] = new Column('id', Type::getType('integer'), array('autoincrement' => true));
357
358
        return [
359
            'date column with default value' => [$date],
360
            'id column with auto increment'  => [$id],
361
        ];
362
    }
363
364
    public function testCreateTableWithDeferredForeignKeys()
365
    {
366
        $table = new Table('user');
367
        $table->addColumn('id', 'integer');
368
        $table->addColumn('article', 'integer');
369
        $table->addColumn('post', 'integer');
370
        $table->addColumn('parent', 'integer');
371
        $table->setPrimaryKey(array('id'));
372
        $table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true));
373
        $table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true));
374
        $table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true));
375
376
        $sql = array(
377
            'CREATE TABLE user ('
378
                . 'id INTEGER NOT NULL, article INTEGER NOT NULL, post INTEGER NOT NULL, parent INTEGER NOT NULL'
379
                . ', PRIMARY KEY(id)'
380
                . ', CONSTRAINT FK_8D93D64923A0E66 FOREIGN KEY (article) REFERENCES article (id) DEFERRABLE INITIALLY IMMEDIATE'
381
                . ', CONSTRAINT FK_8D93D6495A8A6C8D FOREIGN KEY (post) REFERENCES post (id) NOT DEFERRABLE INITIALLY DEFERRED'
382
                . ', CONSTRAINT FK_8D93D6493D8E604F FOREIGN KEY (parent) REFERENCES user (id) DEFERRABLE INITIALLY DEFERRED'
383
                . ')',
384
            'CREATE INDEX IDX_8D93D64923A0E66 ON user (article)',
385
            'CREATE INDEX IDX_8D93D6495A8A6C8D ON user (post)',
386
            'CREATE INDEX IDX_8D93D6493D8E604F ON user (parent)',
387
        );
388
389
        self::assertEquals($sql, $this->_platform->getCreateTableSQL($table));
390
    }
391
392
    public function testAlterTable()
393
    {
394
        $table = new Table('user');
395
        $table->addColumn('id', 'integer');
396
        $table->addColumn('article', 'integer');
397
        $table->addColumn('post', 'integer');
398
        $table->addColumn('parent', 'integer');
399
        $table->setPrimaryKey(array('id'));
400
        $table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true));
401
        $table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true));
402
        $table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true));
403
        $table->addIndex(array('article', 'post'), 'index1');
404
405
        $diff = new TableDiff('user');
406
        $diff->fromTable = $table;
407
        $diff->newName = 'client';
408
        $diff->renamedColumns['id'] = new \Doctrine\DBAL\Schema\Column('key', \Doctrine\DBAL\Types\Type::getType('integer'), array());
409
        $diff->renamedColumns['post'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array());
410
        $diff->removedColumns['parent'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array());
411
        $diff->removedIndexes['index1'] = $table->getIndex('index1');
412
413
        $sql = array(
414
            'DROP INDEX IDX_8D93D64923A0E66',
415
            'DROP INDEX IDX_8D93D6495A8A6C8D',
416
            'DROP INDEX IDX_8D93D6493D8E604F',
417
            'DROP INDEX index1',
418
            'CREATE TEMPORARY TABLE __temp__user AS SELECT id, article, post FROM user',
419
            'DROP TABLE user',
420
            'CREATE TABLE user ('
421
                . '"key" INTEGER NOT NULL, article INTEGER NOT NULL, comment INTEGER NOT NULL'
422
                . ', PRIMARY KEY("key")'
423
                . ', CONSTRAINT FK_8D93D64923A0E66 FOREIGN KEY (article) REFERENCES article (id) DEFERRABLE INITIALLY IMMEDIATE'
424
                . ', CONSTRAINT FK_8D93D6495A8A6C8D FOREIGN KEY (comment) REFERENCES post (id) NOT DEFERRABLE INITIALLY DEFERRED'
425
                . ')',
426
            'INSERT INTO user ("key", article, comment) SELECT id, article, post FROM __temp__user',
427
            'DROP TABLE __temp__user',
428
            'ALTER TABLE user RENAME TO client',
429
            'CREATE INDEX IDX_8D93D64923A0E66 ON client (article)',
430
            'CREATE INDEX IDX_8D93D6495A8A6C8D ON client (comment)',
431
        );
432
433
        self::assertEquals($sql, $this->_platform->getAlterTableSQL($diff));
434
    }
435
436
    protected function getQuotedColumnInPrimaryKeySQL()
437
    {
438
        return array(
439
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))',
440
        );
441
    }
442
443
    protected function getQuotedColumnInIndexSQL()
444
    {
445
        return array(
446
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)',
447
            'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")',
448
        );
449
    }
450
451
    protected function getQuotedNameInIndexSQL()
452
    {
453
        return array(
454
            'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
455
            'CREATE INDEX "key" ON test (column1)',
456
        );
457
    }
458
459
    protected function getQuotedColumnInForeignKeySQL()
460
    {
461
        return array(
462
            'CREATE TABLE "quoted" (' .
463
            '"create" VARCHAR(255) NOT NULL, foo VARCHAR(255) NOT NULL, "bar" VARCHAR(255) NOT NULL, ' .
464
            'CONSTRAINT FK_WITH_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES "foreign" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE, ' .
465
            'CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE, ' .
466
            'CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE)',
467
        );
468
    }
469
470
    protected function getBinaryDefaultLength()
471
    {
472
        return 0;
473
    }
474
475
    protected function getBinaryMaxLength()
476
    {
477
        return 0;
478
    }
479
480 View Code Duplication
    public function testReturnsBinaryTypeDeclarationSQL()
481
    {
482
        self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array()));
483
        self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0)));
484
        self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 9999999)));
485
486
        self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
487
        self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
488
        self::assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 9999999)));
489
    }
490
491
    /**
492
     * @group DBAL-234
493
     */
494
    protected function getAlterTableRenameIndexSQL()
495
    {
496
        return array(
497
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id FROM mytable',
498
            'DROP TABLE mytable',
499
            'CREATE TABLE mytable (id INTEGER NOT NULL, PRIMARY KEY(id))',
500
            'INSERT INTO mytable (id) SELECT id FROM __temp__mytable',
501
            'DROP TABLE __temp__mytable',
502
            'CREATE INDEX idx_bar ON mytable (id)',
503
        );
504
    }
505
506
    /**
507
     * @group DBAL-234
508
     */
509
    protected function getQuotedAlterTableRenameIndexSQL()
510
    {
511
        return array(
512
            'CREATE TEMPORARY TABLE __temp__table AS SELECT id FROM "table"',
513
            'DROP TABLE "table"',
514
            'CREATE TABLE "table" (id INTEGER NOT NULL, PRIMARY KEY(id))',
515
            'INSERT INTO "table" (id) SELECT id FROM __temp__table',
516
            'DROP TABLE __temp__table',
517
            'CREATE INDEX "select" ON "table" (id)',
518
            'CREATE INDEX "bar" ON "table" (id)',
519
        );
520
    }
521
522
    /**
523
     * {@inheritdoc}
524
     */
525
    protected function getQuotedAlterTableRenameColumnSQL()
526
    {
527
        return array(
528
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM mytable',
529
            'DROP TABLE mytable',
530
            'CREATE TABLE mytable (unquoted INTEGER NOT NULL --Unquoted 1
531
, "where" INTEGER NOT NULL --Unquoted 2
532
, "foo" INTEGER NOT NULL --Unquoted 3
533
, reserved_keyword INTEGER NOT NULL --Reserved keyword 1
534
, "from" INTEGER NOT NULL --Reserved keyword 2
535
, "bar" INTEGER NOT NULL --Reserved keyword 3
536
, quoted INTEGER NOT NULL --Quoted 1
537
, "and" INTEGER NOT NULL --Quoted 2
538
, "baz" INTEGER NOT NULL --Quoted 3
539
)',
540
            'INSERT INTO mytable (unquoted, "where", "foo", reserved_keyword, "from", "bar", quoted, "and", "baz") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM __temp__mytable',
541
            'DROP TABLE __temp__mytable',
542
        );
543
    }
544
545
    /**
546
     * {@inheritdoc}
547
     */
548
    protected function getQuotedAlterTableChangeColumnLengthSQL()
549
    {
550
        return array(
551
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM mytable',
552
            'DROP TABLE mytable',
553
            'CREATE TABLE mytable (unquoted1 VARCHAR(255) NOT NULL --Unquoted 1
554
, unquoted2 VARCHAR(255) NOT NULL --Unquoted 2
555
, unquoted3 VARCHAR(255) NOT NULL --Unquoted 3
556
, "create" VARCHAR(255) NOT NULL --Reserved keyword 1
557
, "table" VARCHAR(255) NOT NULL --Reserved keyword 2
558
, "select" VARCHAR(255) NOT NULL --Reserved keyword 3
559
)',
560
            'INSERT INTO mytable (unquoted1, unquoted2, unquoted3, "create", "table", "select") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM __temp__mytable',
561
            'DROP TABLE __temp__mytable',
562
        );
563
    }
564
565
    /**
566
     * @group DBAL-807
567
     */
568
    public function testAlterTableRenameIndexInSchema()
569
    {
570
        $this->markTestIncomplete(
571
            'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' .
572
            'when used with schemas.'
573
        );
574
    }
575
576
    /**
577
     * @group DBAL-807
578
     */
579
    public function testQuotesAlterTableRenameIndexInSchema()
580
    {
581
        $this->markTestIncomplete(
582
            'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' .
583
            'when used with schemas.'
584
        );
585
    }
586
587
    /**
588
     * @group DBAL-423
589
     */
590
    public function testReturnsGuidTypeDeclarationSQL()
591
    {
592
        self::assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
593
    }
594
595
    /**
596
     * {@inheritdoc}
597
     */
598
    public function getAlterTableRenameColumnSQL()
599
    {
600
        return array(
601
            'CREATE TEMPORARY TABLE __temp__foo AS SELECT bar FROM foo',
602
            'DROP TABLE foo',
603
            'CREATE TABLE foo (baz INTEGER DEFAULT 666 NOT NULL --rename test
604
)',
605
            'INSERT INTO foo (baz) SELECT bar FROM __temp__foo',
606
            'DROP TABLE __temp__foo',
607
        );
608
    }
609
610
    /**
611
     * {@inheritdoc}
612
     */
613
    protected function getQuotesTableIdentifiersInAlterTableSQL()
614
    {
615
        return array(
616
            'DROP INDEX IDX_8C736521A81E660E',
617
            'DROP INDEX IDX_8C736521FDC58D6C',
618
            'CREATE TEMPORARY TABLE __temp__foo AS SELECT fk, fk2, id, fk3, bar FROM "foo"',
619
            'DROP TABLE "foo"',
620
            'CREATE TABLE "foo" (fk2 INTEGER NOT NULL, fk3 INTEGER NOT NULL, fk INTEGER NOT NULL, war INTEGER NOT NULL, ' .
621
            'bar INTEGER DEFAULT NULL, bloo INTEGER NOT NULL, ' .
622
            'CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id) NOT DEFERRABLE INITIALLY IMMEDIATE, ' .
623
            'CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE)',
624
            'INSERT INTO "foo" (fk, fk2, war, fk3, bar) SELECT fk, fk2, id, fk3, bar FROM __temp__foo',
625
            'DROP TABLE __temp__foo',
626
            'ALTER TABLE "foo" RENAME TO "table"',
627
            'CREATE INDEX IDX_8C736521A81E660E ON "table" (fk)',
628
            'CREATE INDEX IDX_8C736521FDC58D6C ON "table" (fk2)',
629
        );
630
    }
631
632
    /**
633
     * {@inheritdoc}
634
     */
635
    protected function getCommentOnColumnSQL()
636
    {
637
        return array(
638
            'COMMENT ON COLUMN foo.bar IS \'comment\'',
639
            'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'',
640
            'COMMENT ON COLUMN "select"."from" IS \'comment\'',
641
        );
642
    }
643
644
    protected function getInlineColumnCommentDelimiter()
645
    {
646
        return "\n";
647
    }
648
649
    protected function getInlineColumnRegularCommentSQL()
650
    {
651
        return "--Regular comment\n";
652
    }
653
654
    protected function getInlineColumnCommentRequiringEscapingSQL()
655
    {
656
        return "--Using inline comment delimiter \n-- works\n";
657
    }
658
659
    protected function getInlineColumnEmptyCommentSQL()
660
    {
661
        return "--\n";
662
    }
663
664
    /**
665
     * {@inheritdoc}
666
     */
667
    protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
668
    {
669
        return 'CONSTRAINT "select" UNIQUE (foo)';
670
    }
671
672
    /**
673
     * {@inheritdoc}
674
     */
675
    protected function getQuotesReservedKeywordInIndexDeclarationSQL()
676
    {
677
        return 'INDEX "select" (foo)';
678
    }
679
680
    /**
681
     * {@inheritdoc}
682
     */
683
    protected function getQuotesReservedKeywordInTruncateTableSQL()
684
    {
685
        return 'DELETE FROM "select"';
686
    }
687
688
    /**
689
     * {@inheritdoc}
690
     */
691
    protected function getAlterStringToFixedStringSQL()
692
    {
693
        return array(
694
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT name FROM mytable',
695
            'DROP TABLE mytable',
696
            'CREATE TABLE mytable (name CHAR(2) NOT NULL)',
697
            'INSERT INTO mytable (name) SELECT name FROM __temp__mytable',
698
            'DROP TABLE __temp__mytable',
699
        );
700
    }
701
702
    /**
703
     * {@inheritdoc}
704
     */
705
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
706
    {
707
        return array(
708
            'DROP INDEX idx_foo',
709
            'DROP INDEX idx_bar',
710
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT foo, bar, baz FROM mytable',
711
            'DROP TABLE mytable',
712
            'CREATE TABLE mytable (foo INTEGER NOT NULL, bar INTEGER NOT NULL, baz INTEGER NOT NULL, CONSTRAINT fk_foo FOREIGN KEY (foo) REFERENCES foreign_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE, CONSTRAINT fk_bar FOREIGN KEY (bar) REFERENCES foreign_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE)',
713
            'INSERT INTO mytable (foo, bar, baz) SELECT foo, bar, baz FROM __temp__mytable',
714
            'DROP TABLE __temp__mytable',
715
            'CREATE INDEX idx_bar ON mytable (bar)',
716
            'CREATE INDEX idx_foo_renamed ON mytable (foo)',
717
        );
718
    }
719
720
    /**
721
     * @group DBAL-2436
722
     */
723
    public function testQuotesTableNameInListTableConstraintsSQL()
724
    {
725
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableConstraintsSQL("Foo'Bar\\"), '', true);
726
    }
727
728
    /**
729
     * @group DBAL-2436
730
     */
731
    public function testQuotesTableNameInListTableColumnsSQL()
732
    {
733
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableColumnsSQL("Foo'Bar\\"), '', true);
734
    }
735
736
    /**
737
     * @group DBAL-2436
738
     */
739
    public function testQuotesTableNameInListTableIndexesSQL()
740
    {
741
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableIndexesSQL("Foo'Bar\\"), '', true);
742
    }
743
744
    /**
745
     * @group DBAL-2436
746
     */
747
    public function testQuotesTableNameInListTableForeignKeysSQL()
748
    {
749
        self::assertContains("'Foo''Bar\\'", $this->_platform->getListTableForeignKeysSQL("Foo'Bar\\"), '', true);
750
    }
751
}
752