Skip to content

Commit

Permalink
[DBAL-298] Fix foreign table names not being quoted correctly.
Browse files Browse the repository at this point in the history
  • Loading branch information
beberlei committed Jul 29, 2012
1 parent c52a863 commit 311bda5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/Doctrine/DBAL/Platforms/AbstractPlatform.php
Expand Up @@ -2004,7 +2004,7 @@ public function getForeignKeyBaseDeclarationSQL(ForeignKeyConstraint $foreignKey

$sql .= implode(', ', $foreignKey->getLocalColumns())
. ') REFERENCES '
. $foreignKey->getForeignTableName() . ' ('
. $foreignKey->getQuotedForeignTableName($this) . ' ('
. implode(', ', $foreignKey->getForeignColumns()) . ')';

return $sql;
Expand Down
19 changes: 19 additions & 0 deletions lib/Doctrine/DBAL/Schema/ForeignKeyConstraint.php
Expand Up @@ -22,6 +22,7 @@
namespace Doctrine\DBAL\Schema;

use Doctrine\DBAL\Schema\Visitor\Visitor;
use Doctrine\DBAL\Platforms\AbstractPlatform;

class ForeignKeyConstraint extends AbstractAsset implements Constraint
{
Expand Down Expand Up @@ -109,6 +110,24 @@ public function getForeignTableName()
return $this->_foreignTableName;
}

/**
* Get the quoted representation of this asset but only if it was defined with one. Otherwise
* return the plain unquoted value as inserted.
*
* @param AbstractPlatform $platform
* @return string
*/
public function getQuotedForeignTableName(AbstractPlatform $platform)
{
$keywords = $platform->getReservedKeywordsList();
$parts = explode(".", $this->getForeignTableName());
foreach ($parts AS $k => $v) {
$parts[$k] = ($this->_quoted || $keywords->isKeyword($v)) ? $platform->quoteIdentifier($v) : $v;
}

return implode(".", $parts);
}

/**
* @return array
*/
Expand Down

0 comments on commit 311bda5

Please sign in to comment.