DDC-2733: DefaultQuoteStrategy BUG on Oracle #3476

doctrinebot opened this Issue Oct 10, 2013 · 5 comments

2 participants


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

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:

Hi there!

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;

    return $platform->getSQLResultCasing($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!


Comment created by rudi.neto:


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:

My sugestion will produce:


Comment created by phackwer:

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.

@beberlei beberlei was assigned by doctrinebot Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment