Commit 897817eb authored by Dries's avatar Dries
Browse files

- Patch #279851 by catch, David Strauss, Damien Tournoud, asimmonds, c960657,...

- Patch #279851 by catch, David Strauss, Damien Tournoud, asimmonds, c960657, JohnAlbin, drawk, pwolanin, robertDouglass, coltrane: replace LOWER() with db_select() and LIKE() where possible.
parent 994fafce
......@@ -128,6 +128,7 @@ public function mapConditionOperator($operator) {
// statements, we need to use ILIKE instead. Use backslash for escaping
// wildcard characters.
'LIKE' => array('operator' => 'ILIKE', 'postfix' => " ESCAPE '\\\\'"),
'NOT LIKE' => array('operator' => 'NOT ILIKE', 'postfix' => " ESCAPE '\\\\'"),
);
return isset($specials[$operator]) ? $specials[$operator] : NULL;
......
......@@ -1332,6 +1332,7 @@ protected function mapConditionOperator($operator) {
'IS NOT NULL' => array('use_value' => FALSE),
// Use backslash for escaping wildcard characters.
'LIKE' => array('postfix' => " ESCAPE '\\\\'"),
'NOT LIKE' => array('postfix' => " ESCAPE '\\\\'"),
// These ones are here for performance reasons.
'=' => array(),
'<' => array(),
......
......@@ -157,6 +157,7 @@ public function mapConditionOperator($operator) {
// We don't want to override any of the defaults.
static $specials = array(
'LIKE' => array('postfix' => " ESCAPE '\\'"),
'NOT LIKE' => array('postfix' => " ESCAPE '\\'"),
);
return isset($specials[$operator]) ? $specials[$operator] : NULL;
}
......
......@@ -160,7 +160,7 @@ function statistics_top_referrers() {
$query->addExpression('MAX(timestamp)', 'last');
$query
->fields('a', array('url'))
->where('LOWER(url) NOT LIKE :host', array(':host' => '%' . $_SERVER['HTTP_HOST'] . '%'))
->condition('url', '%' . $_SERVER['HTTP_HOST'] . '%', 'NOT LIKE')
->condition('url', '', '<>')
->groupBy('url')
->limit(30)
......@@ -169,7 +169,7 @@ function statistics_top_referrers() {
$count_query = db_select('accesslog', 'a', array('target' => 'slave'));
$count_query->addExpression('COUNT(DISTINCT url)');
$count_query
->where('LOWER(url) NOT LIKE :host', array(':host' => '%' . $_SERVER['HTTP_HOST'] . '%'))
->condition('url', '%' . $_SERVER['HTTP_HOST'] . '%', 'NOT LIKE')
->condition('url', '', '<>');
$query->setCountQuery($count_query);
......
......@@ -1764,7 +1764,7 @@ function system_update_7003() {
));
$or = db_condition('or');
foreach ($result as $allowed) {
$or->where('LOWER(ip) LIKE LOWER(:mask)', array(':mask' => $allowed->mask));
$or->condition('ip', $allowed->mask, 'LIKE');
}
if (count($or)) {
db_delete('blocked_ips')
......
......@@ -856,11 +856,11 @@ function user_search_execute($keys = NULL) {
if (user_access('administer users')) {
// Administrators can also search in the otherwise private email field.
$query->condition(db_or()->
where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%"))->
where('LOWER(mail) LIKE LOWER(:mail)', array(':mail' => "%$keys%")));
condition('name', '%' . db_like($keys) . '%', 'LIKE')->
condition('mail', '%' . db_like($keys) . '%', 'LIKE'));
}
else {
$query->where('LOWER(name) LIKE LOWER(:name)', array(':name' => "%$keys%"));
$query->condition('name', '%' . db_like($keys) . '%', 'LIKE');
}
$result = $query
->limit(15)
......@@ -1125,7 +1125,7 @@ function user_account_form_validate($form, &$form_state) {
if ($error = user_validate_mail($form_state['values']['mail'])) {
form_set_error('mail', $error);
}
elseif ((bool) db_query_range("SELECT 1 FROM {users} WHERE uid <> :uid AND LOWER(mail) = LOWER(:mail)", 0, 1, array(':uid' => $account->uid, ':mail' => $form_state['values']['mail']))->fetchField()) {
elseif ((bool) db_select('users')->fields('users', array('uid'))->condition('uid', $account->uid, '<>')->condition('mail', db_like($form_state['values']['mail']), 'LIKE')->range(0, 1)->execute()->fetchField()) {
// Format error message dependent on whether the user is logged in or not.
if ($GLOBALS['user']->uid) {
form_set_error('mail', t('The e-mail address %email is already taken.', array('%email' => $form_state['values']['mail'])));
......
......@@ -12,7 +12,7 @@
function user_autocomplete($string = '') {
$matches = array();
if ($string) {
$result = db_query_range("SELECT name FROM {users} WHERE LOWER(name) LIKE LOWER(:name)", 0, 10, array(':name' => $string . '%'));
$result = db_select('users')->fields('users', array('name'))->condition('name', db_like($string) . '%', 'LIKE')->range(0, 10)->execute();
foreach ($result as $user) {
$matches[$user->name] = check_plain($user->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