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 »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • Rebuilding Smart Groups in 2.0
Pages: [1]

Author Topic: Rebuilding Smart Groups in 2.0  (Read 1722 times)

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Rebuilding Smart Groups in 2.0
April 07, 2008, 09:58:29 am
I had been working with Lobo on an upgrade issue where my smart groups became corrupted. I only have about 8 smart groups, so I decided it would actually be easier to just delete them and then rebuild them from new advanced searches.

The problem is that I get the same error when I go to delete them as I do when I go to search on them. I would prefer to delete them as opposed to just disabling them as I would like to keep things clean and tidy.

I am wondering if someone can give me the direct DB query I should run to delete these groups, or if at this point it's a bug? I am happy to directly delete them from the DB; I just want to make sure I do it properly, considering there are a few different group tables.

For reference, here is the error I get when either searching on or trying to delete any of my smart groups:

Code: [Select]

unrecoverable error
    Sorry. A non-recoverable error has occurred.

    Database Error Code: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') = 'all' AND civicrm_contribution.is_test = '0' ) AND ( 1 ) AND 1 ) ' at line 2, 1064

    Return to home page.

Error Details:

Array
(
    [callback] => Array
        (
            [0] => CRM_Core_Error
            [1] => handle
        )

    [code] => -2
    [message] => DB Error: syntax error
    [mode] => 16
    [debug_info] => SELECT DISTINCT(contact_a.id) as contact_id  FROM civicrm_contact contact_a  LEFT JOIN civicrm_group_contact `civicrm_group_contact-10` ON contact_a.id = `civicrm_group_contact-10`.contact_id   WHERE  ( ( ( `civicrm_group_contact-10`.group_id IN (10) AND `civicrm_group_contact-10`.status IN ("Added") ) OR ( 
                            ( contact_a.id IN ( SELECT DISTINCT(contact_a.id) as id  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id   LEFT JOIN civicrm_entity_tag `civicrm_entity_tag-17,7` ON ( `civicrm_entity_tag-17,7`.contact_id = contact_a.id )   WHERE  ( `civicrm_entity_tag-17,7`.tag_id IN (17,7) AND LOWER(  ) = 'all' AND  civicrm_contribution.is_test = '0' )  AND  ( 1 )  AND 1    ) 
                              AND contact_a.id NOT IN (
                              SELECT contact_id FROM civicrm_group_contact
                              WHERE civicrm_group_contact.group_id = 10 AND civicrm_group_contact.status = 'Removed' ) ) ) ) )  LIMIT 0, 25  [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') = 'all' AND  civicrm_contribution.is_test = '0' )  AND  ( 1 )  AND 1    ) 
  ' at line 2]
    [type] => DB_Error
    [user_info] => SELECT DISTINCT(contact_a.id) as contact_id  FROM civicrm_contact contact_a  LEFT JOIN civicrm_group_contact `civicrm_group_contact-10` ON contact_a.id = `civicrm_group_contact-10`.contact_id   WHERE  ( ( ( `civicrm_group_contact-10`.group_id IN (10) AND `civicrm_group_contact-10`.status IN ("Added") ) OR ( 
                            ( contact_a.id IN ( SELECT DISTINCT(contact_a.id) as id  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id   LEFT JOIN civicrm_entity_tag `civicrm_entity_tag-17,7` ON ( `civicrm_entity_tag-17,7`.contact_id = contact_a.id )   WHERE  ( `civicrm_entity_tag-17,7`.tag_id IN (17,7) AND LOWER(  ) = 'all' AND  civicrm_contribution.is_test = '0' )  AND  ( 1 )  AND 1    ) 
                              AND contact_a.id NOT IN (
                              SELECT contact_id FROM civicrm_group_contact
                              WHERE civicrm_group_contact.group_id = 10 AND civicrm_group_contact.status = 'Removed' ) ) ) ) )  LIMIT 0, 25  [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') = 'all' AND  civicrm_contribution.is_test = '0' )  AND  ( 1 )  AND 1    ) 
  ' at line 2]
    [to_string] => [db_error: message="DB Error: syntax error" code=-2 mode=callback callback=CRM_Core_Error::handle prefix="" info="SELECT DISTINCT(contact_a.id) as contact_id  FROM civicrm_contact contact_a  LEFT JOIN civicrm_group_contact `civicrm_group_contact-10` ON contact_a.id = `civicrm_group_contact-10`.contact_id   WHERE  ( ( ( `civicrm_group_contact-10`.group_id IN (10) AND `civicrm_group_contact-10`.status IN ("Added") ) OR ( 
                            ( contact_a.id IN ( SELECT DISTINCT(contact_a.id) as id  FROM civicrm_contact contact_a LEFT JOIN civicrm_contribution ON civicrm_contribution.contact_id = contact_a.id   LEFT JOIN civicrm_entity_tag `civicrm_entity_tag-17,7` ON ( `civicrm_entity_tag-17,7`.contact_id = contact_a.id )   WHERE  ( `civicrm_entity_tag-17,7`.tag_id IN (17,7) AND LOWER(  ) = 'all' AND  civicrm_contribution.is_test = '0' )  AND  ( 1 )  AND 1    ) 
                              AND contact_a.id NOT IN (
                              SELECT contact_id FROM civicrm_group_contact
                              WHERE civicrm_group_contact.group_id = 10 AND civicrm_group_contact.status = 'Removed' ) ) ) ) )  LIMIT 0, 25  [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ') = 'all' AND  civicrm_contribution.is_test = '0' )  AND  ( 1 )  AND 1    ) 
  ' at line 2]"]
)
[/code]

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: Rebuilding Smart Groups in 2.0
April 07, 2008, 02:14:54 pm

1. Make sure you have a backup of the database

2. Do the below on a test site and ensure that you are happy with the test site before you roll into production

3. The code is:

Code: [Select]
mysql> delete from civicrm_group where saved_search_id is not null;
mysql> truncate civicrm_saved_search;

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

emilyf

  • Ask me questions
  • ****
  • Posts: 696
  • Karma: 54
  • CiviCRM version: 2.x - 4.x
  • CMS version: Drupal 5, 6, 7
Re: Rebuilding Smart Groups in 2.0
April 18, 2008, 01:43:20 pm
Thanks lobo...perfect  8)

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • Rebuilding Smart Groups in 2.0

This forum was archived on 2017-11-26.