Commit 85213d3b authored by webchick's avatar webchick

#279851 by catch, et al: Replace LOWER() with db_select() and LIKE() where possible.

parent 83c97345
......@@ -1990,7 +1990,7 @@ function comment_form_validate($form, &$form_state) {
$query = db_select('users', 'u');
$query->addField('u', 'uid', 'uid');
$taken = $query
->where('LOWER(name) = :name', array(':name' => $form_state['values']['name']))
->condition('name', db_like($form_state['values']['name']), 'LIKE')
->countQuery()
->execute()
->fetchField();
......
......@@ -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);
}
......
......@@ -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, '<>');
......
......@@ -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);
}
......
......@@ -750,9 +750,11 @@ function user_access($string, $account = NULL) {
* @return boolean TRUE for blocked users, FALSE for active.
*/
function user_is_blocked($name) {
$deny = db_query("SELECT name FROM {users} WHERE status = 0 AND name = LOWER(:name)", array(':name' => $name))->fetchObject();
return $deny;
return db_select('users')
->fields('users', array('name'))
->condition('name', db_like($name), 'LIKE')
->condition('status', 0)
->execute()->fetchObject();
}
/**
......@@ -1054,7 +1056,7 @@ function user_account_form_validate($form, &$form_state) {
if ($error = user_validate_name($form_state['values']['name'])) {
form_set_error('name', $error);
}
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(name) = LOWER(:name)", 0, 1, array(':uid' => $account->uid, ':name' => $form_state['values']['name']))->fetchField()) {
elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('name', db_like($form_state['values']['name']), 'LIKE')->range(0, 1)->execute()->fetchField()) {
form_set_error('name', t('The name %name is already taken.', array('%name' => $form_state['values']['name'])));
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment