Skip to content
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

CRM-21061: Fixing CiviReport crashing issue for column alias greater then 64 characters. #11126

Closed
wants to merge 1 commit into from

Conversation

agilewarealok
Copy link
Contributor

@agilewarealok agilewarealok commented Oct 12, 2017

Overview

Steps to reproduce the issue:

  1. Create a field group for individuals with very big name. (at least 40-45 chars)
  2. Create fields in this group with again big names (at least 15-20 characters)
  3. Expose these fields to be part of CiviReport.
  4. Generate CiviReport for activities with selecting Custom contact fields.
  5. Click on Preview Report.

Above case throw following error message.

Database Error Code: Incorrect column name

This happens because the final name of the column with it's table name becomes very big (more then 64 characters) and maximum length of MySQL column is 64 characters.

Before

Report was not getting generated due to the maximum length error of the column.

After

It now works as expected, and show the Report result with correct data.

Technical Details

We're trimming the length of both alias and column header before executing the SQL, this would prevent database level error. We've also written a unit test to prevent this from failing in future.

Agileware Ref: CIVICRM-555


@civicrm-builder
Copy link

Can one of the admins verify this patch?

@seamuslee001
Copy link
Contributor

Jenkins ok to test

@jusfreeman
Copy link
Contributor

Can someone review this PR please?

@jusfreeman
Copy link
Contributor

This PR further work related to #10854

@jusfreeman
Copy link
Contributor

@eileenmcnaughton or @seamuslee001 would you mind reviewing this one?

@eileenmcnaughton
Copy link
Contributor

I actually think we might need to tackle this slightly differently to be consistent with report intent. There are aliases defined on the table spec & on the field spec - we should probably intervene when they are defined to make them a max of 32 char each. Test looks great

@jusfreeman
Copy link
Contributor

@eileenmcnaughton just a heads up, we're not going to spend any more time on this bug fix

@eileenmcnaughton
Copy link
Contributor

I'm going to close this because I think #11183 supercedes it. I have put the unit test in #11866 and will merge that. A case could be made to truncate to support tables created prior to that fix - in which case I think it should be in the following function (although one might assume people would have resolved them by now if hitting them)

  /**
   * Set table alias.
   *
   * @param array $table
   * @param string $tableName
   *
   * @return string
   *   Alias for table.
   */
  protected function setTableAlias($table, $tableName) {
    if (!isset($table['alias'])) {
      $this->_columns[$tableName]['alias'] = substr($tableName, 8) .
        '_civireport';
    }
    else {
      $this->_columns[$tableName]['alias'] = $table['alias'] . '_civireport';
    }

    $this->_aliases[$tableName] = $this->_columns[$tableName]['alias'];
    return $this->_aliases[$tableName];
  }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants