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 Profiles (Moderator: Dave Greenberg) »
  • DB Error when creating profile
Pages: [1]

Author Topic: DB Error when creating profile  (Read 16919 times)

Aktifit

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.2.1
  • CMS version: Joomla 2.5.11
  • MySQL version: 5.1.66
  • PHP version: 5.3.3-7
DB Error when creating profile
July 15, 2013, 02:43:33 am
I have to work on a Joomla Website with CiviCRM, I upgraded CiviCRM from 4.1.2 to 4.2.1 (I get an error updating the DB on higher versions...). Now when I try to create a profile, I get a a DB Error: syntax error. I know next to nothing about MySQL so I'm kind of lost here, any help would be appreciated.
Error Details:

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 'GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)' at line 1, 1064
Additional Details:

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

        code] => -2
       
[message] => DB Error: syntax error
    [mode] => 16
    [debug_info] => INSERT INTO dedupe (id1, id2, weight) SELECT 0 id1, 0 id2, 0 weight LIMIT 0 GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight) [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 'GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)' at line 1]
    [type] => DB_Error
    [user_info] => INSERT INTO dedupe (id1, id2, weight) SELECT 0 id1, 0 id2, 0 weight LIMIT 0 GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight) [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 'GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)' at line 1]
    [to_string] => [db_error: message="DB Error: syntax error" code=-2 mode=callback callback=CRM_Core_Error::handle prefix="" info="INSERT INTO dedupe (id1, id2, weight) SELECT 0 id1, 0 id2, 0 weight LIMIT 0 GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight) [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 'GROUP BY id1, id2 ON DUPLICATE KEY UPDATE weight = weight + VALUES(weight)' at line 1]"]
)

dkiasimon

  • I’m new here
  • *
  • Posts: 1
  • Karma: 0
  • CiviCRM version: 4.2.6
  • CMS version: Drupal
  • MySQL version: 5.1
  • PHP version: 5.3.10
Re: DB Error when creating profile
July 31, 2013, 11:51:43 am
We've had the same issue. We're running Civicrm on Drupal but in this case it probably doesn't matter. MySQL doesn't like the GROUP BY statement when it's not really selecting anything.
I don't really know how to make a proper patchfile, but here's what I did:

1. Open CRM/Dedupe/BAO/RuleGroup.php

2. Look for this block

if ($this->params && !$this->noRules) {
      $tempTableQuery = "CREATE TEMPORARY TABLE dedupe (id1 int, weight int, UNIQUE UI_id1 (id1)) ENGINE=MyISAM";
      $insertClause   = "INSERT INTO dedupe (id1, weight)";
      $groupByClause  = "GROUP BY id1";
      $dupeCopyJoin   = " JOIN dedupe_copy ON dedupe_copy.id1 = t1.column WHERE ";
    }
    else {
      $tempTableQuery = "CREATE TEMPORARY TABLE dedupe (id1 int, id2 int, weight int, UNIQUE UI_id1_id2 (id1, id2)) ENGINE=MyISAM";
      $insertClause   = "INSERT INTO dedupe (id1, id2, weight)";
      $groupByClause  = "GROUP BY id1, id2";
      $dupeCopyJoin   = " JOIN dedupe_copy ON dedupe_copy.id1 = t1.column AND dedupe_copy.id2 = t2.column WHERE ";
    }

3. Put this in right after the block:

if(isset($this->noRules) && $this->noRules) {
        $groupByClause = "";
}

That should fix it.


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 when creating profile
July 31, 2013, 03:00:59 pm

i think the below is a band aid and does not address the root cause :(

the question is, why is that select statement generated looking so odd (i.e. not using any civi tables etc). seems like civi is not getting a handle on the right dedupe rules etc. i would probably investigate that path first

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

Aktifit

  • I’m new here
  • *
  • Posts: 3
  • Karma: 0
  • CiviCRM version: 4.2.1
  • CMS version: Joomla 2.5.11
  • MySQL version: 5.1.66
  • PHP version: 5.3.3-7
Re: DB Error when creating profile
August 02, 2013, 01:46:37 am
Thanks for the replies, we actually fixed the problem now. Seems like updating CiviCRM may duplicate some of the dedupe rules, at least that was the case on our webpage, so we simply deleted them manually from the dedupe table. Now everything works fine ;).

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Using CiviCRM »
  • Using Profiles (Moderator: Dave Greenberg) »
  • DB Error when creating profile

This forum was archived on 2017-11-26.