From 54e02ce86571f3e381104643635b4ede9c3e0f80 Mon Sep 17 00:00:00 2001 From: eileen Date: Wed, 24 Oct 2018 08:54:54 +1300 Subject: [PATCH] Remove use of LOWER from city & street searches Adding LOWER to mysql queries makes them slower. lowercasing php strings breaks under some character sets with some server configs. --- CRM/Contact/BAO/Query.php | 7 ++----- tests/phpunit/CRM/Contact/BAO/QueryTest.php | 6 +++--- 2 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CRM/Contact/BAO/Query.php b/CRM/Contact/BAO/Query.php index 027d8165dfdf..c7857ea451b2 100644 --- a/CRM/Contact/BAO/Query.php +++ b/CRM/Contact/BAO/Query.php @@ -2294,8 +2294,7 @@ public function restWhere(&$values) { //get the location name list($tName, $fldName) = self::getLocationTableName($field['where'], $locType); - // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. - $fieldName = "LOWER(`$tName`.$fldName)"; + $fieldName = "`$tName`.$fldName"; // we set both _tables & whereTables because whereTables doesn't seem to do what the name implies it should $this->_tables[$tName] = $this->_whereTables[$tName] = 1; @@ -2307,8 +2306,7 @@ public function restWhere(&$values) { } else { if ($op != 'IN' && !is_numeric($value) && !is_array($value)) { - // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. - $fieldName = "LOWER({$field['where']})"; + $fieldName = "{$field['where']}"; } else { $fieldName = "{$field['where']}"; @@ -3566,7 +3564,6 @@ public function street_address(&$values) { $value = "%{$value}%"; } $op = 'LIKE'; - // LOWER roughly translates to 'hurt my database without deriving any benefit' See CRM-19811. $this->_where[$grouping][] = self::buildClause('civicrm_address.street_address', $op, $value, 'String'); $this->_qill[$grouping][] = ts('Street') . " $op '$n'"; } diff --git a/tests/phpunit/CRM/Contact/BAO/QueryTest.php b/tests/phpunit/CRM/Contact/BAO/QueryTest.php index 96c380d3dc69..14b9d98c01b0 100644 --- a/tests/phpunit/CRM/Contact/BAO/QueryTest.php +++ b/tests/phpunit/CRM/Contact/BAO/QueryTest.php @@ -223,8 +223,8 @@ public function testSearchProfilePrimaryCityCRM14263($params, $selectClause, $wh CRM_Core_Config::singleton()->defaultSearchProfileID = 1; $this->callAPISuccess('address', 'create', array( 'contact_id' => $contactID, - 'city' => 'Cool City', - 'street_address' => 'Long Street', + 'city' => 'Cool CITY', + 'street_address' => 'Long STREET', 'location_type_id' => 1, )); $returnProperties = array( @@ -257,7 +257,7 @@ public function testSearchProfilePrimaryCityCRM14263($params, $selectClause, $wh public function getSearchProfileData() { return [ [ - [['city', '=', 'Cool City', 1, 0]], "civicrm_address.city as `city`", "LOWER(civicrm_address.city) = 'cool city'", + [['city', '=', 'Cool City', 1, 0]], "civicrm_address.city as `city`", "civicrm_address.city = 'cool city'", ], [ // Note that in the query 'long street' is lower cased. We eventually want to change that & not mess with the vars - it turns out