Skip to content

Commit

Permalink
quote reserved keywords in TRUNCATE TABLE SQL
Browse files Browse the repository at this point in the history
fixes #2270
  • Loading branch information
deeky666 committed Jan 12, 2016
1 parent 9567eaa commit 8019435
Show file tree
Hide file tree
Showing 15 changed files with 97 additions and 7 deletions.
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Expand Up @@ -3418,7 +3418,9 @@ public function getEmptyIdentityInsertSQL($tableName, $identifierColumnName)
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE '.$tableName;
$tableIdentifier = new Identifier($tableName);

return 'TRUNCATE ' . $tableIdentifier->getQuotedName($this);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Platforms/DB2Platform.php
Expand Up @@ -234,7 +234,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';
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Expand Up @@ -1057,7 +1057,9 @@ public function supportsReleaseSavepoints()
*/
public function getTruncateTableSQL($tableName, $cascade = false)
{
return 'TRUNCATE TABLE '.$tableName;
$tableIdentifier = new Identifier($tableName);

return 'TRUNCATE TABLE ' . $tableIdentifier->getQuotedName($this);
}

/**
Expand Down
9 changes: 8 additions & 1 deletion lib/Doctrine/DBAL/Platforms/PostgreSqlPlatform.php
Expand Up @@ -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;
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Platforms/SQLAnywherePlatform.php
Expand Up @@ -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);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Expand Up @@ -1493,7 +1493,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);
}

/**
Expand Down
3 changes: 2 additions & 1 deletion lib/Doctrine/DBAL/Platforms/SqlitePlatform.php
Expand Up @@ -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;
}
Expand Down
Expand Up @@ -701,6 +701,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX `select` (foo)';
}

/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE `select`';
}

/**
* {@inheritdoc}
*/
Expand Down
16 changes: 16 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/AbstractPlatformTestCase.php
Expand Up @@ -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
*/
Expand Down
Expand Up @@ -769,6 +769,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX "select" (foo)';
}

/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE "select"';
}

/**
* {@inheritdoc}
*/
Expand Down
Expand Up @@ -1311,6 +1311,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX [select] (foo)';
}

/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE TABLE [select]';
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/DB2PlatformTest.php
Expand Up @@ -640,6 +640,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return ''; // not supported by this platform
}

/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE "select" IMMEDIATE';
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/OraclePlatformTest.php
Expand Up @@ -714,6 +714,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX "select" (foo)';
}

/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE TABLE "select"';
}

/**
* {@inheritdoc}
*/
Expand Down
Expand Up @@ -960,6 +960,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return ''; // not supported by this platform
}

/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'TRUNCATE TABLE "select"';
}

/**
* {@inheritdoc}
*/
Expand Down
8 changes: 8 additions & 0 deletions tests/Doctrine/Tests/DBAL/Platforms/SqlitePlatformTest.php
Expand Up @@ -639,6 +639,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX "select" (foo)';
}

/**
* {@inheritdoc}
*/
protected function getQuotesReservedKeywordInTruncateTableSQL()
{
return 'DELETE FROM "select"';
}

/**
* {@inheritdoc}
*/
Expand Down

0 comments on commit 8019435

Please sign in to comment.