Jira issue originally created by user phackwer:
There's a bug on the DefaultQuoteStrategy when used with Oracle. The getColumnAlias created an invalid alias.
The name of the column had 31 chars, with * being the 3rd. Column was 101 on the query. Resulting name of the alias started with *, which is invalid name for Oracle.
Alias formed was
HOW TO FIX:
replace the regex on line 135:
$columnName = pregreplace('/[A-Za-z0-9]/', '', $columnName);
$columnName = preg_replace('/[A-Za-z0-9]/', '', $columnName);
Comment created by rudi.neto:
I would like to do a contribuition for this issue! I'm not safe with my sugestion, but someone can be helped!
I'm working with 2.4.0 Doctrine Version and I'm facing the same problem, "invalid character" due the function that make a cut off from the begining from alias.
My sugestion to solve this problem is maintain the separator '_' between alias name, but cutting off from the ending alias and reserv the lenght to the counter.
See bellow my modification code at DefaultQuoteStrategy::getColumnAlias() line 130, just replace all lines from function by these below:
public function getColumnAlias($columnName, $counter, AbstractPlatform $platform, ClassMetadata $class = null)
// 1 ) Trim the column alias to the maximum identifier length of the platform.
// If the alias is to long, characters are cut off from the ending subtracting the chars reserved to counter.
// 2 ) Concatenate column name and counter
// 3 ) Strip non alphanumeric characters
// 4 ) Prefix with "_" if the result its numeric
$columnName = substr($columnName, 0, $platform->getMaxIdentifierLength() - strlen($counter));
$columnName = $columnName . $counter;
$columnName = preg*replace('/[^A-Za-z0-9*]/', '', $columnName);
$columnName = is*numeric($columnName) ? '*' . $columnName : $columnName;
What do you guys think?
Comment created by phackwer:
Rudi, prefixing it with * would keep the problem on Oracle. Since that name is for aliasing pourposes only, the * char is useless.
I just remembered another possible situation: fields should not start with numbers!
The changes in my sugestion code don't consider the prefix '', indepedent of the characteres in alias column name, the function will remove the last characteres from alias... see an example with column name DT_VERIFICACAO_SITUACAOACESSO.
The current code create a sql:
DTVERIFICACAO_SITUACAO_ACESSO AS _VERIFICACAO_SITUACAOACESSO23,
My sugestion will produce:
DTVERIFICACAO_SITUACAO_ACESSO AS DT_VERIFICACAO_SITUACAOACES23,
Oh, sorry, my mistake. Your solution sounds better.
Since there's still no solution from the Doctrine Team, I'm iusing my own QuoteStrategy. Hope this bug gets fixed soon.
Comment created by @beberlei:
[fabio.bat.silva] Can you comment on [rudi.neto] solution? Its easily changed, but I am wondering if this is backwards compatible. I would want to merge the fix back to 2.3 and 2.4. Branch is ready to be committed for me locally.