From f63ac65ac584f6b89a88726e0d8555f62f5a2cf2 Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Sat, 4 Sep 2010 11:46:00 +0000 Subject: [PATCH] MDL-24079 converted sql_ilike() to new sql_like in user selectors --- lib/datalib.php | 9 +++++---- user/filters/courserole.php | 16 +++++++++------- user/filters/profilefield.php | 13 ++++++------- user/filters/text.php | 18 ++++++++---------- user/index.php | 5 +++-- user/selector/lib.php | 5 ++--- 6 files changed, 33 insertions(+), 33 deletions(-) diff --git a/lib/datalib.php b/lib/datalib.php index 7ebb845de6..b22c5e742e 100644 --- a/lib/datalib.php +++ b/lib/datalib.php @@ -258,7 +258,6 @@ function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperp $search='', $firstinitial='', $lastinitial='', $extraselect='', array $extraparams=null) { global $DB; - $LIKE = $DB->sql_ilike(); $fullname = $DB->sql_fullname(); $select = "deleted <> 1"; @@ -266,18 +265,20 @@ function get_users_listing($sort='lastaccess', $dir='ASC', $page=0, $recordsperp if (!empty($search)) { $search = trim($search); - $select .= " AND ($fullname $LIKE :search1 OR email $LIKE :search2 OR username = :search3)"; + $select .= " AND (". $DB->sql_like($fullname, ':search1', false, false). + " OR ". $DB->sql_like('email', ':search2', false, false). + " OR username = :search3)"; $params['search1'] = "%$search%"; $params['search2'] = "%$search%"; $params['search3'] = "$search"; } if ($firstinitial) { - $select .= " AND firstname $LIKE :fni"; + $select .= " AND ". $DB->sql_like('firstname', ':fni', false, false); $params['fni'] = "$firstinitial%"; } if ($lastinitial) { - $select .= " AND lastname $LIKE :lni"; + $select .= " AND ". $DB->sql_like('lastname', ':lni', false, false); $params['lni'] = "$lastinitial%"; } diff --git a/user/filters/courserole.php b/user/filters/courserole.php index b542bb6946..06b0f3f0e8 100644 --- a/user/filters/courserole.php +++ b/user/filters/courserole.php @@ -85,8 +85,8 @@ function get_sql_filter($data) { $name = 'ex_courserole'.$counter++; $value = $data['value']; - $roleid = (int)$data['roleid']; - $categoryid = (int)$data['categoryid']; + $roleid = $data['roleid']; + $categoryid = $data['categoryid']; $params = array(); @@ -94,16 +94,18 @@ function get_sql_filter($data) { return array('', $params); } - $timenow = round(time(), 100); // rounding - enable sql caching - $where = "b.contextlevel=50 AND a.timestart<$timenow AND (a.timeend=0 OR a.timeend>$timenow)"; + $where = "b.contextlevel=50"; if ($roleid) { - $where .= " AND a.roleid=$roleid"; + $where .= " AND a.roleid = :roleid"; + $params['roleid'] = $roleid; + } if ($categoryid) { - $where .= " AND c.category=$categoryid"; + $where .= " AND c.category = :categoryid"; + $params['categoryid'] = $categoryid; } if ($value) { - $where .= " AND c.shortname ".$DB->sql_ilike()." :$name"; + $where .= " AND c.shortname = :$name"; $params[$name] = $value; } return array("id IN (SELECT userid diff --git a/user/filters/profilefield.php b/user/filters/profilefield.php index 2b9430dafb..f463bdca59 100644 --- a/user/filters/profilefield.php +++ b/user/filters/profilefield.php @@ -120,7 +120,6 @@ function get_sql_filter($data) { $where = ""; $op = " IN "; - $ilike = $DB->sql_ilike(); if ($operator < 5 and $value === '') { return ''; @@ -128,27 +127,27 @@ function get_sql_filter($data) { switch($operator) { case 0: // contains - $where = "data $ilike :$name"; + $where = $DB->sql_like('data', ":$name", false, false); $params[$name] = "%$value%"; break; case 1: // does not contain - $where = "data NOT $ilike :$name"; + $where = "data NOT LIKE :$name"; //TODO: MDL-24080 $params[$name] = "%$value%"; break; case 2: // equal to - $where = "data $ilike :$name"; + $where = $DB->sql_like('data', ":$name", false, false); $params[$name] = "$value"; break; case 3: // starts with - $where = "data $ilike :$name"; + $where = $DB->sql_like('data', ":$name", false, false); $params[$name] = "$value%"; break; case 4: // ends with - $where = "data $ilike :$name"; + $where = $DB->sql_like('data', ":$name", false, false); $params[$name] = "%$value"; break; case 5: // empty - $where = "data=:$name"; + $where = "data = :$name"; $params[$name] = ""; break; case 6: // is not defined diff --git a/user/filters/text.php b/user/filters/text.php index a611b3b1c7..35a7b653ee 100644 --- a/user/filters/text.php +++ b/user/filters/text.php @@ -88,37 +88,35 @@ function get_sql_filter($data) { return ''; } - $ilike = $DB->sql_ilike(); - switch($operator) { case 0: // contains - $res = "$ilike :$name"; + $res = $DB->sql_like($field, ":$name", false, false); $params[$name] = "%$value%"; break; case 1: // does not contain - $res = "NOT $ilike :$name"; + $res = "$field NOT LIKE :$name"; //TODO: MDL-24080 $params[$name] = "%$value%"; break; case 2: // equal to - $res = "$ilike :$name"; + $res = $DB->sql_like($field, ":$name", false, false); $params[$name] = "$value"; break; case 3: // starts with - $res = "$ilike :$name"; + $res = $DB->sql_like($field, ":$name", false, false); $params[$name] = "$value%"; break; case 4: // ends with - $res = "$ilike :$name"; + $res = $DB->sql_like($field, ":$name", false, false); $params[$name] = "%$value"; break; case 5: // empty - $res = "=:$name"; - $params[$name] = ""; + $res = "$field = :$name"; + $params[$name] = $DB->sql_empty(); break; default: return ''; } - return array($field.' '.$res, $params); + return array($res, $params); } /** diff --git a/user/index.php b/user/index.php index 10c6df0157..b5cd3f941d 100644 --- a/user/index.php +++ b/user/index.php @@ -415,9 +415,10 @@ $totalcount = $DB->count_records_sql("SELECT COUNT(u.id) $from $where", $params); if (!empty($search)) { - $LIKE = $DB->sql_ilike(); $fullname = $DB->sql_fullname('u.firstname','u.lastname'); - $wheres[] = "($fullname $LIKE :search1 OR email $LIKE :search2 OR idnumber $LIKE :search3) "; + $wheres[] = "(". $DB->sql_like($fullname, ':search1', false, false) . + " OR ". $DB->sql_like('email', ':search2', false, false) . + " OR ". $DB->sql_like('idnumber', ':search3', false, false) .") "; $params['search1'] = "%$search%"; $params['search2'] = "%$search%"; $params['search3'] = "%$search%"; diff --git a/user/selector/lib.php b/user/selector/lib.php index daab897301..27d2adef99 100644 --- a/user/selector/lib.php +++ b/user/selector/lib.php @@ -429,15 +429,14 @@ protected function search_sql($search, $u) { foreach ($this->extrafields as $field) { $conditions[] = $u . $field; } - $ilike = ' ' . $DB->sql_ilike(); if ($this->searchanywhere) { $searchparam = '%' . $search . '%'; } else { $searchparam = $search . '%'; } $i = 0; - foreach ($conditions as &$condition) { - $condition .= "$ilike :con{$i}00"; + foreach ($conditions as $key=>$condition) { + $conditions[$key] = $DB->sql_like($condition, ":con{$i}00", false, false); $params["con{$i}00"] = $searchparam; $i++; }