Commit 7301a601 authored by Steve Müller's avatar Steve Müller

quote reserved keywords in TRUNCATE TABLE SQL

fixes #2270
parent ca4eea9f
...@@ -3412,7 +3412,9 @@ abstract class AbstractPlatform ...@@ -3412,7 +3412,9 @@ abstract class AbstractPlatform
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) 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 ...@@ -233,7 +233,9 @@ class DB2Platform extends AbstractPlatform
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
{ {
return 'TRUNCATE ' . $tableName . ' IMMEDIATE'; $tableIdentifier = new Identifier($tableName);
return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this) . ' IMMEDIATE';
} }
/** /**
......
...@@ -1082,7 +1082,9 @@ END;'; ...@@ -1082,7 +1082,9 @@ END;';
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) 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 ...@@ -1068,7 +1068,14 @@ class PostgreSqlPlatform extends AbstractPlatform
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) 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 ...@@ -1124,7 +1124,9 @@ class SQLAnywherePlatform extends AbstractPlatform
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
{ {
return 'TRUNCATE TABLE ' . $tableName; $tableIdentifier = new Identifier($tableName);
return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this);
} }
/** /**
......
...@@ -1490,7 +1490,9 @@ class SQLServerPlatform extends AbstractPlatform ...@@ -1490,7 +1490,9 @@ class SQLServerPlatform extends AbstractPlatform
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
{ {
return 'TRUNCATE TABLE '.$tableName; $tableIdentifier = new Identifier($tableName);
return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this);
} }
/** /**
......
...@@ -505,7 +505,8 @@ class SqlitePlatform extends AbstractPlatform ...@@ -505,7 +505,8 @@ class SqlitePlatform extends AbstractPlatform
*/ */
public function getTruncateTableSQL($tableName, $cascade = false) public function getTruncateTableSQL($tableName, $cascade = false)
{ {
$tableName = str_replace('.', '__', $tableName); $tableIdentifier = new Identifier($tableName);
$tableName = str_replace('.', '__', $tableIdentifier->getQuotedName($this));
return 'DELETE FROM ' . $tableName; return 'DELETE FROM ' . $tableName;
} }
......
...@@ -691,6 +691,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase ...@@ -691,6 +691,14 @@ abstract class AbstractMySQLPlatformTestCase extends AbstractPlatformTestCase
return 'INDEX `select` (foo)'; return 'INDEX `select` (foo)';
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE `select`';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -621,6 +621,22 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase ...@@ -621,6 +621,22 @@ abstract class AbstractPlatformTestCase extends \Doctrine\Tests\DbalTestCase
*/ */
abstract protected function getQuotesReservedKeywordInUniqueConstraintDeclarationSQL(); 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 * @group DBAL-1051
*/ */
......
...@@ -764,6 +764,14 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa ...@@ -764,6 +764,14 @@ abstract class AbstractPostgreSqlPlatformTestCase extends AbstractPlatformTestCa
return 'INDEX "select" (foo)'; return 'INDEX "select" (foo)';
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE "select"';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -1301,6 +1301,14 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas ...@@ -1301,6 +1301,14 @@ abstract class AbstractSQLServerPlatformTestCase extends AbstractPlatformTestCas
return 'INDEX [select] (foo)'; return 'INDEX [select] (foo)';
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE TABLE [select]';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -640,6 +640,14 @@ class DB2PlatformTest extends AbstractPlatformTestCase ...@@ -640,6 +640,14 @@ class DB2PlatformTest extends AbstractPlatformTestCase
return ''; // not supported by this platform return ''; // not supported by this platform
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE "select" IMMEDIATE';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -707,6 +707,14 @@ EOD; ...@@ -707,6 +707,14 @@ EOD;
return 'INDEX "select" (foo)'; return 'INDEX "select" (foo)';
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE TABLE "select"';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -960,6 +960,14 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase ...@@ -960,6 +960,14 @@ class SQLAnywherePlatformTest extends AbstractPlatformTestCase
return ''; // not supported by this platform return ''; // not supported by this platform
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE TABLE "select"';
}
/** /**
* {@inheritdoc} * {@inheritdoc}
*/ */
......
...@@ -637,6 +637,14 @@ class SqlitePlatformTest extends AbstractPlatformTestCase ...@@ -637,6 +637,14 @@ class SqlitePlatformTest extends AbstractPlatformTestCase
return 'INDEX "select" (foo)'; return 'INDEX "select" (foo)';
} }
/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'DELETE FROM "select"';
}
/** /**
* {@inheritdoc} * {@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