SqlitePlatformTest.php 25.1 KB
Newer Older
1 2 3 4
<?php

namespace Doctrine\Tests\DBAL\Platforms;

jeroendedauw's avatar
jeroendedauw committed
5 6
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Platforms\SqlitePlatform;
7
use Doctrine\DBAL\Schema\Column;
jeroendedauw's avatar
jeroendedauw committed
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 25 26 27
    public function getGenerateTableWithMultiColumnUniqueIndexSql()
    {
        return array(
            '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 35 36
        $this->assertEquals('RLIKE', $this->_platform->getRegexpExpression(), 'Regular expression operator is not correct');
        $this->assertEquals('SUBSTR(column, 5, LENGTH(column))', $this->_platform->getSubstringExpression('column', 5), 'Substring expression without length is not correct');
        $this->assertEquals('SUBSTR(column, 0, 5)', $this->_platform->getSubstringExpression('column', 0, 5), 'Substring expression with length is not correct');
37 38
    }

39
    public function testGeneratesTransactionCommands()
40
    {
41
        $this->assertEquals(
42
            'PRAGMA read_uncommitted = 0',
43 44 45
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_UNCOMMITTED)
        );
        $this->assertEquals(
46
            'PRAGMA read_uncommitted = 1',
47 48 49
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_READ_COMMITTED)
        );
        $this->assertEquals(
50
            'PRAGMA read_uncommitted = 1',
51 52 53
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_REPEATABLE_READ)
        );
        $this->assertEquals(
54
            'PRAGMA read_uncommitted = 1',
55 56
            $this->_platform->getSetTransactionIsolationSQL(\Doctrine\DBAL\Connection::TRANSACTION_SERIALIZABLE)
        );
57 58
    }

59
    public function testPrefersIdentityColumns()
60 61 62 63
    {
        $this->assertTrue($this->_platform->prefersIdentityColumns());
    }

64 65 66 67 68 69 70 71
    public function testIgnoresUnsignedIntegerDeclarationForAutoIncrementalIntegers()
    {
        $this->assertSame(
            'INTEGER',
            $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
        );
    }

72 73
    /**
     * @group DBAL-752
74
     * @group DBAL-924
75 76 77 78 79 80 81 82
     */
    public function testGeneratesTypeDeclarationForTinyIntegers()
    {
        $this->assertEquals(
            'TINYINT',
            $this->_platform->getTinyIntTypeDeclarationSQL(array())
        );
        $this->assertEquals(
83
            'INTEGER',
84 85 86
            $this->_platform->getTinyIntTypeDeclarationSQL(array('autoincrement' => true))
        );
        $this->assertEquals(
87
            'INTEGER',
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
            $this->_platform->getTinyIntTypeDeclarationSQL(
                array('autoincrement' => true, 'primary' => true))
        );
        $this->assertEquals(
            'TINYINT',
            $this->_platform->getTinyIntTypeDeclarationSQL(array('unsigned' => false))
        );
        $this->assertEquals(
            'TINYINT UNSIGNED',
            $this->_platform->getTinyIntTypeDeclarationSQL(array('unsigned' => true))
        );
    }

    /**
     * @group DBAL-752
103
     * @group DBAL-924
104 105 106 107 108 109 110 111
     */
    public function testGeneratesTypeDeclarationForSmallIntegers()
    {
        $this->assertEquals(
            'SMALLINT',
            $this->_platform->getSmallIntTypeDeclarationSQL(array())
        );
        $this->assertEquals(
112
            'INTEGER',
113 114 115
            $this->_platform->getSmallIntTypeDeclarationSQL(array('autoincrement' => true))
        );
        $this->assertEquals(
116 117 118 119 120
            'INTEGER',
            $this->_platform->getTinyIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
        );
        $this->assertEquals(
            'INTEGER',
121 122 123 124 125 126 127 128 129 130 131 132 133 134 135
            $this->_platform->getSmallIntTypeDeclarationSQL(
                array('autoincrement' => true, 'primary' => true))
        );
        $this->assertEquals(
            'SMALLINT',
            $this->_platform->getSmallIntTypeDeclarationSQL(array('unsigned' => false))
        );
        $this->assertEquals(
            'SMALLINT UNSIGNED',
            $this->_platform->getSmallIntTypeDeclarationSQL(array('unsigned' => true))
        );
    }

    /**
     * @group DBAL-752
136
     * @group DBAL-924
137 138 139 140 141 142 143 144
     */
    public function testGeneratesTypeDeclarationForMediumIntegers()
    {
        $this->assertEquals(
            'MEDIUMINT',
            $this->_platform->getMediumIntTypeDeclarationSQL(array())
        );
        $this->assertEquals(
145
            'INTEGER',
146 147 148
            $this->_platform->getMediumIntTypeDeclarationSQL(array('autoincrement' => true))
        );
        $this->assertEquals(
149 150 151 152 153
            'INTEGER',
            $this->_platform->getMediumIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
        );
        $this->assertEquals(
            'INTEGER',
154 155 156 157 158 159 160 161 162 163 164 165 166
            $this->_platform->getMediumIntTypeDeclarationSQL(
                array('autoincrement' => true, 'primary' => true))
        );
        $this->assertEquals(
            'MEDIUMINT',
            $this->_platform->getMediumIntTypeDeclarationSQL(array('unsigned' => false))
        );
        $this->assertEquals(
            'MEDIUMINT UNSIGNED',
            $this->_platform->getMediumIntTypeDeclarationSQL(array('unsigned' => true))
        );
    }

167
    public function testGeneratesTypeDeclarationForIntegers()
168 169 170
    {
        $this->assertEquals(
            'INTEGER',
171
            $this->_platform->getIntegerTypeDeclarationSQL(array())
172 173
        );
        $this->assertEquals(
174
            'INTEGER',
175
            $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true))
176
        );
177 178 179 180
        $this->assertEquals(
            'INTEGER',
            $this->_platform->getIntegerTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
        );
181
        $this->assertEquals(
182
            'INTEGER',
183
            $this->_platform->getIntegerTypeDeclarationSQL(
184 185
                array('autoincrement' => true, 'primary' => true))
        );
186 187 188 189 190 191 192 193 194 195 196 197
        $this->assertEquals(
            'INTEGER',
            $this->_platform->getIntegerTypeDeclarationSQL(array('unsigned' => false))
        );
        $this->assertEquals(
            'INTEGER UNSIGNED',
            $this->_platform->getIntegerTypeDeclarationSQL(array('unsigned' => true))
        );
    }

    /**
     * @group DBAL-752
198
     * @group DBAL-924
199 200 201 202 203 204 205 206
     */
    public function testGeneratesTypeDeclarationForBigIntegers()
    {
        $this->assertEquals(
            'BIGINT',
            $this->_platform->getBigIntTypeDeclarationSQL(array())
        );
        $this->assertEquals(
207
            'INTEGER',
208 209 210
            $this->_platform->getBigIntTypeDeclarationSQL(array('autoincrement' => true))
        );
        $this->assertEquals(
211 212 213 214 215
            'INTEGER',
            $this->_platform->getBigIntTypeDeclarationSQL(array('autoincrement' => true, 'unsigned' => true))
        );
        $this->assertEquals(
            'INTEGER',
216 217 218 219 220 221 222 223 224 225 226
            $this->_platform->getBigIntTypeDeclarationSQL(
                array('autoincrement' => true, 'primary' => true))
        );
        $this->assertEquals(
            'BIGINT',
            $this->_platform->getBigIntTypeDeclarationSQL(array('unsigned' => false))
        );
        $this->assertEquals(
            'BIGINT UNSIGNED',
            $this->_platform->getBigIntTypeDeclarationSQL(array('unsigned' => true))
        );
227 228 229 230
    }

    public function testGeneratesTypeDeclarationForStrings()
    {
231 232
        $this->assertEquals(
            'CHAR(10)',
233
            $this->_platform->getVarcharTypeDeclarationSQL(
234 235
                array('length' => 10, 'fixed' => true))
        );
236 237
        $this->assertEquals(
            'VARCHAR(50)',
238
            $this->_platform->getVarcharTypeDeclarationSQL(array('length' => 50)),
239
            'Variable string declaration is not correct'
240 241
        );
        $this->assertEquals(
242
            'VARCHAR(255)',
243
            $this->_platform->getVarcharTypeDeclarationSQL(array()),
244
            'Long string declaration is not correct'
245
        );
246
    }
247

248 249 250 251 252 253
    public function getGenerateIndexSql()
    {
        return 'CREATE INDEX my_idx ON mytable (user_name, last_login)';
    }

    public function getGenerateUniqueIndexSql()
254
    {
255
        return 'CREATE UNIQUE INDEX index_name ON test (test, test2)';
256 257
    }

258 259 260 261 262 263 264 265
    /**
     * @expectedException \Doctrine\DBAL\DBALException
     */
    public function testGeneratesForeignKeyCreationSql()
    {
        parent::testGeneratesForeignKeyCreationSql();
    }

266 267 268 269 270 271 272 273
    /**
     * @expectedException \Doctrine\DBAL\DBALException
     */
    public function testGeneratesConstraintCreationSql()
    {
        parent::testGeneratesConstraintCreationSql();
    }

274
    public function getGenerateForeignKeySql()
275
    {
276
        return null;
277
    }
278 279 280 281

    public function testModifyLimitQuery()
    {
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10, 0);
282
        $this->assertEquals('SELECT * FROM user LIMIT 10 OFFSET 0', $sql);
283 284 285 286 287 288 289
    }

    public function testModifyLimitQueryWithEmptyOffset()
    {
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', 10);
        $this->assertEquals('SELECT * FROM user LIMIT 10', $sql);
    }
290

291 292 293 294 295 296
    public function testModifyLimitQueryWithOffsetAndEmptyLimit()
    {
        $sql = $this->_platform->modifyLimitQuery('SELECT * FROM user', null, 10);
        $this->assertEquals('SELECT * FROM user LIMIT -1 OFFSET 10', $sql);
    }

297 298
    public function getGenerateAlterTableSql()
    {
299
        return array(
300
            "CREATE TEMPORARY TABLE __temp__mytable AS SELECT id, bar, bloo FROM mytable",
301
            "DROP TABLE mytable",
302 303 304 305
            "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))",
            "INSERT INTO mytable (id, baz, bloo) SELECT id, bar, bloo FROM __temp__mytable",
            "DROP TABLE __temp__mytable",
            "ALTER TABLE mytable RENAME TO userlist",
306
        );
307
    }
Fabio B. Silva's avatar
Fabio B. Silva committed
308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323

    /**
     * @group DDC-1845
     */
    public function testGenerateTableSqlShouldNotAutoQuotePrimaryKey()
    {
        $table = new \Doctrine\DBAL\Schema\Table('test');
        $table->addColumn('"like"', 'integer', array('notnull' => true, 'autoincrement' => true));
        $table->setPrimaryKey(array('"like"'));

        $createTableSQL = $this->_platform->getCreateTableSQL($table);
        $this->assertEquals(
            'CREATE TABLE test ("like" INTEGER NOT NULL, PRIMARY KEY("like"))',
            $createTableSQL[0]
        );
    }
324

325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359
    public function testAlterTableAddColumns()
    {
        $diff = new TableDiff('user');
        $diff->addedColumns['foo'] = new Column('foo', Type::getType('string'));
        $diff->addedColumns['count'] = new Column('count', Type::getType('integer'), array('notnull' => false, 'default' => 1));

        $expected = array(
            'ALTER TABLE user ADD COLUMN foo VARCHAR(255) NOT NULL',
            'ALTER TABLE user ADD COLUMN count INTEGER DEFAULT 1',
        );

        $this->assertEquals($expected, $this->_platform->getAlterTableSQL($diff));
    }

    public function testAlterTableAddComplexColumns()
    {
        $diff = new TableDiff('user');
        $diff->addedColumns['time'] = new Column('time', Type::getType('date'), array('default' => 'CURRENT_DATE'));

        try {
            $this->_platform->getAlterTableSQL($diff);
            $this->fail();
        } catch (DBALException $e) {
        }

        $diff = new TableDiff('user');
        $diff->addedColumns['id'] = new Column('id', Type::getType('integer'), array('autoincrement' => true));

        try {
            $this->_platform->getAlterTableSQL($diff);
            $this->fail();
        } catch (DBALException $e) {
        }
    }

360 361 362 363 364 365 366
    public function testCreateTableWithDeferredForeignKeys()
    {
        $table = new Table('user');
        $table->addColumn('id', 'integer');
        $table->addColumn('article', 'integer');
        $table->addColumn('post', 'integer');
        $table->addColumn('parent', 'integer');
367
        $table->setPrimaryKey(array('id'));
368 369 370 371 372 373
        $table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true));
        $table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true));
        $table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true));

        $sql = array(
            'CREATE TABLE user ('
374 375
                . 'id INTEGER NOT NULL, article INTEGER NOT NULL, post INTEGER NOT NULL, parent INTEGER NOT NULL'
                . ', PRIMARY KEY(id)'
376 377 378 379 380 381 382 383 384 385 386 387
                . ', CONSTRAINT FK_8D93D64923A0E66 FOREIGN KEY (article) REFERENCES article (id) DEFERRABLE INITIALLY IMMEDIATE'
                . ', CONSTRAINT FK_8D93D6495A8A6C8D FOREIGN KEY (post) REFERENCES post (id) NOT DEFERRABLE INITIALLY DEFERRED'
                . ', CONSTRAINT FK_8D93D6493D8E604F FOREIGN KEY (parent) REFERENCES user (id) DEFERRABLE INITIALLY DEFERRED'
                . ')',
            'CREATE INDEX IDX_8D93D64923A0E66 ON user (article)',
            'CREATE INDEX IDX_8D93D6495A8A6C8D ON user (post)',
            'CREATE INDEX IDX_8D93D6493D8E604F ON user (parent)',
        );

        $this->assertEquals($sql, $this->_platform->getCreateTableSQL($table));
    }

388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431
    public function testAlterTable()
    {
        $table = new Table('user');
        $table->addColumn('id', 'integer');
        $table->addColumn('article', 'integer');
        $table->addColumn('post', 'integer');
        $table->addColumn('parent', 'integer');
        $table->setPrimaryKey(array('id'));
        $table->addForeignKeyConstraint('article', array('article'), array('id'), array('deferrable' => true));
        $table->addForeignKeyConstraint('post', array('post'), array('id'), array('deferred' => true));
        $table->addForeignKeyConstraint('user', array('parent'), array('id'), array('deferrable' => true, 'deferred' => true));
        $table->addIndex(array('article', 'post'), 'index1');

        $diff = new TableDiff('user');
        $diff->fromTable = $table;
        $diff->newName = 'client';
        $diff->renamedColumns['id'] = new \Doctrine\DBAL\Schema\Column('key', \Doctrine\DBAL\Types\Type::getType('integer'), array());
        $diff->renamedColumns['post'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array());
        $diff->removedColumns['parent'] = new \Doctrine\DBAL\Schema\Column('comment', \Doctrine\DBAL\Types\Type::getType('integer'), array());
        $diff->removedIndexes['index1'] = $table->getIndex('index1');

        $sql = array(
            'DROP INDEX IDX_8D93D64923A0E66',
            'DROP INDEX IDX_8D93D6495A8A6C8D',
            'DROP INDEX IDX_8D93D6493D8E604F',
            'DROP INDEX index1',
            'CREATE TEMPORARY TABLE __temp__user AS SELECT id, article, post FROM user',
            'DROP TABLE user',
            'CREATE TABLE user ('
                . '"key" INTEGER NOT NULL, article INTEGER NOT NULL, comment INTEGER NOT NULL'
                . ', PRIMARY KEY("key")'
                . ', CONSTRAINT FK_8D93D64923A0E66 FOREIGN KEY (article) REFERENCES article (id) DEFERRABLE INITIALLY IMMEDIATE'
                . ', CONSTRAINT FK_8D93D6495A8A6C8D FOREIGN KEY (comment) REFERENCES post (id) NOT DEFERRABLE INITIALLY DEFERRED'
                . ')',
            'INSERT INTO user ("key", article, comment) SELECT id, article, post FROM __temp__user',
            'DROP TABLE __temp__user',
            'ALTER TABLE user RENAME TO client',
            'CREATE INDEX IDX_8D93D64923A0E66 ON client (article)',
            'CREATE INDEX IDX_8D93D6495A8A6C8D ON client (comment)',
        );

        $this->assertEquals($sql, $this->_platform->getAlterTableSQL($diff));
    }

432 433
    protected function getQuotedColumnInPrimaryKeySQL()
    {
434
        return array(
435
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL, PRIMARY KEY("create"))',
436
        );
437 438 439 440
    }

    protected function getQuotedColumnInIndexSQL()
    {
441
        return array(
442 443 444 445 446
            'CREATE TABLE "quoted" ("create" VARCHAR(255) NOT NULL)',
            'CREATE INDEX IDX_22660D028FD6E0FB ON "quoted" ("create")',
        );
    }

Markus Fasselt's avatar
Markus Fasselt committed
447 448 449 450 451 452 453 454
    protected function getQuotedNameInIndexSQL()
    {
        return array(
            'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
            'CREATE INDEX "key" ON test (column1)',
        );
    }

455 456 457
    protected function getQuotedColumnInForeignKeySQL()
    {
        return array(
458 459 460 461 462
            '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") NOT DEFERRABLE INITIALLY IMMEDIATE, ' .
            'CONSTRAINT FK_WITH_NON_RESERVED_KEYWORD FOREIGN KEY ("create", foo, "bar") REFERENCES foo ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE, ' .
            'CONSTRAINT FK_WITH_INTENDED_QUOTATION FOREIGN KEY ("create", foo, "bar") REFERENCES "foo-bar" ("create", bar, "foo-bar") NOT DEFERRABLE INITIALLY IMMEDIATE)',
463
        );
464
    }
Steve Müller's avatar
Steve Müller committed
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485

    protected function getBinaryDefaultLength()
    {
        return 0;
    }

    protected function getBinaryMaxLength()
    {
        return 0;
    }

    public function testReturnsBinaryTypeDeclarationSQL()
    {
        $this->assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array()));
        $this->assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 0)));
        $this->assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('length' => 9999999)));

        $this->assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true)));
        $this->assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 0)));
        $this->assertSame('BLOB', $this->_platform->getBinaryTypeDeclarationSQL(array('fixed' => true, 'length' => 9999999)));
    }
486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512

    /**
     * @group DBAL-234
     */
    protected function getAlterTableRenameIndexSQL()
    {
        return array(
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT id FROM mytable',
            'DROP TABLE mytable',
            'CREATE TABLE mytable (id INTEGER NOT NULL, PRIMARY KEY(id))',
            'INSERT INTO mytable (id) SELECT id FROM __temp__mytable',
            'DROP TABLE __temp__mytable',
            'CREATE INDEX idx_bar ON mytable (id)',
        );
    }

    /**
     * @group DBAL-234
     */
    protected function getQuotedAlterTableRenameIndexSQL()
    {
        return array(
            'CREATE TEMPORARY TABLE __temp__table AS SELECT id FROM "table"',
            'DROP TABLE "table"',
            'CREATE TABLE "table" (id INTEGER NOT NULL, PRIMARY KEY(id))',
            'INSERT INTO "table" (id) SELECT id FROM __temp__table',
            'DROP TABLE __temp__table',
513 514
            'CREATE INDEX "select" ON "table" (id)',
            'CREATE INDEX "bar" ON "table" (id)',
515 516
        );
    }
517 518 519 520 521 522 523 524 525 526 527 528 529

    /**
     * {@inheritdoc}
     */
    protected function getQuotedAlterTableRenameColumnSQL()
    {
        return array(
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select", "quoted1", "quoted2", "quoted3" FROM mytable',
            'DROP TABLE mytable',
            'CREATE TABLE mytable (unquoted INTEGER NOT NULL, "where" INTEGER NOT NULL, "foo" INTEGER NOT NULL, reserved_keyword INTEGER NOT NULL, "from" INTEGER NOT NULL, "bar" INTEGER NOT NULL, quoted INTEGER NOT NULL, "and" INTEGER NOT NULL, "baz" INTEGER NOT NULL)',
            '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',
            'DROP TABLE __temp__mytable',
        );
530 531 532 533 534 535 536 537 538 539 540 541 542 543
	}

    /**
     * {@inheritdoc}
     */
    protected function getQuotedAlterTableChangeColumnLengthSQL()
    {
        return array(
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM mytable',
            'DROP TABLE mytable',
            'CREATE TABLE mytable (unquoted1 VARCHAR(255) NOT NULL, unquoted2 VARCHAR(255) NOT NULL, unquoted3 VARCHAR(255) NOT NULL, "create" VARCHAR(255) NOT NULL, "table" VARCHAR(255) NOT NULL, "select" VARCHAR(255) NOT NULL)',
            'INSERT INTO mytable (unquoted1, unquoted2, unquoted3, "create", "table", "select") SELECT unquoted1, unquoted2, unquoted3, "create", "table", "select" FROM __temp__mytable',
            'DROP TABLE __temp__mytable',
        );
544
    }
545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566

    /**
     * @group DBAL-807
     */
    public function testAlterTableRenameIndexInSchema()
    {
        $this->markTestIncomplete(
            'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' .
            'when used with schemas.'
        );
    }

    /**
     * @group DBAL-807
     */
    public function testQuotesAlterTableRenameIndexInSchema()
    {
        $this->markTestIncomplete(
            'Test currently produces broken SQL due to SQLLitePlatform::getAlterTable being broken ' .
            'when used with schemas.'
        );
    }
567 568 569 570 571 572 573 574

    /**
     * @group DBAL-423
     */
    public function testReturnsGuidTypeDeclarationSQL()
    {
        $this->assertSame('CHAR(36)', $this->_platform->getGuidTypeDeclarationSQL(array()));
    }
575 576 577 578 579 580 581 582 583 584 585 586 587 588

    /**
     * {@inheritdoc}
     */
    public function getAlterTableRenameColumnSQL()
    {
        return array(
            'CREATE TEMPORARY TABLE __temp__foo AS SELECT bar FROM foo',
            'DROP TABLE foo',
            'CREATE TABLE foo (baz INTEGER DEFAULT 666 NOT NULL)',
            'INSERT INTO foo (baz) SELECT bar FROM __temp__foo',
            'DROP TABLE __temp__foo',
        );
    }
589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610

    /**
     * {@inheritdoc}
     */
    protected function getQuotesTableIdentifiersInAlterTableSQL()
    {
        return array(
            'DROP INDEX IDX_8C736521A81E660E',
            'DROP INDEX IDX_8C736521FDC58D6C',
            'CREATE TEMPORARY TABLE __temp__foo AS SELECT fk, fk2, id, fk3, bar FROM "foo"',
            'DROP TABLE "foo"',
            'CREATE TABLE "foo" (fk2 INTEGER NOT NULL, fk3 INTEGER NOT NULL, fk INTEGER NOT NULL, war INTEGER NOT NULL, ' .
            'bar INTEGER DEFAULT NULL, bloo INTEGER NOT NULL, ' .
            'CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id) NOT DEFERRABLE INITIALLY IMMEDIATE, ' .
            'CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id) NOT DEFERRABLE INITIALLY IMMEDIATE)',
            'INSERT INTO "foo" (fk, fk2, war, fk3, bar) SELECT fk, fk2, id, fk3, bar FROM __temp__foo',
            'DROP TABLE __temp__foo',
            'ALTER TABLE "foo" RENAME TO "table"',
            'CREATE INDEX IDX_8C736521A81E660E ON "table" (fk)',
            'CREATE INDEX IDX_8C736521FDC58D6C ON "table" (fk2)',
        );
    }
611 612 613 614 615 616 617 618 619 620 621 622

    /**
     * {@inheritdoc}
     */
    protected function getCommentOnColumnSQL()
    {
        return array(
            'COMMENT ON COLUMN foo.bar IS \'comment\'',
            'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'',
            'COMMENT ON COLUMN "select"."from" IS \'comment\'',
        );
    }
623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638

    /**
     * {@inheritdoc}
     */
    protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL()
    {
        return 'CONSTRAINT "select" UNIQUE (foo)';
    }

    /**
     * {@inheritdoc}
     */
    protected function getQuotesReservedKeywordInIndexDeclarationSQL()
    {
        return 'INDEX "select" (foo)';
    }
639 640 641 642 643 644 645 646 647 648 649 650 651 652

    /**
     * {@inheritdoc}
     */
    protected function getAlterStringToFixedStringSQL()
    {
        return array(
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT name FROM mytable',
            'DROP TABLE mytable',
            'CREATE TABLE mytable (name CHAR(2) NOT NULL)',
            'INSERT INTO mytable (name) SELECT name FROM __temp__mytable',
            'DROP TABLE __temp__mytable',
        );
    }
653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670

    /**
     * {@inheritdoc}
     */
    protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL()
    {
        return array(
            'DROP INDEX idx_foo',
            'DROP INDEX idx_bar',
            'CREATE TEMPORARY TABLE __temp__mytable AS SELECT foo, bar, baz FROM mytable',
            'DROP TABLE mytable',
            '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)',
            'INSERT INTO mytable (foo, bar, baz) SELECT foo, bar, baz FROM __temp__mytable',
            'DROP TABLE __temp__mytable',
            'CREATE INDEX idx_bar ON mytable (bar)',
            'CREATE INDEX idx_foo_renamed ON mytable (foo)',
        );
    }
671
}