Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote the name of an index in the create table statement. #723

Merged
merged 2 commits into from
Jan 12, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1517,7 +1517,7 @@ public function getCreateTableSQL(Table $table, $createFlags = self::CREATE_INDE
$options['primary'] = $index->getQuotedColumns($this);
$options['primary_index'] = $index;
} else {
$options['indexes'][$index->getName()] = $index;
$options['indexes'][$index->getQuotedName($this)] = $index;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,13 @@ protected function getQuotedColumnInIndexSQL()
);
}

protected function getQuotedNameInIndexSQL()
{
return array(
'CREATE TABLE test (column1 VARCHAR(255) NOT NULL, INDEX `key` (column1)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB'
);
}

protected function getQuotedColumnInForeignKeySQL()
{
return array(
Expand Down
11 changes: 11 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,7 @@ public function testQuotedColumnInPrimaryKeyPropagation()

abstract protected function getQuotedColumnInPrimaryKeySQL();
abstract protected function getQuotedColumnInIndexSQL();
abstract protected function getQuotedNameInIndexSQL();
abstract protected function getQuotedColumnInForeignKeySQL();

/**
Expand All @@ -554,6 +555,16 @@ public function testQuotedColumnInIndexPropagation()
$this->assertEquals($this->getQuotedColumnInIndexSQL(), $sql);
}

public function testQuotedNameInIndexSQL()
{
$table = new Table('test');
$table->addColumn('column1', 'string');
$table->addIndex(array('column1'), '`key`');

$sql = $this->_platform->getCreateTableSQL($table);
$this->assertEquals($this->getQuotedNameInIndexSQL(), $sql);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to create an abstract protected getQuotedNameInIndexSQL() method in this class

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The method is declared in line 537. Or do I misinterpret your comment?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah sorry didn't see that line. Nevermind then.

}

/**
* @group DBAL-374
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,14 @@ protected function getQuotedColumnInIndexSQL()
);
}

protected function getQuotedNameInIndexSQL()
{
return array(
'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
'CREATE INDEX "key" ON test (column1)',
);
}

protected function getQuotedColumnInForeignKeySQL()
{
return array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -455,6 +455,14 @@ protected function getQuotedColumnInIndexSQL()
);
}

protected function getQuotedNameInIndexSQL()
{
return array(
'CREATE TABLE test (column1 NVARCHAR(255) NOT NULL)',
'CREATE INDEX [key] ON test (column1)',
);
}

protected function getQuotedColumnInForeignKeySQL()
{
return array(
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,14 @@ protected function getQuotedColumnInIndexSQL()
);
}

protected function getQuotedNameInIndexSQL()
{
return array(
'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
'CREATE INDEX "key" ON test (column1)',
);
}

protected function getQuotedColumnInPrimaryKeySQL()
{
return array(
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,14 @@ protected function getQuotedColumnInIndexSQL()
);
}

protected function getQuotedNameInIndexSQL()
{
return array(
'CREATE TABLE test (column1 VARCHAR2(255) NOT NULL)',
'CREATE INDEX "key" ON test (column1)',
);
}

protected function getQuotedColumnInForeignKeySQL()
{
return array(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,14 @@ protected function getQuotedColumnInIndexSQL()
);
}

protected function getQuotedNameInIndexSQL()
{
return array(
'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
'CREATE INDEX "key" ON test (column1)',
);
}

protected function getQuotedColumnInPrimaryKeySQL()
{
return array(
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,14 @@ protected function getQuotedColumnInIndexSQL()
);
}

protected function getQuotedNameInIndexSQL()
{
return array(
'CREATE TABLE test (column1 VARCHAR(255) NOT NULL)',
'CREATE INDEX "key" ON test (column1)',
);
}

protected function getQuotedColumnInForeignKeySQL()
{
return array(
Expand Down