diff --git a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php index 3f5b0c853..70359de33 100644 --- a/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php +++ b/lib/Doctrine/ORM/Mapping/DefaultQuoteStrategy.php @@ -127,12 +127,15 @@ class DefaultQuoteStrategy implements QuoteStrategy */ public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null) { - // Trim the column alias to the maximum identifier length of the platform. - // If the alias is to long, characters are cut off from the beginning. - // And strip non alphanumeric characters + // 1 ) Concatenate column name and counter + // 2 ) Trim the column alias to the maximum identifier length of the platform. + // 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 = substr($columnName, -$platform->getMaxIdentifierLength()); $columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName); + $columnName = is_numeric($columnName) ? '_' . $columnName : $columnName; return $platform->getSQLResultCasing($columnName); } diff --git a/tests/Doctrine/Tests/Models/Quote/NumericEntity.php b/tests/Doctrine/Tests/Models/Quote/NumericEntity.php new file mode 100644 index 000000000..f1186cbcc --- /dev/null +++ b/tests/Doctrine/Tests/Models/Quote/NumericEntity.php @@ -0,0 +1,31 @@ +value = $value; + } + +} \ No newline at end of file diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 747df24bb..d15f78d48 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -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 */