Commit 5f0dfd29 authored by Bill Schaller's avatar Bill Schaller

Merge pull request #2275 from deeky666/DBAL-2270

Quote reserved keywords in TRUNCATE TABLE SQL
parents c752fc01 7301a601
......@@ -3436,7 +3436,9 @@ abstract class AbstractPlatform
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE '.$tableName;
$tableIdentifier = new Identifier($tableName);
return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this);
}
/**
......
......@@ -233,7 +233,9 @@ class DB2Platform extends AbstractPlatform
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE ' . $tableName . ' IMMEDIATE';
$tableIdentifier = new Identifier($tableName);
return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this) . ' IMMEDIATE';
}
/**
......
......@@ -1085,7 +1085,9 @@ END;';
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE TABLE '.$tableName;
$tableIdentifier = new Identifier($tableName);
return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this);
}
/**
......
......@@ -1068,7 +1068,14 @@ class PostgreSqlPlatform extends AbstractPlatform
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE '.$tableName.' '.(($cascade)?'CASCADE':'');
$tableIdentifier = new Identifier($tableName);
$sql = 'TRUNCATE ' . $tableIdentifier->getQuotedName($this);
if ($cascade) {
$sql .= ' CASCADE';
}
return $sql;
}
/**
......
......@@ -1124,7 +1124,9 @@ class SQLAnywherePlatform extends AbstractPlatform
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE TABLE ' . $tableName;
$tableIdentifier = new Identifier($tableName);
return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this);
}
/**
......
......@@ -1493,7 +1493,9 @@ class SQLServerPlatform extends AbstractPlatform
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE TABLE '.$tableName;
$tableIdentifier = new Identifier($tableName);
return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this);
}
/**
......
......@@ -513,7 +513,8 @@ class SqlitePlatform extends AbstractPlatform
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
$tableName = str_replace('.', '__', $tableName);
$tableIdentifier = new Identifier($tableName);
$tableName = str_replace('.', '__', $tableIdentifier->getQuotedName($this));
return 'DELETE FROM ' . $tableName;
}
......
......@@ -701,6 +701,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
return 'INDEX `select` (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE `select`';
}
/**
* {@inheritdoc}
*/
......
......@@ -621,6 +621,22 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
*/
abstract protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL();
/**
* @group DBAL-2270
*/
public function testQuotesReservedKeywordInTruncateTableSQL()
{
$this->assertSame(
$this->getQuotesReservedKeywordInTruncateTableSQL(),
$this->_platform->getTruncateTableSQL('select')
);
}
/**
* @return string
*/
abstract protected function getQuotesReservedKeywordInTruncateTableSQL();
/**
* @group DBAL-1051
*/
......
......@@ -769,6 +769,14 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
return 'INDEX "select" (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE "select"';
}
/**
* {@inheritdoc}
*/
......
......@@ -1311,6 +1311,14 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
return 'INDEX [select] (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE TABLE [select]';
}
/**
* {@inheritdoc}
*/
......
......@@ -640,6 +640,14 @@ class DB2PlatformTest extends AbstractPlatformTestCase
return ''; // not supported by this platform
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE "select" IMMEDIATE';
}
/**
* {@inheritdoc}
*/
......
......@@ -712,6 +712,14 @@ EOD;
return 'INDEX "select" (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE TABLE "select"';
}
/**
* {@inheritdoc}
*/
......
......@@ -960,6 +960,14 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
return ''; // not supported by this platform
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE TABLE "select"';
}
/**
* {@inheritdoc}
*/
......
......@@ -673,6 +673,14 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
return 'INDEX "select" (foo)';
}
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'DELETE FROM "select"';
}
/**
* {@inheritdoc}
*/
......
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