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

CRM_Core_DAO::objectExists() broken by MySQL liberal collation rules

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Major
    • Resolution: Won't Fix
    • Affects Version/s: 1.3
    • Fix Version/s: 1.4
    • Component/s: None
    • Labels:
      None

      Description

      CRM_Core_DAO::objectExists() uses DB_DataObject?s find() method to check whether another object with the same properties exists; this is then used by the objectExists rule in, for example, checks for prefix names? duplicacy.

      Unfortunately (well, not really?), the MySQL?s collation rules we use (utf8_unicode_ci) is not only case-sensitive, but also collates characters quite liberally (for example, resolving e, é and ? into the same character):

      mysql> SELECT * FROM civicrm_individual_prefix WHERE name LIKE 'Sen%';
      ---------------------------------- | id | domain_id | name | weight | is_active |
      ----------------------------------

      5 1 Sen 5 1
      6 1 Sén. 6 1
      7 1 S?n.. 7 1

      ----------------------------------
      3 rows in set (0.00 sec)

      This can be side-stepped by specifying the binary collation:

      mysql> SELECT * FROM civicrm_individual_prefix WHERE name LIKE 'Sen%' COLLATE utf8_bin;
      --------------------------------

      id domain_id name weight is_active

      --------------------------------

      5 1 Sen 5 1

      --------------------------------
      1 row in set (0.00 sec)

      This is what should be done by the objectExists() method.

      Note: MySQL 4.0 does not support collations, so the code to do the actual select should depend on CIVICRM_MYSQL_VERSION.

        Attachments

          Activity

            People

            • Assignee:
              lobo Donald A. Lobo
              Reporter:
              shot Piotr Szotkowski
            • Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: