Skip to content

Commit

Permalink
Merge pull request #2275 from deeky666/DBAL-2270
Browse files Browse the repository at this point in the history
Quote reserved keywords in TRUNCATE TABLE SQL
  • Loading branch information
Bill Schaller committed Jan 12, 2016
2 parents c752fc0 + 7301a60 commit 5f0dfd2
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
Original file line number Diff line number Diff line change
Expand Up @@ -3436,7 +3436,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
Original file line number Diff line number Diff line change
Expand Up @@ -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';
}

/**
Expand Down
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Platforms/OraclePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1085,7 +1085,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -769,6 +769,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX "select" (foo)';
}

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

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -712,6 +712,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX "select" (foo)';
}

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

/**
* {@inheritdoc}
*/
Expand Down
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
Expand Up @@ -673,6 +673,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX "select" (foo)';
}

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

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

0 comments on commit 5f0dfd2

Please sign in to comment.