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) »
  • MySQL error at Step One: Subquery returns more than 1 row
Pages: [1]

Author Topic: MySQL error at Step One: Subquery returns more than 1 row  (Read 5233 times)

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
MySQL error at Step One: Subquery returns more than 1 row
July 23, 2008, 08:42:08 am
Hi,

I'm getting this error at Step One:
Database Error Code: Subquery returns more than 1 row, 1242

Here's the query:
SET @dupe_field_names = (SELECT name FROM civicrm_custom_field group by name having count(*) > 1)

Here's the result of manually running SELECT name FROM civicrm_custom_field group by name having count(*) > 1 :
+---------------------------------+
| name                            |
+---------------------------------+
| Food_in_Community__Groups_You_W |
| Producing_Food__Freedom_Foods_C |
| Producing_Food__Organic_Certifi |
| Producing_Food__Supply_Public_S |
+---------------------------------+

CiviCRM 2.0.5
Drupal 5.8
MySQL 5.0.45 (also tested on 5.0.22).

I'm upgrading a test copy of a 1.8 db. I've gone through the intermediate upgrades and the "Rebuild your 1.9 Database to Ensure Schema Integrity" steps. I had previously got past this stage in a trial upgrade of the same 1.8 db to 2.0.3, so this may be a new error since 2.0.3 . I documented the steps I took in my 2.0.3 trial upgrade and have followed them here.

   1. Upgrade db from 1.8 to 1.9 - see  Upgrade from Prior Versions:
          * Create civicrm19 and import dump of civicrm18.
          * Run civicrm_upgradedb_v1.8_v1.9_41.mysql from 2.0.5 on civicrm19 - OK.
   2. Rebuild your 1.9 Database to Ensure Schema Integrity:
          * Create civicrm20 and run civicrm_41.mysql from civicrm-1.9.13019-drupal-php5 on it.
          * Dump the data ONLY from civicrm19:
            mysqldump -u root -p -c -e -n -t civicrm19 > ...
          * Import this data dump into civicrm20.
   3. Reset config_backend:
      update civicrm_domain set config_backend = NULL where id = 1
   4. Check perms on files/ .
   5. Visit /index.php?q=civicrm/upgrade&reset=1 ->
      Upgrade Step One (Database Cleanup)

Any help appreciated. Thanks,

Dave

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: MySQL error at Step One: Subquery returns more than 1 row
July 23, 2008, 03:39:38 pm

most likely u might have triggered an upgrade bug :(

can u please mail your db to deepak at webaccess.co.in and we'll take a look :)

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

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: MySQL error at Step One: Subquery returns more than 1 row
July 24, 2008, 03:06:27 am
Thanks Lobo, will do so as soon as I receive permission from the data's owner. Which would be more helpful, the original 1.8 db or after upgrading to 1.9 & rebuilding?

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: MySQL error at Step One: Subquery returns more than 1 row
July 24, 2008, 03:11:30 am

can u send the 1.9 db after it has been rebuilt

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

Deepak Srivastava

  • Moderator
  • Ask me questions
  • *****
  • Posts: 677
  • Karma: 65
Re: MySQL error at Step One: Subquery returns more than 1 row
July 25, 2008, 03:15:54 am
Dave,
The error you noticed will only occur for cases when there are more than one duplicate custom-field-name in the db (as was in your case).

I applied the following patch to fix the error:
Quote
--- CRM/Upgrade/TwoZero/sql/cleanup.mysql       (revision 16083)
+++ CRM/Upgrade/TwoZero/sql/cleanup.mysql       (working copy)
@@ -79,13 +79,13 @@
 
 -- fix duplicate names in custom fields / groups
 
-SET @dupe_field_names = (SELECT name FROM civicrm_custom_field group by name having count(*) > 1);
+SELECT @dupe_field_names := name FROM civicrm_custom_field group by name having count(*) > 1;
 
 UPDATE civicrm_custom_field
 SET name = LOWER(REPLACE(REPLACE(REPLACE(label, '/', ''), '-', ''), ' ', '_'))
 WHERE name IN (@dupe_field_names);
 
-SET @dupe_group_names = (SELECT name FROM civicrm_custom_group group by name having count(*) > 1);
+SELECT @dupe_group_names := name FROM civicrm_custom_group group by name having count(*) > 1;
 
 UPDATE civicrm_custom_group
 SET name = LOWER(REPLACE(REPLACE(REPLACE(title, '/', ''), '-', ''), ' ', '_'))

though it didn't actually solve the problem since the query could not convert those duplicate names into unique ones, which was clear /w the following error:
         Database consistency check failed for step 1. Duplicate entries found in civicrm_custom_field for the column 'name'.
which i had to fix using some custom queries which i 'll mail you separately.

I also came across errors which implied you had special characters in you custom-field names. Following is the query i used to fix this problem:
Quote
UPDATE civicrm_custom_field
SET name = LOWER( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( REPLACE( name, '?', '' ) , ':', '' ) , '(', '' ), ')', '' ), '&', ''), '.', '') );
« Last Edit: July 25, 2008, 03:27:02 am by Deepak Srivastava »
Found this reply helpful? Contribute NOW and help us improve CiviCRM with the Make it Happen! initiative.

davej

  • Ask me questions
  • ****
  • Posts: 404
  • Karma: 21
Re: MySQL error at Step One: Subquery returns more than 1 row
July 25, 2008, 08:18:44 am
Many thanks for your help, Deepak. I posted about the problem with duplicate field names during a previous attempt at upgrading - 1.9 to 2.0.2 Custom Data Upgrade: Duplicate column name; no table name - solved but didn't get that far this time due to the new error.

I think your change to cleanup.mysql leaves it semantically incorrect, though. As you say, the 2.0.5 version only works if there is no more than one name that is duplicated. Your change avoids the error message "Subquery returns more than 1 row" but the code does not actually work for the case where there is more than one duplicated name. The statement:
Code: [Select]
SELECT @dupe_field_names := name FROM civicrm_custom_field group by name having count(*) > 1;just assigns the last selected name to @dupe_field_names, not the whole list of names. As I understand it, MySQL user-defined variables are scalar only. So the subsequent UPDATE just fixes the last of the duplicate names.

I tried a different approach, which works for me:

Code: [Select]
CREATE TEMPORARY TABLE civicrm_temp_custom_field_dupes ( name varchar(64) not null );

INSERT INTO civicrm_temp_custom_field_dupes (name)
SELECT name FROM civicrm_custom_field group by name having count(*) > 1;

UPDATE civicrm_custom_field
SET name = LOWER(REPLACE(REPLACE(REPLACE(label, '/', ''), '-', ''), ' ', '_'))
WHERE name IN (SELECT name FROM civicrm_temp_custom_field_dupes);

A similar approach should work for duplicate group names.

I also added to cleanup.mysql your query to remove problematic characters from field names. With these changes to cleanup.mysql, the upgrade completes without further intervention.  :)

Hope these comments are helpful and thanks again for your efforts.

Dave

Pages: [1]
  • CiviCRM Community Forums (archive) »
  • Old sections (read-only, deprecated) »
  • Support »
  • Upgrading CiviCRM (Moderator: Deepak Srivastava) »
  • MySQL error at Step One: Subquery returns more than 1 row

This forum was archived on 2017-11-26.