Commit f1559554 authored by Benjamin Eberlei's avatar Benjamin Eberlei

Merge master into 2.2

parent 8cc129aa
......@@ -77,6 +77,14 @@ class Index extends AbstractAsset implements Constraint
return $this->_columns;
}
/**
* @return array
*/
public function getUnquotedColumns()
{
return array_map(array($this, 'trimQuotes'), $this->getColumns());
}
/**
* Is the index neither unique nor primary key?
*
......@@ -108,11 +116,11 @@ class Index extends AbstractAsset implements Constraint
* @param int $pos
* @return bool
*/
public function hasColumnAtPosition($columnName, $pos=0)
public function hasColumnAtPosition($columnName, $pos = 0)
{
$columnName = strtolower($columnName);
$indexColumns = \array_map('strtolower', $this->getColumns());
return \array_search($columnName, $indexColumns) === $pos;
$columnName = $this->trimQuotes(strtolower($columnName));
$indexColumns = array_map('strtolower', $this->getUnquotedColumns());
return array_search($columnName, $indexColumns) === $pos;
}
/**
......@@ -125,7 +133,7 @@ class Index extends AbstractAsset implements Constraint
{
$sameColumns = true;
for ($i = 0; $i < count($this->_columns); $i++) {
if (!isset($columnNames[$i]) || strtolower($this->_columns[$i]) != strtolower($columnNames[$i])) {
if (!isset($columnNames[$i]) || $this->trimQuotes(strtolower($this->_columns[$i])) != $this->trimQuotes(strtolower($columnNames[$i]))) {
$sameColumns = false;
}
}
......
......@@ -81,4 +81,19 @@ class IndexTest extends \PHPUnit_Framework_TestCase
$this->assertTrue($idx1->isFullfilledBy($pri));
$this->assertTrue($idx1->isFullfilledBy($uniq));
}
/**
* @group DBAL-285
*/
public function testIndexQuotes()
{
$index = new Index("foo", array("`bar`", "`baz`"));
$this->assertTrue($index->spansColumns(array("bar", "baz")));
$this->assertTrue($index->hasColumnAtPosition("bar", 0));
$this->assertTrue($index->hasColumnAtPosition("baz", 1));
$this->assertFalse($index->hasColumnAtPosition("bar", 1));
$this->assertFalse($index->hasColumnAtPosition("baz", 0));
}
}
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