diff --git a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php index 400b3213bf4..d06fd058040 100644 --- a/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/AbstractPlatform.php @@ -3412,7 +3412,9 @@ public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName) */ public function getTruncateTableSQL($tableName, $cascade = false) { - return 'TRUNCATE '.$tableName; + $tableIdentifier = new Identifier($tableName); + + return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this); } /** diff --git a/lib/Doctrine/DBAL/Platforms/DB2Platform.php b/lib/Doctrine/DBAL/Platforms/DB2Platform.php index b6ef11c1951..3febc662e6c 100644 --- a/lib/Doctrine/DBAL/Platforms/DB2Platform.php +++ b/lib/Doctrine/DBAL/Platforms/DB2Platform.php @@ -233,7 +233,9 @@ public function getTimeTypeDeclarationSQL(array $fieldDeclaration) */ public function getTruncateTableSQL($tableName, $cascade = false) { - return 'TRUNCATE ' . $tableName . ' IMMEDIATE'; + $tableIdentifier = new Identifier($tableName); + + return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this) . ' IMMEDIATE'; } /** diff --git a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php index 3a943c50f8a..9f900ec47a2 100644 --- a/lib/Doctrine/DBAL/Platforms/OraclePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/OraclePlatform.php @@ -1082,7 +1082,9 @@ public function supportsReleaseSavepoints() */ public function getTruncateTableSQL($tableName, $cascade = false) { - return 'TRUNCATE TABLE '.$tableName; + $tableIdentifier = new Identifier($tableName); + + return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this); } /** diff --git a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php index 8c8caa0a855..cc3d1883e70 100644 --- a/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php @@ -1068,7 +1068,14 @@ public function getEmptyIdentityInsertSQL($quotedTableName, $quotedIdentifierCol */ 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; } /** diff --git a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php index 36debc390e1..c57349d36ea 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php @@ -1124,7 +1124,9 @@ public function getTrimExpression($str, $pos = self::TRIM_UNSPECIFIED, $char = f */ public function getTruncateTableSQL($tableName, $cascade = false) { - return 'TRUNCATE TABLE ' . $tableName; + $tableIdentifier = new Identifier($tableName); + + return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this); } /** diff --git a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php index 2312efc5441..cb5f4baf5a2 100644 --- a/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php @@ -1490,7 +1490,9 @@ public function quoteSingleIdentifier($str) */ public function getTruncateTableSQL($tableName, $cascade = false) { - return 'TRUNCATE TABLE '.$tableName; + $tableIdentifier = new Identifier($tableName); + + return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this); } /** diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index 3d8a09b63ee..ba83974eb58 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -505,7 +505,8 @@ public function getName() */ public function getTruncateTableSQL($tableName, $cascade = false) { - $tableName = str_replace('.', '__', $tableName); + $tableIdentifier = new Identifier($tableName); + $tableName = str_replace('.', '__', $tableIdentifier->getQuotedName($this)); return 'DELETE FROM ' . $tableName; } diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php index 9622707c4f1..f4435666849 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractMySQLPlatformTestCase.php @@ -691,6 +691,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() return 'INDEX `select` (foo)'; } + /** + * {@inheritdoc} + */ + protected function getQuotesReservedKeywordInTruncateTableSQL() + { + return 'TRUNCATE `select`'; + } + /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php index f6d96797289..a1a56664ff5 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php @@ -621,6 +621,22 @@ public function testQuotesReservedKeywordInUniqueConstraintDeclarationSQL() */ 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 */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php index 17ee9e4bcf7..b653b80bc83 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractPostgreSqlPlatformTestCase.php @@ -764,6 +764,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() return 'INDEX "select" (foo)'; } + /** + * {@inheritdoc} + */ + protected function getQuotesReservedKeywordInTruncateTableSQL() + { + return 'TRUNCATE "select"'; + } + /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php index 01e1a853e59..a45f289880d 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/AbstractSQLServerPlatformTestCase.php @@ -1301,6 +1301,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() return 'INDEX [select] (foo)'; } + /** + * {@inheritdoc} + */ + protected function getQuotesReservedKeywordInTruncateTableSQL() + { + return 'TRUNCATE TABLE [select]'; + } + /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php index c0c8c8400db..55584091265 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php @@ -640,6 +640,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() return ''; // not supported by this platform } + /** + * {@inheritdoc} + */ + protected function getQuotesReservedKeywordInTruncateTableSQL() + { + return 'TRUNCATE "select" IMMEDIATE'; + } + /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php index 46fcb971da6..d8b8a780ad4 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php @@ -707,6 +707,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() return 'INDEX "select" (foo)'; } + /** + * {@inheritdoc} + */ + protected function getQuotesReservedKeywordInTruncateTableSQL() + { + return 'TRUNCATE TABLE "select"'; + } + /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php index 672fae00220..9ddd1b3ca30 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SQLAnywherePlatformTest.php @@ -960,6 +960,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() return ''; // not supported by this platform } + /** + * {@inheritdoc} + */ + protected function getQuotesReservedKeywordInTruncateTableSQL() + { + return 'TRUNCATE TABLE "select"'; + } + /** * {@inheritdoc} */ diff --git a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php index f0d00b42523..fc302240f81 100644 --- a/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php +++ b/tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php @@ -637,6 +637,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL() return 'INDEX "select" (foo)'; } + /** + * {@inheritdoc} + */ + protected function getQuotesReservedKeywordInTruncateTableSQL() + { + return 'DELETE FROM "select"'; + } + /** * {@inheritdoc} */