Commit 6460e4aa authored by Steve Müller's avatar Steve Müller

quote table and constraint names in drop foreign key / drop constraint SQL

parent a9e08c8c
......@@ -1450,14 +1450,17 @@ abstract class AbstractPlatform
*/
public function getDropConstraintSQL($constraint, $table)
{
if ($constraint instanceof Constraint) {
$constraint = $constraint->getQuotedName($this);
if (! $constraint instanceof Constraint) {
$constraint = new Identifier($constraint);
}
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
if (! $table instanceof Table) {
$table = new Identifier($table);
}
$constraint = $constraint->getQuotedName($this);
$table = $table->getQuotedName($this);
return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $constraint;
}
......@@ -1471,14 +1474,17 @@ abstract class AbstractPlatform
*/
public function getDropForeignKeySQL($foreignKey, $table)
{
if ($foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = $foreignKey->getQuotedName($this);
if (! $foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = new Identifier($foreignKey);
}
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
if (! $table instanceof Table) {
$table = new Identifier($table);
}
$foreignKey = $foreignKey->getQuotedName($this);
$table = $table->getQuotedName($this);
return 'ALTER TABLE ' . $table . ' DROP FOREIGN KEY ' . $foreignKey;
}
......
......@@ -663,14 +663,17 @@ LEFT JOIN user_cons_columns r_cols
*/
public function getDropForeignKeySQL($foreignKey, $table)
{
if ($foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = $foreignKey->getQuotedName($this);
if (! $foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = new Identifier($foreignKey);
}
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
if (! $table instanceof Table) {
$table = new Identifier($table);
}
$foreignKey = $foreignKey->getQuotedName($this);
$table = $table->getQuotedName($this);
return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $foreignKey;
}
......
......@@ -160,14 +160,17 @@ class SQLServerPlatform extends AbstractPlatform
*/
public function getDropForeignKeySQL($foreignKey, $table)
{
if ($foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = $foreignKey->getQuotedName($this);
if (! $foreignKey instanceof ForeignKeyConstraint) {
$foreignKey = new Identifier($foreignKey);
}
if ($table instanceof Table) {
$table = $table->getQuotedName($this);
if (! $table instanceof Table) {
$table = new Identifier($table);
}
$foreignKey = $foreignKey->getQuotedName($this);
$table = $table->getQuotedName($this);
return 'ALTER TABLE ' . $table . ' DROP CONSTRAINT ' . $foreignKey;
}
......
......@@ -571,6 +571,16 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
);
}
protected function getQuotesDropForeignKeySQL()
{
return 'ALTER TABLE `table` DROP FOREIGN KEY `select`';
}
protected function getQuotesDropConstraintSQL()
{
return 'ALTER TABLE `table` DROP CONSTRAINT `select`';
}
public function testDoesNotPropagateDefaultValuesForUnsupportedColumnTypes()
{
$table = new Table("text_blob_default_value");
......
......@@ -967,6 +967,52 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
);
}
/**
* @group DBAL-1237
*/
public function testQuotesDropForeignKeySQL()
{
if (! $this->_platform->supportsForeignKeyConstraints()) {
$this->markTestSkipped(
sprintf('%s does not support foreign key constraints.', get_class($this->_platform))
);
}
$tableName = 'table';
$table = new Table($tableName);
$foreignKeyName = 'select';
$foreignKey = new ForeignKeyConstraint(array(), 'foo', array(), 'select');
$expectedSql = $this->getQuotesDropForeignKeySQL();
$this->assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKeyName, $tableName));
$this->assertSame($expectedSql, $this->_platform->getDropForeignKeySQL($foreignKey, $table));
}
protected function getQuotesDropForeignKeySQL()
{
return 'ALTER TABLE "table" DROP FOREIGN KEY "select"';
}
/**
* @group DBAL-1237
*/
public function testQuotesDropConstraintSQL()
{
$tableName = 'table';
$table = new Table($tableName);
$constraintName = 'select';
$constraint = new ForeignKeyConstraint(array(), 'foo', array(), 'select');
$expectedSql = $this->getQuotesDropConstraintSQL();
$this->assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraintName, $tableName));
$this->assertSame($expectedSql, $this->_platform->getDropConstraintSQL($constraint, $table));
}
protected function getQuotesDropConstraintSQL()
{
return 'ALTER TABLE "table" DROP CONSTRAINT "select"';
}
protected function getStringLiteralQuoteCharacter()
{
return "'";
......
......@@ -669,6 +669,11 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
);
}
protected function getQuotesDropForeignKeySQL()
{
return 'ALTER TABLE "table" DROP CONSTRAINT "select"';
}
public function testGetNullCommentOnColumnSQL()
{
$this->assertEquals(
......
......@@ -1035,6 +1035,16 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
);
}
protected function getQuotesDropForeignKeySQL()
{
return 'ALTER TABLE [table] DROP CONSTRAINT [select]';
}
protected function getQuotesDropConstraintSQL()
{
return 'ALTER TABLE [table] DROP CONSTRAINT [select]';
}
/**
* @dataProvider getGeneratesIdentifierNamesInDefaultConstraintDeclarationSQL
* @group DBAL-830
......
......@@ -545,6 +545,11 @@ class OraclePlatformTest extends AbstractPlatformTestCase
);
}
protected function getQuotesDropForeignKeySQL()
{
return 'ALTER TABLE "table" DROP CONSTRAINT "select"';
}
/**
* @group DBAL-423
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment