CiviCRM Community Forums (archive)

*

News:

Have a question about CiviCRM?
Get it answered quickly at the new
CiviCRM Stack Exchange Q+A site

This forum was archived on 25 November 2017. Learn more.
How to get involved.
What to do if you think you've found a bug.



  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • DB error exporting group of contacts with household merge
Pages: [1]

Author Topic: DB error exporting group of contacts with household merge  (Read 879 times)

civi5

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
  • CiviCRM version: 4.1
  • CMS version: Drupal 7
  • MySQL version: MySQL 5
  • PHP version: 5.3.6
DB error exporting group of contacts with household merge
March 18, 2013, 01:52:31 pm
I am running Civi 4.2.8 and I have a group that has multiple contacts.  I run a search and I get the list of contacts in that group.  I then choose to export all the contacts.  If I select the Merge Household Members into their Households then I get a DB error during the export.  If I do not merge the contacts then the export works as expected.

I have debugged the error to being a syntax error in the SQL query that generates a temporary table.  The problem is the query is trying to create a column with no name that is the type of varchar(64).  This unnamed column is the last column on the list columns for the temporary as such:

....7_a_b_phone_type varchar(64), 7_a_b_im_service_provider varchar(64), varchar(64), PRIMARY KEY ( id ) , INDEX index_street_address( street_address ) .......

You can see in the middle is just an unnamed varchar(64).  It seems like the array that is generating the column names has an extra index at the end that is blank and that is being added to the list of columns.  Any suggestions on what might be causing this?  All the other exports seem to work just fine. 

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: DB error exporting group of contacts with household merge
March 18, 2013, 03:32:34 pm

Can u add some debugging statements here: CRM/Export/BAO/Export.php and see if you can trace how / where / why the unnamed column is being added

thanx

lobo
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

civi5

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
  • CiviCRM version: 4.1
  • CMS version: Drupal 7
  • MySQL version: MySQL 5
  • PHP version: 5.3.6
Re: DB error exporting group of contacts with household merge
March 18, 2013, 04:39:04 pm
Thanks Lobo. You pointed me in the right direction.  I was able to pinpoint the problem.  In the export file around line 420 there is the relationship merge code

      //also merge Head of Household
      $relationKeyMOH = CRM_Utils_Array::key('Household Member of', $contactRelationshipTypes);
      $relationKeyHOH = CRM_Utils_Array::key('Head of Household for', $contactRelationshipTypes);

      foreach ($returnProperties as $key => $value) {
        if (!array_key_exists($key, $contactRelationshipTypes)) {
          $returnProperties[$relationKeyMOH][$key] = $value;
          $returnProperties[$relationKeyHOH][$key] = $value;
        }
      }


The problem we were having is the relationship name is hard coded into the file.  Our "head of household for" had been renamed. So $relationKeyHOH was returned as an empty string.  Thus the value in $returnProperties was assigned to a key that was [""].  I renamed head of household back to the default name and everything worked as expected. 

Perhaps the pseudo constant ID should be used?  Head of household is always id 6 and member of household is always id 7, or so it seems that is always the case in my expirence.  The problem with relationship name is the name is editable by the user under Administer->Custom Data and Screens->Relationship Types. In this case the customer changed the name years ago when running civi 1.9, or there about.  It was not until just now that the rename of a hard coded system relationship became apparent.

At least the problem is discovered. If there are simple ways to address it I can take a stab at coding the changes if you have any recommendations.

Donald Lobo

  • Administrator
  • I’m (like) Lobo ;)
  • *****
  • Posts: 15963
  • Karma: 470
    • CiviCRM site
  • CiviCRM version: 4.2+
  • CMS version: Drupal 7, Joomla 2.5+
  • MySQL version: 5.5.x
  • PHP version: 5.4.x
Re: DB error exporting group of contacts with household merge
March 18, 2013, 05:30:29 pm
can u apply this patch:

Code: [Select]
diff --git a/CRM/Export/BAO/Export.php b/CRM/Export/BAO/Export.php
index d2f9377..d81160b 100644
--- a/CRM/Export/BAO/Export.php
+++ b/CRM/Export/BAO/Export.php
@@ -91,7 +91,7 @@ class CRM_Export_BAO_Export {
       NULL,
       NULL,
       TRUE,
-      'label',
+      'name',
       FALSE
     );
     $queryMode = CRM_Contact_BAO_Query::MODE_CONTACTS;

and see if it fixes it. the name field does not change and should always be in english etc. If this fixes it, please file an issue and point to this forum topic

thanx

lobo
« Last Edit: March 18, 2013, 06:15:06 pm by Donald Lobo »
A new CiviCRM Q&A resource needs YOUR help to get started. Visit our StackExchange proposed site, sign up and vote on 5 questions

civi5

  • I post occasionally
  • **
  • Posts: 39
  • Karma: 3
  • CiviCRM version: 4.1
  • CMS version: Drupal 7
  • MySQL version: MySQL 5
  • PHP version: 5.3.6
Re: DB error exporting group of contacts with household merge
March 19, 2013, 07:37:43 am
That patch did the trick. I will open up a ticket in just a few moments with this correction.

Thanks for the insight.


edit: issue is created http://issues.civicrm.org/jira/browse/CRM-12154
« Last Edit: March 19, 2013, 07:43:56 am by civi5 »

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Core CiviCRM Functions (Moderator: Yashodha Chaku) »
  • DB error exporting group of contacts with household merge

This forum was archived on 2017-11-26.