Commit 46271a9a authored by Steve Müller's avatar Steve Müller

adjust Index asset to be able to return quoted column names

parent f042fd8b
......@@ -19,12 +19,15 @@
namespace Doctrine\DBAL\Schema;
use Doctrine\DBAL\Schema\Visitor\Visitor;
use Doctrine\DBAL\Platforms\AbstractPlatform;
class Index extends AbstractAsset implements Constraint
{
/**
* @var array
* Asset identifier instances of the column names the index is associated with.
* array($columnName => Identifier)
*
* @var Identifier[]
*/
protected $_columns;
......@@ -73,7 +76,7 @@ class Index extends AbstractAsset implements Constraint
protected function _addColumn($column)
{
if(is_string($column)) {
$this->_columns[] = $column;
$this->_columns[$column] = new Identifier($column);
} else {
throw new \InvalidArgumentException("Expecting a string as Index Column");
}
......@@ -84,7 +87,30 @@ class Index extends AbstractAsset implements Constraint
*/
public function getColumns()
{
return $this->_columns;
return array_keys($this->_columns);
}
/**
* Returns the quoted representation of the column names
* the index is associated with.
*
* But only if they were defined with one or the column name
* is a keyword reserved by the platform.
* Otherwise the plain unquoted value as inserted is returned.
*
* @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform The platform to use for quotation.
*
* @return array
*/
public function getQuotedColumns(AbstractPlatform $platform)
{
$columns = array();
foreach ($this->_columns as $column) {
$columns[] = $column->getQuotedName($platform);
}
return $columns;
}
/**
......@@ -141,9 +167,11 @@ class Index extends AbstractAsset implements Constraint
*/
public function spansColumns(array $columnNames)
{
$columns = $this->getColumns();
$numberOfColumns = count($columns);
$sameColumns = true;
for ($i = 0; $i < count($this->_columns); $i++) {
if (!isset($columnNames[$i]) || $this->trimQuotes(strtolower($this->_columns[$i])) != $this->trimQuotes(strtolower($columnNames[$i]))) {
for ($i = 0; $i < $numberOfColumns; $i++) {
if (!isset($columnNames[$i]) || $this->trimQuotes(strtolower($columns[$i])) != $this->trimQuotes(strtolower($columnNames[$i]))) {
$sameColumns = false;
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment