New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DDC-2435] Fix column name with numbers and non alphanumeric characters. #671

Merged
merged 1 commit into from May 17, 2013
Jump to file or symbol
Failed to load files and symbols.
+58 −3
Diff settings

Always

Just for now

@@ -127,12 +127,15 @@ function ($joinColumn) use ($platform)
*/
public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null)

This comment has been minimized.

@beberlei

beberlei May 17, 2013

Member

Wondering if we should ship an AnsiQuoteStrategy that just assumes every column is ANSI compliant and only does return $platform->getSQLResultCashing($columnName . $counter);

@beberlei

beberlei May 17, 2013

Member

Wondering if we should ship an AnsiQuoteStrategy that just assumes every column is ANSI compliant and only does return $platform->getSQLResultCashing($columnName . $counter);

This comment has been minimized.

@FabioBatSilva

FabioBatSilva May 17, 2013

Member

Sounds good.

I've created an issue : DDC-2459

@FabioBatSilva

FabioBatSilva May 17, 2013

Member

Sounds good.

I've created an issue : DDC-2459

{
// 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);
}
@@ -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 @@ public function testStripNonAlphanumericCharactersFromAlias()
);
}
/**
* @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
*/
ProTip! Use n and p to navigate between commits in a pull request.