From 85213d3bee5c4373f12378c3fa910f0e93e6d678 Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Wed, 13 Jan 2010 06:44:31 +0000 Subject: #279851 by catch, et al: Replace LOWER() with db_select() and LIKE() where possible. --- modules/profile/profile.admin.inc | 7 ++++++- modules/profile/profile.module | 3 +-- modules/profile/profile.pages.inc | 12 ++++++++---- 3 files changed, 15 insertions(+), 7 deletions(-) (limited to 'modules/profile') diff --git a/modules/profile/profile.admin.inc b/modules/profile/profile.admin.inc index 7503bcaa3..72708a55a 100644 --- a/modules/profile/profile.admin.inc +++ b/modules/profile/profile.admin.inc @@ -421,7 +421,12 @@ function profile_field_delete_submit($form, &$form_state) { */ function profile_admin_settings_autocomplete($string) { $matches = array(); - $result = db_query_range("SELECT category FROM {profile_field} WHERE LOWER(category) LIKE LOWER(:category)", 0, 10, array(':category' => $string . '%')); + $result = db_select('profile_field') + ->fields('profile_field', array('category')) + ->condition('category', db_like($string) . '%', 'LIKE') + ->range(0, 10) + ->execute(); + foreach ($result as $data) { $matches[$data->category] = check_plain($data->category); } diff --git a/modules/profile/profile.module b/modules/profile/profile.module index 244c8804d..38642d538 100644 --- a/modules/profile/profile.module +++ b/modules/profile/profile.module @@ -610,8 +610,7 @@ function _profile_get_fields($category, $register = FALSE) { $query->condition('register', 1); } else { - // Use LOWER(:category) instead of PHP's strtolower() to avoid UTF-8 conversion issues. - $query->where('LOWER(category) = LOWER(:category)', array(':category' => $category)); + $query->condition('category', db_like($category), 'LIKE'); } if (!user_access('administer users')) { $query->condition('visibility', PROFILE_HIDDEN, '<>'); diff --git a/modules/profile/profile.pages.inc b/modules/profile/profile.pages.inc index 9bb406bb4..bfc23e221 100644 --- a/modules/profile/profile.pages.inc +++ b/modules/profile/profile.pages.inc @@ -125,10 +125,14 @@ function profile_autocomplete($field, $string) { $matches = array(); $autocomplete_field = (bool) db_query_range("SELECT 1 FROM {profile_field} WHERE fid = :fid AND autocomplete = 1", 0, 1, array(':fid' => $field))->fetchField(); if ($autocomplete_field) { - $values = db_query_range("SELECT value FROM {profile_value} WHERE fid = :fid AND LOWER(value) LIKE LOWER(:value) GROUP BY value ORDER BY value ASC", 0, 10, array( - ':fid' => $field, - ':value' => $string . '%', - ))->fetchCol(); + $values = db_select('profile_value') + ->fields('profile_value', array('value')) + ->condition('fid', $field) + ->condition('value', db_like($string) . '%', 'LIKE') + ->groupBy('value') + ->orderBy('value') + ->range(0, 10) + ->execute()->fetchCol(); foreach ($values as $value) { $matches[$value] = check_plain($value); } -- cgit v1.2.3