Commit c6887c12 authored by Marco Pivetta's avatar Marco Pivetta

Merge pull request #710 from deeky666/DBAL-1029

[DBAL-1029] Fix foreign key referential action SQL on SQL Server and SQL Anywhere
parents a141ab08 0e91465e
......@@ -652,17 +652,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');
......
......@@ -1171,4 +1171,19 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
"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'),
);
}
}
......@@ -411,12 +411,6 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
$this->_platform->getForeignKeyMatchCLauseSQL(3);
}
public function testCannotGenerateNoActionForeignKeyReferentialActionClauseSQL()
{
$this->setExpectedException('\InvalidArgumentException');
$this->_platform->getForeignKeyReferentialActionSQL('no action');
}
public function testCannotGenerateForeignKeyConstraintSQLWithEmptyLocalColumns()
{
$this->setExpectedException('\InvalidArgumentException');
......@@ -923,4 +917,19 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
$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