Doctrine 1
  1. Doctrine 1
  2. DC-335

Oracle identifier too long in normal SELECT when using longer table name or column

    Details

    • Type: Bug Bug
    • Status: Open
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: 1.2.1
    • Fix Version/s: None
    • Component/s: Query
    • Labels:
      None
    • Environment:
      Oracle

      Description

      Unfortunatelly oracle has max identifier length for 30 characters. When using longer model names eg. misCompanyContributor with column names the generated aliases for selected columns mix tableized modelname with colum name joined by two __, and sometimes the generated alias should exceed the allowed 30 characters long identifiers, and oracle complains with:

      {{
      ORA-00972: identifier is too long
      }}

      An example of large select with alias:
      {{
      SELECT
      ...
      mis_contributor.contributor_id AS mis_contributor__contributor_id
      ..
      FROM mis_contributor ...
      }}

        Activity

        Hide
        Michel D'HOOGE added a comment -

        I have applied the following patch to use aliases of identifiers (what is after the "as" when defining field name).

        So far, it seems to work... But I am quite sure I didn't take all possible cases into consideration.

        --- lib/vendor/doctrine/Doctrine/Hydrator/Graph.php.orig	2010-10-07 19:09:10.000000000 +0200
        +++ lib/vendor/doctrine/Doctrine/Hydrator/Graph.php	2010-10-14 00:08:05.000000000 +0200
        @@ -298,10 +298,10 @@
                         }
         
                         $e = explode('__', $key);
        -                $last = strtolower(array_pop($e));
        +                $fieldName = strtolower(array_pop($e));
                         $cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))];
                         $table = $this->_queryComponents[$cache[$key]['dqlAlias']]['table'];
        -                $fieldName = $table->getFieldName($last);
        +                $last = $table->getColumnName($fieldName);
                         $cache[$key]['fieldName'] = $fieldName;
                         if ($table->isIdentifier($fieldName)) {
                             $cache[$key]['isIdentifier'] = true;
        
        --- lib/vendor/doctrine/Doctrine/Query.php.orig	2010-10-07 19:09:10.000000000 +0200
        +++ lib/vendor/doctrine/Doctrine/Query.php	2010-10-14 00:03:28.000000000 +0200
        @@ -494,12 +494,12 @@
                         $parentAlias = $this->getSqlTableAlias($componentAlias . '.' . $parent->getComponentName());
                         $sql[] = $this->_conn->quoteIdentifier($parentAlias) . '.' . $this->_conn->quoteIdentifier($columnName)
                                . ' AS '
        -                       . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
        +                       . $this->_conn->quoteIdentifier($tableAlias . '__' . $fieldName);
                     } else {
        -                $columnName = $table->getColumnName($fieldName);
        +                $columnName = $table->getColumnName($fieldName); // Really needed?
                         $sql[] = $this->_conn->quoteIdentifier($tableAlias) . '.' . $this->_conn->quoteIdentifier($columnName)
                                . ' AS '
        -                       . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName);
        +                       . $this->_conn->quoteIdentifier($tableAlias . '__' . $fieldName);
                     }
                 }
         
        @@ -554,7 +554,7 @@
         
                     return $this->_conn->quoteIdentifier($tableAlias . '.' . $name)
                            . ' AS '
        -                   . $this->_conn->quoteIdentifier($tableAlias . '__' . $name);
        +                   . $this->_conn->quoteIdentifier($tableAlias . '__' . $field);
                 }
             }
        
        Show
        Michel D'HOOGE added a comment - I have applied the following patch to use aliases of identifiers (what is after the "as" when defining field name). So far, it seems to work... But I am quite sure I didn't take all possible cases into consideration. --- lib/vendor/doctrine/Doctrine/Hydrator/Graph.php.orig 2010-10-07 19:09:10.000000000 +0200 +++ lib/vendor/doctrine/Doctrine/Hydrator/Graph.php 2010-10-14 00:08:05.000000000 +0200 @@ -298,10 +298,10 @@ } $e = explode('__', $key); - $last = strtolower(array_pop($e)); + $fieldName = strtolower(array_pop($e)); $cache[$key]['dqlAlias'] = $this->_tableAliases[strtolower(implode('__', $e))]; $table = $this->_queryComponents[$cache[$key]['dqlAlias']]['table']; - $fieldName = $table->getFieldName($last); + $last = $table->getColumnName($fieldName); $cache[$key]['fieldName'] = $fieldName; if ($table->isIdentifier($fieldName)) { $cache[$key]['isIdentifier'] = true; --- lib/vendor/doctrine/Doctrine/Query.php.orig 2010-10-07 19:09:10.000000000 +0200 +++ lib/vendor/doctrine/Doctrine/Query.php 2010-10-14 00:03:28.000000000 +0200 @@ -494,12 +494,12 @@ $parentAlias = $this->getSqlTableAlias($componentAlias . '.' . $parent->getComponentName()); $sql[] = $this->_conn->quoteIdentifier($parentAlias) . '.' . $this->_conn->quoteIdentifier($columnName) . ' AS ' - . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); + . $this->_conn->quoteIdentifier($tableAlias . '__' . $fieldName); } else { - $columnName = $table->getColumnName($fieldName); + $columnName = $table->getColumnName($fieldName); // Really needed? $sql[] = $this->_conn->quoteIdentifier($tableAlias) . '.' . $this->_conn->quoteIdentifier($columnName) . ' AS ' - . $this->_conn->quoteIdentifier($tableAlias . '__' . $columnName); + . $this->_conn->quoteIdentifier($tableAlias . '__' . $fieldName); } } @@ -554,7 +554,7 @@ return $this->_conn->quoteIdentifier($tableAlias . '.' . $name) . ' AS ' - . $this->_conn->quoteIdentifier($tableAlias . '__' . $name); + . $this->_conn->quoteIdentifier($tableAlias . '__' . $field); } }
        Hide
        Michel D'HOOGE added a comment -

        A workaround is available in DC-72 for version 1.1.4

        Show
        Michel D'HOOGE added a comment - A workaround is available in DC-72 for version 1.1.4

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Miloslav "adrive" Kmet
          • Votes:
            1 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

            • Created:
              Updated: