Merge pull request #671 from FabioBatSilva/DDC-2435
[DDC-2435] Fix column name with numbers and non alphanumeric characters.
This commit is contained in:
commit
c9d9b68fa9
@ -127,12 +127,15 @@ class DefaultQuoteStrategy implements QuoteStrategy
|
|||||||
*/
|
*/
|
||||||
public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null)
|
public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null)
|
||||||
{
|
{
|
||||||
// Trim the column alias to the maximum identifier length of the platform.
|
// 1 ) Concatenate column name and counter
|
||||||
// If the alias is to long, characters are cut off from the beginning.
|
// 2 ) Trim the column alias to the maximum identifier length of the platform.
|
||||||
// And strip non alphanumeric characters
|
// If the alias is to long, characters are cut off from the beginning.
|
||||||
|
// 3 ) Strip non alphanumeric characters
|
||||||
|
// 4 ) Prefix with "_" if the result its numeric
|
||||||
$columnName = $columnName . $counter;
|
$columnName = $columnName . $counter;
|
||||||
$columnName = substr($columnName, -$platform->getMaxIdentifierLength());
|
$columnName = substr($columnName, -$platform->getMaxIdentifierLength());
|
||||||
$columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName);
|
$columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName);
|
||||||
|
$columnName = is_numeric($columnName) ? '_' . $columnName : $columnName;
|
||||||
|
|
||||||
return $platform->getSQLResultCasing($columnName);
|
return $platform->getSQLResultCasing($columnName);
|
||||||
}
|
}
|
||||||
|
31
tests/Doctrine/Tests/Models/Quote/NumericEntity.php
Normal file
31
tests/Doctrine/Tests/Models/Quote/NumericEntity.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Doctrine\Tests\Models\Quote;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Entity
|
||||||
|
* @Table(name="table")
|
||||||
|
*/
|
||||||
|
class NumericEntity
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* @Id
|
||||||
|
* @Column(type="integer", name="`1:1`")
|
||||||
|
* @GeneratedValue(strategy="AUTO")
|
||||||
|
*/
|
||||||
|
public $id;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @Column(type="string", name="`2:2`")
|
||||||
|
*/
|
||||||
|
public $value;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $value
|
||||||
|
*/
|
||||||
|
public function __construct($value)
|
||||||
|
{
|
||||||
|
$this->value = $value;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -1810,6 +1810,27 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @group DDC-2435
|
||||||
|
*/
|
||||||
|
public function testColumnNameWithNumbersAndNonAlphanumericCharacters()
|
||||||
|
{
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT e FROM Doctrine\Tests\Models\Quote\NumericEntity e',
|
||||||
|
'SELECT t0_."1:1" AS _110, t0_."2:2" AS _221 FROM table t0_'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT e.value FROM Doctrine\Tests\Models\Quote\NumericEntity e',
|
||||||
|
'SELECT t0_."2:2" AS _220 FROM table t0_'
|
||||||
|
);
|
||||||
|
|
||||||
|
$this->assertSqlGeneration(
|
||||||
|
'SELECT TRIM(e.value) FROM Doctrine\Tests\Models\Quote\NumericEntity e',
|
||||||
|
'SELECT TRIM(t0_."2:2") AS sclr0 FROM table t0_'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @group DDC-1845
|
* @group DDC-1845
|
||||||
*/
|
*/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user