Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-8324

Unsubscribe link in mailing results in a MySQL syntax error and fails

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Fixed/Completed
    • Affects Version/s: 3.4.3
    • Fix Version/s: 3.4.4
    • Component/s: CiviMail
    • Labels:
      None

      Description

      The unsubscribe link in a mass mailing sent via CiviMail returns a MySQL syntax error. The cause of this is that the code implodes the array $base_group_ids, which, when empty, returns an empty string. In MySQL the following statement is invalid and returns a syntax error:

      WHERE myfield IN ()

      The parentheses cannot be empty. The following patch resolves this problem. The fix in the patch is not super elegant, but it does resolve the issue at hand. Seems like a more elegant solution would be to not include:

      OR $group.id IN(".implode(', ', $base_group_ids).")

      ... in the query at all if $base_group_ids is empty.

      Following is the error from the CiviCRM log, if it helps:

      Jun 16 18:31:16 [info] $Fatal Error Details = Array
      (
      [callback] => Array
      (
      [0] => CRM_Core_Error
      [1] => handle
      )

      [code] => -2
      [message] => DB Error: syntax error
      [mode] => 16
      [debug_info] =>
      SELECT civicrm_group.id as group_id,
      civicrm_group.title as title,
      civicrm_group.description as description
      FROM civicrm_group
      LEFT JOIN civicrm_group_contact
      ON civicrm_group_contact.group_id = civicrm_group.id
      WHERE civicrm_group.id IN (155)
      AND civicrm_group.is_hidden = 0
      AND (civicrm_group.saved_search_id is not null
      OR (civicrm_group_contact.contact_id = 6263
      AND civicrm_group_contact.status = 'Added')
      OR civicrm_group.id IN()
      ) [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds t
      o your MySQL server version for the right syntax to use near ')
      )' at line 12]
      [type] => DB_Error
      [user_info] =>
      SELECT civicrm_group.id as group_id,
      civicrm_group.title as title,
      civicrm_group.description as description
      FROM civicrm_group
      LEFT JOIN civicrm_group_contact
      ON civicrm_group_contact.group_id = civicrm_group.id
      WHERE civicrm_group.id IN (155)
      AND civicrm_group.is_hidden = 0
      AND (civicrm_group.saved_search_id is not null
      OR (civicrm_group_contact.contact_id = 6263
      AND civicrm_group_contact.status = 'Added')
      OR civicrm_group.id IN()
      ) [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds t
      o your MySQL server version for the right syntax to use near ')
      )' at line 12]
      [to_string] => [db_error: message="DB Error: syntax error" code=-2 mode=callback callback=CRM_Core_Error::handle pr
      efix="" info="
      SELECT civicrm_group.id as group_id,
      civicrm_group.title as title,
      civicrm_group.description as description
      FROM civicrm_group
      LEFT JOIN civicrm_group_contact
      ON civicrm_group_contact.group_id = civicrm_group.id
      WHERE civicrm_group.id IN (155)
      AND civicrm_group.is_hidden = 0
      AND (civicrm_group.saved_search_id is not null
      OR (civicrm_group_contact.contact_id = 6263
      AND civicrm_group_contact.status = 'Added')
      OR civicrm_group.id IN()
      ) [nativecode=1064 ** You have an error in your SQL syntax; check the manual that corresponds t
      o your MySQL server version for the right syntax to use near ')
      )' at line 12]"]
      )

      Jun 16 18:31:16 [info] $backTrace = /var/www/creativecommons.net/www/sites/default/modules/civicrm/CRM/Core/Error.php,
      backtrace, 205
      , handle,
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/packages/PEAR.php, call_user_func, 931
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/packages/DB.php, PEAR_Error, 968
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/packages/PEAR.php, DB_Error, 564
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/packages/DB/common.php, raiseError, 1903
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/packages/DB/mysql.php, raiseError, 898
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/packages/DB/mysql.php, mysqlRaiseError, 327
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/packages/DB/common.php, simpleQuery, 1216
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/packages/DB/DataObject.php, query, 2420
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/packages/DB/DataObject.php, _query, 1606
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/CRM/Core/DAO.php, query, 145
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/CRM/Mailing/Event/BAO/Unsubscribe.php, query, 212
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/CRM/Mailing/Page/Common.php, unsub_from_mailing, 82
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/CRM/Mailing/Page/Optout.php, run, 43
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/CRM/Core/Invoke.php, run, 223
      /var/www/creativecommons.net/www/sites/default/modules/civicrm/drupal/civicrm.module, invoke, 363
      , civicrm_invoke,
      /var/www/creativecommons.net/www/includes/menu.inc, call_user_func_array, 348
      /var/www/creativecommons.net/www/index.php, menu_execute_active_handler, 18

        Attachments

          Activity

            People

            • Assignee:
              rohan Rohan S. Chavan
              Reporter:
              nkinkade Nathan Kinkade
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: