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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Original file line number Diff line number Diff line change
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
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 @@ -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
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 @@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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
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 @@ -764,6 +764,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 @@ -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
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 @@ -707,6 +707,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 @@ -637,6 +637,14 @@ protected function getQuotesReservedKeywordInIndexDeclarationSQL()
return 'INDEX "select" (foo)';
}

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

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