Commit 7710d546 authored by Steve Müller's avatar Steve Müller

fix foreign key referential action SQL on SQL Server and SQL Anywhere

parent 57a2b0c3
......@@ -645,17 +645,12 @@ class SQLAnywherePlatform extends AbstractPlatform
*/
public function getForeignKeyReferentialActionSQL($action)
{
$action = strtoupper($action);
switch ($action) {
case 'CASCADE':
case 'SET NULL':
case 'SET DEFAULT':
case 'RESTRICT':
return $action;
default:
throw new \InvalidArgumentException('Invalid foreign key action: ' . $action);
// NO ACTION is not supported, therefore falling back to RESTRICT.
if (strtoupper($action) === 'NO ACTION') {
return 'RESTRICT';
}
return parent::getForeignKeyReferentialActionSQL($action);
}
/**
......
......@@ -1393,6 +1393,19 @@ class SQLServerPlatform extends AbstractPlatform
return 'ROLLBACK TRANSACTION ' . $savepoint;
}
/**
* {@inheritdoc}
*/
public function getForeignKeyReferentialActionSQL($action)
{
// RESTRICT is not supported, therefore falling back to NO ACTION.
if (strtoupper($action) === 'RESTRICT') {
return 'NO ACTION';
}
return parent::getForeignKeyReferentialActionSQL($action);
}
/**
* {@inheritDoc}
*/
......
......@@ -58,6 +58,31 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
$this->assertEquals(str_repeat($c, 4), $this->_platform->quoteSingleIdentifier($c));
}
/**
* @group DBAL-1029
*
* @dataProvider getReturnsForeignKeyReferentialActionSQL
*/
public function testReturnsForeignKeyReferentialActionSQL($action, $expectedSQL)
{
$this->assertSame($expectedSQL, $this->_platform->getForeignKeyReferentialActionSQL($action));
}
/**
* @return array
*/
public function getReturnsForeignKeyReferentialActionSQL()
{
return array(
array('CASCADE', 'CASCADE'),
array('SET NULL', 'SET NULL'),
array('NO ACTION', 'NO ACTION'),
array('RESTRICT', 'RESTRICT'),
array('SET DEFAULT', 'SET DEFAULT'),
array('CaScAdE', 'CASCADE'),
);
}
public function testGetInvalidtForeignKeyReferentialActionSQL()
{
$this->setExpectedException('InvalidArgumentException');
......
......@@ -1159,4 +1159,31 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
'ALTER TABLE [table] ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
);
}
/**
* {@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'",
);
}
/**
* {@inheritdoc}
*/
public function getReturnsForeignKeyReferentialActionSQL()
{
return array(
array('CASCADE', 'CASCADE'),
array('SET NULL', 'SET NULL'),
array('NO ACTION', 'NO ACTION'),
array('RESTRICT', 'NO ACTION'),
array('SET DEFAULT', 'SET DEFAULT'),
array('CaScAdE', 'CASCADE'),
);
}
}
......@@ -8,6 +8,7 @@ use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Platforms\SQLAnywherePlatform;
use Doctrine\DBAL\Schema\Column;
use Doctrine\DBAL\Schema\ColumnDiff;
use Doctrine\DBAL\Schema\Comparator;
use Doctrine\DBAL\Schema\ForeignKeyConstraint;
use Doctrine\DBAL\Schema\Index;
use Doctrine\DBAL\Schema\Table;
......@@ -889,4 +890,52 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
'ALTER TABLE "table" ADD CONSTRAINT fk2 FOREIGN KEY (fk2) REFERENCES fk_table2 (id)',
);
}
/**
* {@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\'',
);
}
/**
* @group DBAL-1004
*/
public function testAltersTableColumnCommentWithExplicitlyQuotedIdentifiers()
{
$table1 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'))));
$table2 = new Table('"foo"', array(new Column('"bar"', Type::getType('integer'), array('comment' => 'baz'))));
$comparator = new Comparator();
$tableDiff = $comparator->diffTable($table1, $table2);
$this->assertInstanceOf('Doctrine\DBAL\Schema\TableDiff', $tableDiff);
$this->assertSame(
array(
'COMMENT ON COLUMN "foo"."bar" IS \'baz\'',
),
$this->_platform->getAlterTableSQL($tableDiff)
);
}
/**
* {@inheritdoc}
*/
public function getReturnsForeignKeyReferentialActionSQL()
{
return array(
array('CASCADE', 'CASCADE'),
array('SET NULL', 'SET NULL'),
array('NO ACTION', 'RESTRICT'),
array('RESTRICT', 'RESTRICT'),
array('SET DEFAULT', 'SET DEFAULT'),
array('CaScAdE', 'CASCADE'),
);
}
}
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