| Total Complexity | 107 |
| Total Lines | 1174 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
Complex classes like SQLAnywherePlatformTest often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use SQLAnywherePlatformTest, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 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 | [false, ''], |
||
| 225 | [true, ''], |
||
| 226 | [LockMode::NONE, ' WITH (NOLOCK)'], |
||
| 227 | [LockMode::OPTIMISTIC, ''], |
||
| 228 | [LockMode::PESSIMISTIC_READ, ' WITH (UPDLOCK)'], |
||
| 229 | [LockMode::PESSIMISTIC_WRITE, ' WITH (XLOCK)'], |
||
| 230 | ]; |
||
| 231 | } |
||
| 232 | |||
| 233 | public function testHasCorrectMaxIdentifierLength() |
||
| 236 | } |
||
| 237 | |||
| 238 | public function testFixesSchemaElementNames() |
||
| 239 | { |
||
| 240 | $maxIdentifierLength = $this->platform->getMaxIdentifierLength(); |
||
| 241 | $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'; |
||
| 242 | $schemaElementName = ''; |
||
| 243 | |||
| 244 | for ($i = 0; $i < $maxIdentifierLength + 100; $i++) { |
||
| 245 | $schemaElementName .= $characters[mt_rand(0, strlen($characters) - 1)]; |
||
| 246 | } |
||
| 247 | |||
| 248 | $fixedSchemaElementName = substr($schemaElementName, 0, $maxIdentifierLength); |
||
| 249 | |||
| 250 | self::assertEquals( |
||
| 251 | $fixedSchemaElementName, |
||
| 252 | $this->platform->fixSchemaElementName($schemaElementName) |
||
| 253 | ); |
||
| 254 | self::assertEquals( |
||
| 255 | $fixedSchemaElementName, |
||
| 256 | $this->platform->fixSchemaElementName($fixedSchemaElementName) |
||
| 257 | ); |
||
| 258 | } |
||
| 259 | |||
| 260 | public function testGeneratesColumnTypesDeclarationSQL() |
||
| 288 | } |
||
| 289 | |||
| 290 | public function testHasNativeGuidType() |
||
| 291 | { |
||
| 292 | self::assertTrue($this->platform->hasNativeGuidType()); |
||
| 293 | } |
||
| 294 | |||
| 295 | public function testGeneratesDDLSnippets() |
||
| 296 | { |
||
| 297 | self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('foobar')); |
||
| 298 | self::assertEquals("CREATE DATABASE 'foobar'", $this->platform->getCreateDatabaseSQL('"foobar"')); |
||
| 299 | self::assertEquals("CREATE DATABASE 'create'", $this->platform->getCreateDatabaseSQL('create')); |
||
| 300 | self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('foobar')); |
||
| 301 | self::assertEquals("DROP DATABASE 'foobar'", $this->platform->getDropDatabaseSQL('"foobar"')); |
||
| 302 | self::assertEquals("DROP DATABASE 'create'", $this->platform->getDropDatabaseSQL('create')); |
||
| 303 | self::assertEquals('CREATE GLOBAL TEMPORARY TABLE', $this->platform->getCreateTemporaryTableSnippetSQL()); |
||
| 304 | self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('foobar')); |
||
| 305 | self::assertEquals("START DATABASE 'foobar' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('"foobar"')); |
||
| 306 | self::assertEquals("START DATABASE 'create' AUTOSTOP OFF", $this->platform->getStartDatabaseSQL('create')); |
||
| 307 | self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('foobar')); |
||
| 308 | self::assertEquals('STOP DATABASE "foobar" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('"foobar"')); |
||
| 309 | self::assertEquals('STOP DATABASE "create" UNCONDITIONALLY', $this->platform->getStopDatabaseSQL('create')); |
||
| 310 | self::assertEquals('TRUNCATE TABLE foobar', $this->platform->getTruncateTableSQL('foobar')); |
||
| 311 | |||
| 312 | $viewSql = 'SELECT * FROM footable'; |
||
| 313 | self::assertEquals('CREATE VIEW fooview AS ' . $viewSql, $this->platform->getCreateViewSQL('fooview', $viewSql)); |
||
| 314 | self::assertEquals('DROP VIEW fooview', $this->platform->getDropViewSQL('fooview')); |
||
| 315 | } |
||
| 316 | |||
| 317 | public function testGeneratesPrimaryKeyDeclarationSQL() |
||
| 330 | ) |
||
| 331 | ); |
||
| 332 | } |
||
| 333 | |||
| 334 | public function testCannotGeneratePrimaryKeyDeclarationSQLWithEmptyColumns() |
||
| 335 | { |
||
| 336 | $this->expectException(InvalidArgumentException::class); |
||
| 337 | |||
| 338 | $this->platform->getPrimaryKeyDeclarationSQL(new Index('pk', [], true, true)); |
||
| 339 | } |
||
| 340 | |||
| 341 | public function testGeneratesCreateUnnamedPrimaryKeySQL() |
||
| 342 | { |
||
| 343 | self::assertEquals( |
||
| 344 | 'ALTER TABLE foo ADD PRIMARY KEY CLUSTERED (a, b)', |
||
| 345 | $this->platform->getCreatePrimaryKeySQL( |
||
| 346 | new Index('pk', ['a', 'b'], true, true, ['clustered']), |
||
| 347 | 'foo' |
||
| 348 | ) |
||
| 349 | ); |
||
| 350 | self::assertEquals( |
||
| 351 | 'ALTER TABLE foo ADD PRIMARY KEY (a, b)', |
||
| 352 | $this->platform->getCreatePrimaryKeySQL( |
||
| 353 | new Index('any_pk_name', ['a', 'b'], true, true), |
||
| 354 | new Table('foo') |
||
| 355 | ) |
||
| 356 | ); |
||
| 357 | } |
||
| 358 | |||
| 359 | public function testGeneratesUniqueConstraintDeclarationSQL() |
||
| 360 | { |
||
| 361 | self::assertEquals( |
||
| 362 | 'CONSTRAINT unique_constraint UNIQUE CLUSTERED (a, b)', |
||
| 363 | $this->platform->getUniqueConstraintDeclarationSQL( |
||
| 364 | 'unique_constraint', |
||
| 365 | new UniqueConstraint('', ['a', 'b'], ['clustered']) |
||
| 366 | ) |
||
| 367 | ); |
||
| 368 | self::assertEquals( |
||
| 369 | 'CONSTRAINT UNIQUE (a, b)', |
||
| 370 | $this->platform->getUniqueConstraintDeclarationSQL('', new UniqueConstraint('', ['a', 'b'])) |
||
| 371 | ); |
||
| 372 | } |
||
| 373 | |||
| 374 | public function testCannotGenerateUniqueConstraintDeclarationSQLWithEmptyColumns() |
||
| 375 | { |
||
| 376 | $this->expectException(InvalidArgumentException::class); |
||
| 377 | |||
| 378 | $this->platform->getUniqueConstraintDeclarationSQL('constr', new UniqueConstraint('constr', [])); |
||
| 379 | } |
||
| 380 | |||
| 381 | public function testGeneratesForeignKeyConstraintsWithAdvancedPlatformOptionsSQL() |
||
| 382 | { |
||
| 383 | self::assertEquals( |
||
| 384 | 'CONSTRAINT fk ' . |
||
| 385 | 'NOT NULL FOREIGN KEY (a, b) ' . |
||
| 386 | 'REFERENCES foreign_table (c, d) ' . |
||
| 387 | 'MATCH UNIQUE SIMPLE ON UPDATE CASCADE ON DELETE SET NULL CHECK ON COMMIT CLUSTERED FOR OLAP WORKLOAD', |
||
| 388 | $this->platform->getForeignKeyDeclarationSQL( |
||
| 389 | new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd'], 'fk', [ |
||
| 390 | 'notnull' => true, |
||
| 391 | 'match' => SQLAnywherePlatform::FOREIGN_KEY_MATCH_SIMPLE_UNIQUE, |
||
| 392 | 'onUpdate' => 'CASCADE', |
||
| 393 | 'onDelete' => 'SET NULL', |
||
| 394 | 'check_on_commit' => true, |
||
| 395 | 'clustered' => true, |
||
| 396 | 'for_olap_workload' => true, |
||
| 397 | ]) |
||
| 398 | ) |
||
| 399 | ); |
||
| 400 | self::assertEquals( |
||
| 401 | 'FOREIGN KEY (a, b) REFERENCES foreign_table (c, d)', |
||
| 402 | $this->platform->getForeignKeyDeclarationSQL( |
||
| 403 | new ForeignKeyConstraint(['a', 'b'], 'foreign_table', ['c', 'd']) |
||
| 404 | ) |
||
| 405 | ); |
||
| 406 | } |
||
| 407 | |||
| 408 | public function testGeneratesForeignKeyMatchClausesSQL() |
||
| 409 | { |
||
| 410 | self::assertEquals('SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(1)); |
||
| 411 | self::assertEquals('FULL', $this->platform->getForeignKeyMatchClauseSQL(2)); |
||
| 412 | self::assertEquals('UNIQUE SIMPLE', $this->platform->getForeignKeyMatchClauseSQL(129)); |
||
| 413 | self::assertEquals('UNIQUE FULL', $this->platform->getForeignKeyMatchClauseSQL(130)); |
||
| 414 | } |
||
| 415 | |||
| 416 | public function testCannotGenerateInvalidForeignKeyMatchClauseSQL() |
||
| 417 | { |
||
| 418 | $this->expectException(InvalidArgumentException::class); |
||
| 419 | |||
| 420 | $this->platform->getForeignKeyMatchCLauseSQL(3); |
||
| 421 | } |
||
| 422 | |||
| 423 | public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns() |
||
| 424 | { |
||
| 425 | $this->expectException(InvalidArgumentException::class); |
||
| 426 | $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint([], 'foreign_tbl', ['c', 'd'])); |
||
| 427 | } |
||
| 428 | |||
| 429 | public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignColumns() |
||
| 430 | { |
||
| 431 | $this->expectException(InvalidArgumentException::class); |
||
| 432 | $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], 'foreign_tbl', [])); |
||
| 433 | } |
||
| 434 | |||
| 435 | public function testCannotGenerateForeignKeyConstraintSQLWithEmptyForeignTableName() |
||
| 436 | { |
||
| 437 | $this->expectException(InvalidArgumentException::class); |
||
| 438 | $this->platform->getForeignKeyDeclarationSQL(new ForeignKeyConstraint(['a', 'b'], '', ['c', 'd'])); |
||
| 439 | } |
||
| 440 | |||
| 441 | public function testCannotGenerateCommonIndexWithCreateConstraintSQL() |
||
| 442 | { |
||
| 443 | $this->expectException(InvalidArgumentException::class); |
||
| 444 | |||
| 445 | $this->platform->getCreateConstraintSQL(new Index('fooindex', []), new Table('footable')); |
||
| 446 | } |
||
| 447 | |||
| 448 | public function testCannotGenerateCustomConstraintWithCreateConstraintSQL() |
||
| 449 | { |
||
| 450 | $this->expectException(InvalidArgumentException::class); |
||
| 451 | |||
| 452 | $this->platform->getCreateConstraintSQL($this->createMock(Constraint::class), 'footable'); |
||
| 453 | } |
||
| 454 | |||
| 455 | public function testGeneratesCreateIndexWithAdvancedPlatformOptionsSQL() |
||
| 456 | { |
||
| 457 | self::assertEquals( |
||
| 458 | 'CREATE UNIQUE INDEX fooindex ON footable (a, b) WITH NULLS DISTINCT', |
||
| 459 | $this->platform->getCreateIndexSQL( |
||
| 460 | new Index( |
||
| 461 | 'fooindex', |
||
| 462 | ['a', 'b'], |
||
| 463 | true, |
||
| 464 | false, |
||
| 465 | ['with_nulls_distinct'] |
||
| 466 | ), |
||
| 467 | 'footable' |
||
| 468 | ) |
||
| 469 | ); |
||
| 470 | |||
| 471 | // WITH NULLS DISTINCT clause not available on primary indexes. |
||
| 472 | self::assertEquals( |
||
| 473 | 'ALTER TABLE footable ADD PRIMARY KEY (a, b)', |
||
| 474 | $this->platform->getCreateIndexSQL( |
||
| 475 | new Index( |
||
| 476 | 'fooindex', |
||
| 477 | ['a', 'b'], |
||
| 478 | false, |
||
| 479 | true, |
||
| 480 | ['with_nulls_distinct'] |
||
| 481 | ), |
||
| 482 | 'footable' |
||
| 483 | ) |
||
| 484 | ); |
||
| 485 | |||
| 486 | // WITH NULLS DISTINCT clause not available on non-unique indexes. |
||
| 487 | self::assertEquals( |
||
| 488 | 'CREATE INDEX fooindex ON footable (a, b)', |
||
| 489 | $this->platform->getCreateIndexSQL( |
||
| 490 | new Index( |
||
| 491 | 'fooindex', |
||
| 492 | ['a', 'b'], |
||
| 493 | false, |
||
| 494 | false, |
||
| 495 | ['with_nulls_distinct'] |
||
| 496 | ), |
||
| 497 | 'footable' |
||
| 498 | ) |
||
| 499 | ); |
||
| 500 | |||
| 501 | self::assertEquals( |
||
| 502 | 'CREATE VIRTUAL UNIQUE CLUSTERED INDEX fooindex ON footable (a, b) WITH NULLS NOT DISTINCT FOR OLAP WORKLOAD', |
||
| 503 | $this->platform->getCreateIndexSQL( |
||
| 504 | new Index( |
||
| 505 | 'fooindex', |
||
| 506 | ['a', 'b'], |
||
| 507 | true, |
||
| 508 | false, |
||
| 509 | ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload'] |
||
| 510 | ), |
||
| 511 | 'footable' |
||
| 512 | ) |
||
| 513 | ); |
||
| 514 | self::assertEquals( |
||
| 515 | 'CREATE VIRTUAL CLUSTERED INDEX fooindex ON footable (a, b) FOR OLAP WORKLOAD', |
||
| 516 | $this->platform->getCreateIndexSQL( |
||
| 517 | new Index( |
||
| 518 | 'fooindex', |
||
| 519 | ['a', 'b'], |
||
| 520 | false, |
||
| 521 | false, |
||
| 522 | ['virtual', 'clustered', 'with_nulls_not_distinct', 'for_olap_workload'] |
||
| 523 | ), |
||
| 524 | 'footable' |
||
| 525 | ) |
||
| 526 | ); |
||
| 527 | |||
| 528 | // WITH NULLS NOT DISTINCT clause not available on primary indexes. |
||
| 529 | self::assertEquals( |
||
| 530 | 'ALTER TABLE footable ADD PRIMARY KEY (a, b)', |
||
| 531 | $this->platform->getCreateIndexSQL( |
||
| 532 | new Index( |
||
| 533 | 'fooindex', |
||
| 534 | ['a', 'b'], |
||
| 535 | false, |
||
| 536 | true, |
||
| 537 | ['with_nulls_not_distinct'] |
||
| 538 | ), |
||
| 539 | 'footable' |
||
| 540 | ) |
||
| 541 | ); |
||
| 542 | |||
| 543 | // WITH NULLS NOT DISTINCT clause not available on non-unique indexes. |
||
| 544 | self::assertEquals( |
||
| 545 | 'CREATE INDEX fooindex ON footable (a, b)', |
||
| 546 | $this->platform->getCreateIndexSQL( |
||
| 547 | new Index( |
||
| 548 | 'fooindex', |
||
| 549 | ['a', 'b'], |
||
| 550 | false, |
||
| 551 | false, |
||
| 552 | ['with_nulls_not_distinct'] |
||
| 553 | ), |
||
| 554 | 'footable' |
||
| 555 | ) |
||
| 556 | ); |
||
| 557 | } |
||
| 558 | |||
| 559 | public function testThrowsExceptionOnInvalidWithNullsNotDistinctIndexOptions() |
||
| 560 | { |
||
| 561 | $this->expectException('UnexpectedValueException'); |
||
| 562 | |||
| 563 | $this->platform->getCreateIndexSQL( |
||
| 564 | new Index( |
||
| 565 | 'fooindex', |
||
| 566 | ['a', 'b'], |
||
| 567 | false, |
||
| 568 | false, |
||
| 569 | ['with_nulls_distinct', 'with_nulls_not_distinct'] |
||
| 570 | ), |
||
| 571 | 'footable' |
||
| 572 | ); |
||
| 573 | } |
||
| 574 | |||
| 575 | public function testDoesNotSupportIndexDeclarationInCreateAlterTableStatements() |
||
| 576 | { |
||
| 577 | $this->expectException(DBALException::class); |
||
| 578 | |||
| 579 | $this->platform->getIndexDeclarationSQL('index', new Index('index', [])); |
||
| 580 | } |
||
| 581 | |||
| 582 | public function testGeneratesDropIndexSQL() |
||
| 591 | )); |
||
| 592 | } |
||
| 593 | |||
| 594 | public function testCannotGenerateDropIndexSQLWithInvalidIndexParameter() |
||
| 595 | { |
||
| 596 | $this->expectException(InvalidArgumentException::class); |
||
| 597 | |||
| 598 | $this->platform->getDropIndexSQL(['index'], 'table'); |
||
| 599 | } |
||
| 600 | |||
| 601 | public function testCannotGenerateDropIndexSQLWithInvalidTableParameter() |
||
| 606 | } |
||
| 607 | |||
| 608 | public function testGeneratesSQLSnippets() |
||
| 609 | { |
||
| 610 | self::assertEquals('STRING(column1, "string1", column2, "string2")', $this->platform->getConcatExpression( |
||
| 611 | 'column1', |
||
| 612 | '"string1"', |
||
| 613 | 'column2', |
||
| 614 | '"string2"' |
||
| 615 | )); |
||
| 616 | self::assertEquals('CURRENT DATE', $this->platform->getCurrentDateSQL()); |
||
| 617 | self::assertEquals('CURRENT TIME', $this->platform->getCurrentTimeSQL()); |
||
| 618 | self::assertEquals('CURRENT TIMESTAMP', $this->platform->getCurrentTimestampSQL()); |
||
| 619 | self::assertEquals("DATEADD(DAY, 4, '1987/05/02')", $this->platform->getDateAddDaysExpression("'1987/05/02'", '4')); |
||
| 620 | self::assertEquals("DATEADD(HOUR, 12, '1987/05/02')", $this->platform->getDateAddHourExpression("'1987/05/02'", '12')); |
||
| 621 | self::assertEquals("DATEADD(MINUTE, 2, '1987/05/02')", $this->platform->getDateAddMinutesExpression("'1987/05/02'", '2')); |
||
| 622 | self::assertEquals("DATEADD(MONTH, 102, '1987/05/02')", $this->platform->getDateAddMonthExpression("'1987/05/02'", '102')); |
||
| 623 | self::assertEquals("DATEADD(QUARTER, 5, '1987/05/02')", $this->platform->getDateAddQuartersExpression("'1987/05/02'", '5')); |
||
| 624 | self::assertEquals("DATEADD(SECOND, 1, '1987/05/02')", $this->platform->getDateAddSecondsExpression("'1987/05/02'", '1')); |
||
| 625 | self::assertEquals("DATEADD(WEEK, 3, '1987/05/02')", $this->platform->getDateAddWeeksExpression("'1987/05/02'", '3')); |
||
| 626 | self::assertEquals("DATEADD(YEAR, 10, '1987/05/02')", $this->platform->getDateAddYearsExpression("'1987/05/02'", '10')); |
||
| 627 | self::assertEquals("DATEDIFF(day, '1987/04/01', '1987/05/02')", $this->platform->getDateDiffExpression("'1987/05/02'", "'1987/04/01'")); |
||
| 628 | self::assertEquals("DATEADD(DAY, -1 * 4, '1987/05/02')", $this->platform->getDateSubDaysExpression("'1987/05/02'", '4')); |
||
| 629 | self::assertEquals("DATEADD(HOUR, -1 * 12, '1987/05/02')", $this->platform->getDateSubHourExpression("'1987/05/02'", '12')); |
||
| 630 | self::assertEquals("DATEADD(MINUTE, -1 * 2, '1987/05/02')", $this->platform->getDateSubMinutesExpression("'1987/05/02'", '2')); |
||
| 631 | self::assertEquals("DATEADD(MONTH, -1 * 102, '1987/05/02')", $this->platform->getDateSubMonthExpression("'1987/05/02'", '102')); |
||
| 632 | self::assertEquals("DATEADD(QUARTER, -1 * 5, '1987/05/02')", $this->platform->getDateSubQuartersExpression("'1987/05/02'", '5')); |
||
| 633 | self::assertEquals("DATEADD(SECOND, -1 * 1, '1987/05/02')", $this->platform->getDateSubSecondsExpression("'1987/05/02'", '1')); |
||
| 634 | self::assertEquals("DATEADD(WEEK, -1 * 3, '1987/05/02')", $this->platform->getDateSubWeeksExpression("'1987/05/02'", '3')); |
||
| 635 | self::assertEquals("DATEADD(YEAR, -1 * 10, '1987/05/02')", $this->platform->getDateSubYearsExpression("'1987/05/02'", '10')); |
||
| 636 | self::assertEquals('Y-m-d H:i:s.u', $this->platform->getDateTimeFormatString()); |
||
| 637 | self::assertEquals('H:i:s.u', $this->platform->getTimeFormatString()); |
||
| 638 | self::assertEquals('', $this->platform->getForUpdateSQL()); |
||
| 639 | self::assertEquals('LOCATE(string_column, substring_column)', $this->platform->getLocateExpression('string_column', 'substring_column')); |
||
| 640 | self::assertEquals('LOCATE(string_column, substring_column, 1)', $this->platform->getLocateExpression('string_column', 'substring_column', '1')); |
||
| 641 | self::assertEquals("HASH(column, 'MD5')", $this->platform->getMd5Expression('column')); |
||
| 642 | self::assertEquals('SUBSTRING(column, 5)', $this->platform->getSubstringExpression('column', '5')); |
||
| 643 | self::assertEquals('SUBSTRING(column, 5, 2)', $this->platform->getSubstringExpression('column', '5', '2')); |
||
| 644 | self::assertEquals('GLOBAL TEMPORARY', $this->platform->getTemporaryTableSQL()); |
||
| 645 | self::assertEquals( |
||
| 646 | 'LTRIM(column)', |
||
| 647 | $this->platform->getTrimExpression('column', TrimMode::LEADING) |
||
| 648 | ); |
||
| 649 | self::assertEquals( |
||
| 650 | 'RTRIM(column)', |
||
| 651 | $this->platform->getTrimExpression('column', TrimMode::TRAILING) |
||
| 652 | ); |
||
| 653 | self::assertEquals( |
||
| 654 | 'TRIM(column)', |
||
| 655 | $this->platform->getTrimExpression('column') |
||
| 656 | ); |
||
| 657 | self::assertEquals( |
||
| 658 | 'TRIM(column)', |
||
| 659 | $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED) |
||
| 660 | ); |
||
| 661 | self::assertEquals( |
||
| 662 | "SUBSTR(column, PATINDEX('%[^' + c + ']%', column))", |
||
| 663 | $this->platform->getTrimExpression('column', TrimMode::LEADING, 'c') |
||
| 664 | ); |
||
| 665 | self::assertEquals( |
||
| 666 | "REVERSE(SUBSTR(REVERSE(column), PATINDEX('%[^' + c + ']%', REVERSE(column))))", |
||
| 667 | $this->platform->getTrimExpression('column', TrimMode::TRAILING, 'c') |
||
| 668 | ); |
||
| 669 | self::assertEquals( |
||
| 670 | "REVERSE(SUBSTR(REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))), PATINDEX('%[^' + c + ']%', " . |
||
| 671 | "REVERSE(SUBSTR(column, PATINDEX('%[^' + c + ']%', column))))))", |
||
| 672 | $this->platform->getTrimExpression('column', TrimMode::UNSPECIFIED, 'c') |
||
| 673 | ); |
||
| 674 | } |
||
| 675 | |||
| 676 | public function testHasCorrectDateTimeTzFormatString() |
||
| 677 | { |
||
| 678 | self::assertEquals('Y-m-d H:i:s.uP', $this->platform->getDateTimeTzFormatString()); |
||
| 679 | } |
||
| 680 | |||
| 681 | public function testGeneratesDateTimeTzColumnTypeDeclarationSQL() |
||
| 682 | { |
||
| 683 | self::assertEquals( |
||
| 684 | 'TIMESTAMP WITH TIME ZONE', |
||
| 685 | $this->platform->getDateTimeTzTypeDeclarationSQL([ |
||
| 686 | 'length' => 10, |
||
| 687 | 'fixed' => true, |
||
| 688 | 'unsigned' => true, |
||
| 689 | 'autoincrement' => true, |
||
| 690 | ]) |
||
| 691 | ); |
||
| 692 | } |
||
| 693 | |||
| 694 | public function testInitializesDateTimeTzTypeMapping() |
||
| 695 | { |
||
| 696 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('timestamp with time zone')); |
||
| 697 | self::assertEquals('datetime', $this->platform->getDoctrineTypeMapping('timestamp with time zone')); |
||
| 698 | } |
||
| 699 | |||
| 700 | public function testHasCorrectDefaultTransactionIsolationLevel() |
||
| 701 | { |
||
| 702 | self::assertEquals( |
||
| 703 | TransactionIsolationLevel::READ_UNCOMMITTED, |
||
| 704 | $this->platform->getDefaultTransactionIsolationLevel() |
||
| 705 | ); |
||
| 706 | } |
||
| 707 | |||
| 708 | public function testGeneratesTransactionsCommands() |
||
| 709 | { |
||
| 710 | self::assertEquals( |
||
| 711 | 'SET TEMPORARY OPTION isolation_level = 0', |
||
| 712 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_UNCOMMITTED) |
||
| 713 | ); |
||
| 714 | self::assertEquals( |
||
| 715 | 'SET TEMPORARY OPTION isolation_level = 1', |
||
| 716 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::READ_COMMITTED) |
||
| 717 | ); |
||
| 718 | self::assertEquals( |
||
| 719 | 'SET TEMPORARY OPTION isolation_level = 2', |
||
| 720 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::REPEATABLE_READ) |
||
| 721 | ); |
||
| 722 | self::assertEquals( |
||
| 723 | 'SET TEMPORARY OPTION isolation_level = 3', |
||
| 724 | $this->platform->getSetTransactionIsolationSQL(TransactionIsolationLevel::SERIALIZABLE) |
||
| 725 | ); |
||
| 726 | } |
||
| 727 | |||
| 728 | public function testCannotGenerateTransactionCommandWithInvalidIsolationLevel() |
||
| 729 | { |
||
| 730 | $this->expectException(InvalidArgumentException::class); |
||
| 731 | |||
| 732 | $this->platform->getSetTransactionIsolationSQL('invalid_transaction_isolation_level'); |
||
| 733 | } |
||
| 734 | |||
| 735 | public function testModifiesLimitQuery() |
||
| 736 | { |
||
| 737 | self::assertEquals( |
||
| 738 | 'SELECT TOP 10 * FROM user', |
||
| 739 | $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 0) |
||
| 740 | ); |
||
| 741 | } |
||
| 742 | |||
| 743 | public function testModifiesLimitQueryWithEmptyOffset() |
||
| 744 | { |
||
| 745 | self::assertEquals( |
||
| 746 | 'SELECT TOP 10 * FROM user', |
||
| 747 | $this->platform->modifyLimitQuery('SELECT * FROM user', 10) |
||
| 748 | ); |
||
| 749 | } |
||
| 750 | |||
| 751 | public function testModifiesLimitQueryWithOffset() |
||
| 752 | { |
||
| 753 | self::assertEquals( |
||
| 754 | 'SELECT TOP 10 START AT 6 * FROM user', |
||
| 755 | $this->platform->modifyLimitQuery('SELECT * FROM user', 10, 5) |
||
| 756 | ); |
||
| 757 | self::assertEquals( |
||
| 758 | 'SELECT TOP 0 START AT 6 * FROM user', |
||
| 759 | $this->platform->modifyLimitQuery('SELECT * FROM user', 0, 5) |
||
| 760 | ); |
||
| 761 | } |
||
| 762 | |||
| 763 | public function testModifiesLimitQueryWithSubSelect() |
||
| 764 | { |
||
| 765 | self::assertEquals( |
||
| 766 | 'SELECT TOP 10 * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl', |
||
| 767 | $this->platform->modifyLimitQuery('SELECT * FROM (SELECT u.id as uid, u.name as uname FROM user) AS doctrine_tbl', 10) |
||
| 768 | ); |
||
| 769 | } |
||
| 770 | |||
| 771 | public function testModifiesLimitQueryWithoutLimit() |
||
| 772 | { |
||
| 773 | self::assertEquals( |
||
| 774 | 'SELECT TOP ALL START AT 11 n FROM Foo', |
||
| 775 | $this->platform->modifyLimitQuery('SELECT n FROM Foo', null, 10) |
||
| 776 | ); |
||
| 777 | } |
||
| 778 | |||
| 779 | public function testPrefersIdentityColumns() |
||
| 780 | { |
||
| 781 | self::assertTrue($this->platform->prefersIdentityColumns()); |
||
| 782 | } |
||
| 783 | |||
| 784 | public function testDoesNotPreferSequences() |
||
| 785 | { |
||
| 786 | self::assertFalse($this->platform->prefersSequences()); |
||
| 787 | } |
||
| 788 | |||
| 789 | public function testSupportsIdentityColumns() |
||
| 790 | { |
||
| 791 | self::assertTrue($this->platform->supportsIdentityColumns()); |
||
| 792 | } |
||
| 793 | |||
| 794 | public function testSupportsPrimaryConstraints() |
||
| 795 | { |
||
| 796 | self::assertTrue($this->platform->supportsPrimaryConstraints()); |
||
| 797 | } |
||
| 798 | |||
| 799 | public function testSupportsForeignKeyConstraints() |
||
| 800 | { |
||
| 801 | self::assertTrue($this->platform->supportsForeignKeyConstraints()); |
||
| 802 | } |
||
| 803 | |||
| 804 | public function testSupportsForeignKeyOnUpdate() |
||
| 807 | } |
||
| 808 | |||
| 809 | public function testSupportsAlterTable() |
||
| 810 | { |
||
| 811 | self::assertTrue($this->platform->supportsAlterTable()); |
||
| 812 | } |
||
| 813 | |||
| 814 | public function testSupportsTransactions() |
||
| 815 | { |
||
| 816 | self::assertTrue($this->platform->supportsTransactions()); |
||
| 817 | } |
||
| 818 | |||
| 819 | public function testSupportsSchemas() |
||
| 820 | { |
||
| 821 | self::assertFalse($this->platform->supportsSchemas()); |
||
| 822 | } |
||
| 823 | |||
| 824 | public function testSupportsIndexes() |
||
| 825 | { |
||
| 826 | self::assertTrue($this->platform->supportsIndexes()); |
||
| 827 | } |
||
| 828 | |||
| 829 | public function testSupportsCommentOnStatement() |
||
| 830 | { |
||
| 831 | self::assertTrue($this->platform->supportsCommentOnStatement()); |
||
| 832 | } |
||
| 833 | |||
| 834 | public function testSupportsSavePoints() |
||
| 835 | { |
||
| 836 | self::assertTrue($this->platform->supportsSavepoints()); |
||
| 837 | } |
||
| 838 | |||
| 839 | public function testSupportsReleasePoints() |
||
| 840 | { |
||
| 841 | self::assertTrue($this->platform->supportsReleaseSavepoints()); |
||
| 842 | } |
||
| 843 | |||
| 844 | public function testSupportsCreateDropDatabase() |
||
| 845 | { |
||
| 846 | self::assertTrue($this->platform->supportsCreateDropDatabase()); |
||
| 847 | } |
||
| 848 | |||
| 849 | public function testSupportsGettingAffectedRows() |
||
| 850 | { |
||
| 851 | self::assertTrue($this->platform->supportsGettingAffectedRows()); |
||
| 852 | } |
||
| 853 | |||
| 854 | public function testDoesNotSupportSequences() |
||
| 855 | { |
||
| 856 | self::markTestSkipped('This version of the platform now supports sequences.'); |
||
| 857 | } |
||
| 858 | |||
| 859 | public function testSupportsSequences() |
||
| 860 | { |
||
| 861 | self::assertTrue($this->platform->supportsSequences()); |
||
| 862 | } |
||
| 863 | |||
| 864 | public function testGeneratesSequenceSqlCommands() |
||
| 890 | ); |
||
| 891 | } |
||
| 892 | |||
| 893 | public function testDoesNotSupportInlineColumnComments() |
||
| 894 | { |
||
| 895 | self::assertFalse($this->platform->supportsInlineColumnComments()); |
||
| 896 | } |
||
| 897 | |||
| 898 | public function testCannotEmulateSchemas() |
||
| 899 | { |
||
| 900 | self::assertFalse($this->platform->canEmulateSchemas()); |
||
| 901 | } |
||
| 902 | |||
| 903 | public function testInitializesDoctrineTypeMappings() |
||
| 904 | { |
||
| 905 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('integer')); |
||
| 906 | self::assertSame('integer', $this->platform->getDoctrineTypeMapping('integer')); |
||
| 907 | |||
| 908 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('binary')); |
||
| 909 | self::assertSame('binary', $this->platform->getDoctrineTypeMapping('binary')); |
||
| 910 | |||
| 911 | self::assertTrue($this->platform->hasDoctrineTypeMappingFor('varbinary')); |
||
| 912 | self::assertSame('binary', $this->platform->getDoctrineTypeMapping('varbinary')); |
||
| 913 | } |
||
| 914 | |||
| 915 | protected function getBinaryDefaultLength() |
||
| 916 | { |
||
| 917 | return 1; |
||
| 918 | } |
||
| 919 | |||
| 920 | protected function getBinaryMaxLength() |
||
| 921 | { |
||
| 922 | return 32767; |
||
| 923 | } |
||
| 924 | |||
| 925 | public function testReturnsBinaryTypeDeclarationSQL() |
||
| 926 | { |
||
| 927 | self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([])); |
||
| 928 | self::assertSame('VARBINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 0])); |
||
| 929 | self::assertSame('VARBINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL(['length' => 32767])); |
||
| 930 | |||
| 931 | self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL(['fixed' => true])); |
||
| 932 | self::assertSame('BINARY(1)', $this->platform->getBinaryTypeDeclarationSQL([ |
||
| 933 | 'fixed' => true, |
||
| 934 | 'length' => 0, |
||
| 935 | ])); |
||
| 936 | self::assertSame('BINARY(32767)', $this->platform->getBinaryTypeDeclarationSQL([ |
||
| 937 | 'fixed' => true, |
||
| 938 | 'length' => 32767, |
||
| 939 | ])); |
||
| 940 | } |
||
| 941 | |||
| 942 | /** |
||
| 943 | * @group DBAL-234 |
||
| 944 | */ |
||
| 945 | protected function getAlterTableRenameIndexSQL() |
||
| 946 | { |
||
| 947 | return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_bar']; |
||
| 948 | } |
||
| 949 | |||
| 950 | /** |
||
| 951 | * @group DBAL-234 |
||
| 952 | */ |
||
| 953 | protected function getQuotedAlterTableRenameIndexSQL() |
||
| 954 | { |
||
| 955 | return [ |
||
| 956 | 'ALTER INDEX "create" ON "table" RENAME TO "select"', |
||
| 957 | 'ALTER INDEX "foo" ON "table" RENAME TO "bar"', |
||
| 958 | ]; |
||
| 959 | } |
||
| 960 | |||
| 961 | /** |
||
| 962 | * {@inheritdoc} |
||
| 963 | */ |
||
| 964 | protected function getQuotedAlterTableRenameColumnSQL() |
||
| 965 | { |
||
| 966 | return [ |
||
| 967 | 'ALTER TABLE mytable RENAME unquoted1 TO unquoted', |
||
| 968 | 'ALTER TABLE mytable RENAME unquoted2 TO "where"', |
||
| 969 | 'ALTER TABLE mytable RENAME unquoted3 TO "foo"', |
||
| 970 | 'ALTER TABLE mytable RENAME "create" TO reserved_keyword', |
||
| 971 | 'ALTER TABLE mytable RENAME "table" TO "from"', |
||
| 972 | 'ALTER TABLE mytable RENAME "select" TO "bar"', |
||
| 973 | 'ALTER TABLE mytable RENAME quoted1 TO quoted', |
||
| 974 | 'ALTER TABLE mytable RENAME quoted2 TO "and"', |
||
| 975 | 'ALTER TABLE mytable RENAME quoted3 TO "baz"', |
||
| 976 | ]; |
||
| 977 | } |
||
| 978 | |||
| 979 | /** |
||
| 980 | * {@inheritdoc} |
||
| 981 | */ |
||
| 982 | protected function getQuotedAlterTableChangeColumnLengthSQL() |
||
| 983 | { |
||
| 984 | $this->markTestIncomplete('Not implemented yet'); |
||
| 985 | } |
||
| 986 | |||
| 987 | /** |
||
| 988 | * @group DBAL-807 |
||
| 989 | */ |
||
| 990 | protected function getAlterTableRenameIndexInSchemaSQL() |
||
| 991 | { |
||
| 992 | return ['ALTER INDEX idx_foo ON myschema.mytable RENAME TO idx_bar']; |
||
| 993 | } |
||
| 994 | |||
| 995 | /** |
||
| 996 | * @group DBAL-807 |
||
| 997 | */ |
||
| 998 | protected function getQuotedAlterTableRenameIndexInSchemaSQL() |
||
| 999 | { |
||
| 1000 | return [ |
||
| 1001 | 'ALTER INDEX "create" ON "schema"."table" RENAME TO "select"', |
||
| 1002 | 'ALTER INDEX "foo" ON "schema"."table" RENAME TO "bar"', |
||
| 1003 | ]; |
||
| 1004 | } |
||
| 1005 | |||
| 1006 | /** |
||
| 1007 | * @group DBAL-423 |
||
| 1008 | */ |
||
| 1009 | public function testReturnsGuidTypeDeclarationSQL() |
||
| 1010 | { |
||
| 1011 | self::assertSame('UNIQUEIDENTIFIER', $this->platform->getGuidTypeDeclarationSQL([])); |
||
| 1012 | } |
||
| 1013 | |||
| 1014 | /** |
||
| 1015 | * {@inheritdoc} |
||
| 1016 | */ |
||
| 1017 | public function getAlterTableRenameColumnSQL() |
||
| 1018 | { |
||
| 1019 | return ['ALTER TABLE foo RENAME bar TO baz']; |
||
| 1020 | } |
||
| 1021 | |||
| 1022 | /** |
||
| 1023 | * {@inheritdoc} |
||
| 1024 | */ |
||
| 1025 | protected function getQuotesTableIdentifiersInAlterTableSQL() |
||
| 1026 | { |
||
| 1027 | return [ |
||
| 1028 | 'ALTER TABLE "foo" DROP FOREIGN KEY fk1', |
||
| 1029 | 'ALTER TABLE "foo" DROP FOREIGN KEY fk2', |
||
| 1030 | 'ALTER TABLE "foo" RENAME id TO war', |
||
| 1031 | 'ALTER TABLE "foo" ADD bloo INT NOT NULL, DROP baz, ALTER bar INT DEFAULT NULL', |
||
| 1032 | 'ALTER TABLE "foo" RENAME "table"', |
||
| 1033 | 'ALTER TABLE "table" ADD CONSTRAINT fk_add FOREIGN KEY (fk3) REFERENCES fk_table (id)', |
||
| 1034 | 'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)', |
||
| 1035 | ]; |
||
| 1036 | } |
||
| 1037 | |||
| 1038 | /** |
||
| 1039 | * {@inheritdoc} |
||
| 1040 | */ |
||
| 1041 | protected function getCommentOnColumnSQL() |
||
| 1042 | { |
||
| 1043 | return [ |
||
| 1044 | 'COMMENT ON COLUMN foo.bar IS \'comment\'', |
||
| 1045 | 'COMMENT ON COLUMN "Foo"."BAR" IS \'comment\'', |
||
| 1046 | 'COMMENT ON COLUMN "select"."from" IS \'comment\'', |
||
| 1047 | ]; |
||
| 1048 | } |
||
| 1049 | |||
| 1050 | /** |
||
| 1051 | * @group DBAL-1004 |
||
| 1052 | */ |
||
| 1053 | public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers() |
||
| 1054 | { |
||
| 1055 | $table1 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'))]); |
||
| 1056 | $table2 = new Table('"foo"', [new Column('"bar"', Type::getType('integer'), ['comment' => 'baz'])]); |
||
| 1057 | |||
| 1058 | $comparator = new Comparator(); |
||
| 1059 | |||
| 1060 | $tableDiff = $comparator->diffTable($table1, $table2); |
||
| 1061 | |||
| 1062 | self::assertInstanceOf(TableDiff::class, $tableDiff); |
||
| 1063 | self::assertSame( |
||
| 1064 | ['COMMENT ON COLUMN "foo"."bar" IS \'baz\''], |
||
| 1065 | $this->platform->getAlterTableSQL($tableDiff) |
||
|
|
|||
| 1066 | ); |
||
| 1067 | } |
||
| 1068 | |||
| 1069 | /** |
||
| 1070 | * {@inheritdoc} |
||
| 1071 | */ |
||
| 1072 | public function getReturnsForeignKeyReferentialActionSQL() |
||
| 1073 | { |
||
| 1074 | return [ |
||
| 1075 | ['CASCADE', 'CASCADE'], |
||
| 1076 | ['SET NULL', 'SET NULL'], |
||
| 1077 | ['NO ACTION', 'RESTRICT'], |
||
| 1078 | ['RESTRICT', 'RESTRICT'], |
||
| 1079 | ['SET DEFAULT', 'SET DEFAULT'], |
||
| 1080 | ['CaScAdE', 'CASCADE'], |
||
| 1081 | ]; |
||
| 1082 | } |
||
| 1083 | |||
| 1084 | /** |
||
| 1085 | * {@inheritdoc} |
||
| 1086 | */ |
||
| 1087 | protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL() |
||
| 1088 | { |
||
| 1089 | return 'CONSTRAINT "select" UNIQUE (foo)'; |
||
| 1090 | } |
||
| 1091 | |||
| 1092 | /** |
||
| 1093 | * {@inheritdoc} |
||
| 1094 | */ |
||
| 1095 | protected function getQuotesReservedKeywordInIndexDeclarationSQL() |
||
| 1096 | { |
||
| 1097 | return ''; // not supported by this platform |
||
| 1098 | } |
||
| 1099 | |||
| 1100 | /** |
||
| 1101 | * {@inheritdoc} |
||
| 1102 | */ |
||
| 1103 | protected function getQuotesReservedKeywordInTruncateTableSQL() |
||
| 1104 | { |
||
| 1105 | return 'TRUNCATE TABLE "select"'; |
||
| 1106 | } |
||
| 1107 | |||
| 1108 | /** |
||
| 1109 | * {@inheritdoc} |
||
| 1110 | */ |
||
| 1111 | protected function supportsInlineIndexDeclaration() |
||
| 1112 | { |
||
| 1113 | return false; |
||
| 1114 | } |
||
| 1115 | |||
| 1116 | /** |
||
| 1117 | * {@inheritdoc} |
||
| 1118 | */ |
||
| 1119 | protected function getAlterStringToFixedStringSQL() |
||
| 1120 | { |
||
| 1121 | return ['ALTER TABLE mytable ALTER name CHAR(2) NOT NULL']; |
||
| 1122 | } |
||
| 1123 | |||
| 1124 | /** |
||
| 1125 | * {@inheritdoc} |
||
| 1126 | */ |
||
| 1127 | protected function getGeneratesAlterTableRenameIndexUsedByForeignKeySQL() |
||
| 1128 | { |
||
| 1129 | return ['ALTER INDEX idx_foo ON mytable RENAME TO idx_foo_renamed']; |
||
| 1130 | } |
||
| 1131 | |||
| 1132 | /** |
||
| 1133 | * @group DBAL-2436 |
||
| 1134 | */ |
||
| 1135 | public function testQuotesSchemaNameInListTableColumnsSQL() |
||
| 1136 | { |
||
| 1137 | self::assertStringContainsStringIgnoringCase( |
||
| 1138 | "'Foo''Bar\\'", |
||
| 1139 | $this->platform->getListTableColumnsSQL("Foo'Bar\\.baz_table") |
||
| 1140 | ); |
||
| 1141 | } |
||
| 1142 | |||
| 1143 | /** |
||
| 1144 | * @group DBAL-2436 |
||
| 1145 | */ |
||
| 1146 | public function testQuotesTableNameInListTableConstraintsSQL() |
||
| 1147 | { |
||
| 1148 | self::assertStringContainsStringIgnoringCase("'Foo''Bar\\'", $this->platform->getListTableConstraintsSQL("Foo'Bar\\"), ''); |
||
| 1149 | } |
||
| 1150 | |||
| 1151 | /** |
||
| 1152 | * @group DBAL-2436 |
||
| 1153 | */ |
||
| 1154 | public function testQuotesSchemaNameInListTableConstraintsSQL() |
||
| 1155 | { |
||
| 1156 | self::assertStringContainsStringIgnoringCase( |
||
| 1157 | "'Foo''Bar\\'", |
||
| 1158 | $this->platform->getListTableConstraintsSQL("Foo'Bar\\.baz_table") |
||
| 1159 | ); |
||
| 1160 | } |
||
| 1161 | |||
| 1162 | /** |
||
| 1163 | * @group DBAL-2436 |
||
| 1164 | */ |
||
| 1165 | public function testQuotesTableNameInListTableForeignKeysSQL() |
||
| 1166 | { |
||
| 1167 | self::assertStringContainsStringIgnoringCase( |
||
| 1168 | "'Foo''Bar\\'", |
||
| 1169 | $this->platform->getListTableForeignKeysSQL("Foo'Bar\\") |
||
| 1170 | ); |
||
| 1171 | } |
||
| 1172 | |||
| 1173 | /** |
||
| 1174 | * @group DBAL-2436 |
||
| 1175 | */ |
||
| 1176 | public function testQuotesSchemaNameInListTableForeignKeysSQL() |
||
| 1177 | { |
||
| 1178 | self::assertStringContainsStringIgnoringCase( |
||
| 1179 | "'Foo''Bar\\'", |
||
| 1180 | $this->platform->getListTableForeignKeysSQL("Foo'Bar\\.baz_table") |
||
| 1181 | ); |
||
| 1182 | } |
||
| 1183 | |||
| 1184 | /** |
||
| 1185 | * @group DBAL-2436 |
||
| 1186 | */ |
||
| 1187 | public function testQuotesTableNameInListTableIndexesSQL() |
||
| 1192 | ); |
||
| 1193 | } |
||
| 1194 | |||
| 1195 | /** |
||
| 1196 | * @group DBAL-2436 |
||
| 1197 | */ |
||
| 1198 | public function testQuotesSchemaNameInListTableIndexesSQL() |
||
| 1199 | { |
||
| 1200 | self::assertStringContainsStringIgnoringCase( |
||
| 1201 | "'Foo''Bar\\'", |
||
| 1202 | $this->platform->getListTableIndexesSQL("Foo'Bar\\.baz_table") |
||
| 1203 | ); |
||
| 1204 | } |
||
| 1205 | } |
||
| 1206 |