Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Quote reserved keywords in TRUNCATE TABLE SQL #2275

Merged
merged 1 commit into from Jan 12, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Expand Up @@ -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);
}

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

/**
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 @@ -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);
}

/**
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 @@ -691,6 +691,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 @@ -764,6 +764,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX "select" (foo)';
}

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

/**
* {@inheritdoc}
*/
Expand Down
Expand Up @@ -1301,6 +1301,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 @@ -707,6 +707,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 @@ -637,6 +637,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX "select" (foo)';
}

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

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