Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 2.3.4
    • Fix Version/s: None
    • Component/s: Mapping Drivers, ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      Symfony on all platforms (Windows, Linux and Mac)
      Oracle 11g

      Description

      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.

      Example:
      CO_SEQ_NOMEGIGANTEPRAKCTMEUDEUS

      Alias formed was
      _SEQ_NOMEGIGANTEPRAKCTMEUDEUS101

      HOW TO FIX:
      replace the regex on line 135:
      original:
      $columnName = preg_replace('/[^A-Za-z0-9_]/', '', $columnName);
      fixed:
      $columnName = preg_replace('/[^A-Za-z0-9]/', '', $columnName);

        Activity

        Hide
        Rudi Uhrig Neto added a comment -

        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:

        DefaultQuoteStrategy.php
        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?

        Show
        Rudi Uhrig Neto added a comment - 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: DefaultQuoteStrategy.php 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?
        Hide
        Pablo Santiago Sánchez added a comment -

        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!

        Show
        Pablo Santiago Sánchez added a comment - 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!
        Hide
        Rudi Uhrig Neto added a comment - - edited

        Pablo,

        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_SITUACAO_ACESSO.

        The current code create a sql:
        DT_VERIFICACAO_SITUACAO_ACESSO AS _VERIFICACAO_SITUACAO_ACESSO23,

        My sugestion will produce:
        DT_VERIFICACAO_SITUACAO_ACESSO AS DT_VERIFICACAO_SITUACAO_ACES23,

        Show
        Rudi Uhrig Neto added a comment - - edited Pablo, 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_SITUACAO_ACESSO. The current code create a sql: DT_VERIFICACAO_SITUACAO_ACESSO AS _VERIFICACAO_SITUACAO_ACESSO23, My sugestion will produce: DT_VERIFICACAO_SITUACAO_ACESSO AS DT_VERIFICACAO_SITUACAO_ACES23,
        Hide
        Pablo Santiago Sánchez added a comment -

        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.

        Show
        Pablo Santiago Sánchez added a comment - 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.
        Hide
        Benjamin Eberlei added a comment -

        Fabio B. Silva Can you comment on Rudi Uhrig 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.

        Show
        Benjamin Eberlei added a comment - Fabio B. Silva Can you comment on Rudi Uhrig 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.

          People

          • Assignee:
            Benjamin Eberlei
            Reporter:
            Pablo Santiago Sánchez
          • Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

            • Created:
              Updated: