Index: message/lib.php
===================================================================
--- message/lib.php	(revision 140)
+++ message/lib.php	(working copy)
@@ -631,7 +631,6 @@
     global $CFG, $USER;
 
     $fullname = sql_fullname();
-    $LIKE     = sql_ilike();
 
     if (!empty($exceptions)) {
         $except = ' AND u.id NOT IN ('. $exceptions .') ';
@@ -654,7 +653,7 @@
                       LEFT OUTER JOIN {$CFG->prefix}message_contacts mc
                       ON mc.contactid = u.id AND mc.userid = {$USER->id} 
                       WHERE $select
-                          AND ($fullname $LIKE '%$searchtext%')
+                          AND (" . sql_olike($fullname, $searchtext) . ")
                           $except $order");
     } else {
 
@@ -670,7 +669,7 @@
                                  ON mc.contactid = u.id AND mc.userid = {$USER->id} 
                                  WHERE $select
                                        AND ra.contextid $contextlists
-                                       AND ($fullname $LIKE '%$searchtext%')
+                                       AND (" . sql_olike($fullname, $searchtext) . ")
                                        $except $order");
 
         return $users;
@@ -691,8 +690,6 @@
     if ($userid == 0) $userid = $USER->id;
 
     /// Some differences in SQL syntax
-    $LIKE = sql_ilike();
-    $NOTLIKE = 'NOT ' . $LIKE;
     if ($CFG->dbfamily == "postgres") {
         $REGEXP = "~*";
         $NOTREGEXP = "!~*";
@@ -724,7 +721,7 @@
             $searchterm = substr($searchterm,1);
             $messagesearch .= " m.message $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
         } else {
-            $messagesearch .= " m.message $LIKE '%$searchterm%' ";
+            $messagesearch .= sql_olike('m.message', $searchterm);
         }
     }
 
Index: group/lib.php
===================================================================
--- group/lib.php	(revision 140)
+++ group/lib.php	(working copy)
@@ -401,9 +401,8 @@
     $context = get_context_instance(CONTEXT_COURSE, $courseid);
     
     if ($searchtext !== '') {   // Search for a subset of remaining users
-        $LIKE      = sql_ilike();
         $FULLNAME  = sql_fullname();
-        $wheresearch = " AND u.id IN (SELECT id FROM {$CFG->prefix}user WHERE $FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%' )";
+        $wheresearch = " AND u.id IN (SELECT id FROM {$CFG->prefix}user WHERE " . sql_olike($FULLNAME, $searchtext) . " OR " . sql_olike('email', $searchtext) . ")";
     } else {
         $wheresearch = '';
     }
Index: lib/datalib.php
===================================================================
--- lib/datalib.php	(revision 140)
+++ lib/datalib.php	(working copy)
@@ -148,7 +148,6 @@
 function search_users($courseid, $groupid, $searchtext, $sort='', $exceptions='') {
     global $CFG;
 
-    $LIKE      = sql_ilike();
     $fullname  = sql_fullname('u.firstname', 'u.lastname');
 
     if (!empty($exceptions)) {
@@ -169,7 +168,7 @@
         return get_records_sql("SELECT u.id, u.firstname, u.lastname, u.email
                       FROM {$CFG->prefix}user u
                       WHERE $select
-                          AND ($fullname $LIKE '%$searchtext%' OR u.email $LIKE '%$searchtext%')
+                          AND (" . sql_olike($fullname, $searchtext) . " OR " . sql_olike(u.email,$searchtext) . ")
                           $except $order");
     } else {
 
@@ -179,7 +178,7 @@
                           FROM {$CFG->prefix}user u,
                                {$CFG->prefix}groups_members gm
                           WHERE $select AND gm.groupid = '$groupid' AND gm.userid = u.id
-                              AND ($fullname $LIKE '%$searchtext%' OR u.email $LIKE '%$searchtext%')
+                              AND (" . sql_olike($fullname, $searchtext) . " OR " . sql_olike(u.email,$searchtext) . ")
                               $except $order");
         } else {
             $context = get_context_instance(CONTEXT_COURSE, $courseid);
@@ -188,7 +187,7 @@
                           FROM {$CFG->prefix}user u,
                                {$CFG->prefix}role_assignments ra
                           WHERE $select AND ra.contextid $contextlists AND ra.userid = u.id
-                              AND ($fullname $LIKE '%$searchtext%' OR u.email $LIKE '%$searchtext%')
+                              AND (" . sql_olike($fullname, $searchtext) . " OR " . sql_olike(u.email,$searchtext) . ")
                               $except $order");
         }
         return $users;
@@ -242,14 +241,13 @@
                 'load so much data into memory.', DEBUG_DEVELOPER);
     }
 
-    $LIKE      = sql_ilike();
     $fullname  = sql_fullname();
 
     $select = 'username <> \'guest\' AND deleted = 0';
 
     if (!empty($search)){
         $search = trim($search);
-        $select .= " AND ($fullname $LIKE '%$search%' OR email $LIKE '%$search%') ";
+        $select .= " AND (" . sql_olike($fullname, $searchtext) . " OR " . sql_olike(u.email,$searchtext) . ") ";
     }
 
     if ($confirmed) {
@@ -301,22 +299,21 @@
 
     global $CFG;
 
-    $LIKE      = sql_ilike();
     $fullname  = sql_fullname();
 
     $select = "deleted <> '1'";
 
     if (!empty($search)) {
         $search = trim($search);
-        $select .= " AND ($fullname $LIKE '%$search%' OR email $LIKE '%$search%' OR username='$search') ";
+        $select .= " AND (" . sql_olike($fullname, $search) . " OR " . sql_olike(u.email, $search) . " OR username='$search') ";
     }
 
     if ($firstinitial) {
-        $select .= ' AND firstname '. $LIKE .' \''. $firstinitial .'%\' ';
+        $select .= ' AND ' . sql_olike('firstname', $firstinitial, 3);
     }
 
     if ($lastinitial) {
-        $select .= ' AND lastname '. $LIKE .' \''. $lastinitial .'%\' ';
+        $select .= ' AND ' . sql_olike('lastname', $lastinitial, 3);
     }
 
     if ($extraselect) {
@@ -1080,13 +1077,9 @@
 
     //to allow case-insensitive search for postgesql
     if ($CFG->dbfamily == 'postgres') {
-        $LIKE = 'ILIKE';
-        $NOTLIKE = 'NOT ILIKE';   // case-insensitive
         $REGEXP = '~*';
         $NOTREGEXP = '!~*';
     } else {
-        $LIKE = 'LIKE';
-        $NOTLIKE = 'NOT LIKE';
         $REGEXP = 'REGEXP';
         $NOTREGEXP = 'NOT REGEXP';
     }
@@ -1136,10 +1129,10 @@
             $idnumbersearch .= " c.idnumber $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
             $shortnamesearch .= " c.shortname $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
         } else {
-            $summarysearch .= ' summary '. $NOT . $LIKE .' \'%'. $searchterm .'%\' ';
-            $fullnamesearch .= ' fullname '. $NOT . $LIKE .' \'%'. $searchterm .'%\' ';
-            $idnumbersearch .= ' idnumber '. $NOT . $LIKE .' \'%'. $searchterm .'%\' ';
-            $shortnamesearch .= ' shortname '. $NOT . $LIKE .' \'%'. $searchterm .'%\' ';
+            $summarysearch .= sql_olike('summary', $searchterm, 1);
+            $fullnamesearch .= sql_olike('fullname', $searchterm, 1);
+            $idnumbersearch .= sql_olike('idnumber', $searchterm, 1);
+            $shortnamesearch .= sql_olike('shortname', $searchterm, 1);
         }
 
     }
Index: lib/dmllib.php
===================================================================
--- lib/dmllib.php	(revision 140)
+++ lib/dmllib.php	(working copy)
@@ -1773,7 +1773,65 @@
     }
 }
 
+/**
+ * Returns the proper SQL to do LIKE in a case-insensitive way for oracle
+ * and Postgres
+ * 
+ * Note the LIKE are case sensitive for Oracle. Oracle 10g is required to use
+ * the caseinsensitive search using regexp_like() or NLS_COMP=LINGUISTIC :-(
+ * See http://docs.moodle.org/en/XMLDB_Problems#Case-insensitive_searches
+ *
+ * @uses $CFG
+ * @param string $field Number of records per page
+ * @param string $data Number of records per page
+ * @param integer $operator Number of records per page
+ * @return string
+ */
+function sql_olike($field, $data, $operator=0) {
+    global $CFG;
+    $not = '';
 
+    switch ($operator) {
+        case 0: // contains
+            $value = "'%$data%'";
+            $oci8_value = "'$data'";
+            break;
+        case 1: // does not contain
+            $not = 'NOT';
+            $value = "'%$data%'";
+            $oci8_value = "'$data'";
+            break;
+        case 2: // equal to
+            $value = "'$data'";
+            $oci8_value = "'^$data$'";
+            break;
+        case 3: // starts with
+            $value = "'$data%'";
+            $oci8_value = "'^$data'";
+            break;
+        case 4: // ends with
+            $value = "'%$data'";
+            $oci8_value = "'$data$'";
+            break;
+        case 5: // empty
+            $value = "''";
+            $oci8_value = "''";
+            break;
+        case 7: // is defined
+            break;
+    }
+
+    switch ($CFG->dbfamily) {
+        case 'postgres':
+             return " $field $not ILIKE $value ";
+        case 'oracle':
+            return "$not regexp_like($field, $oci8_value, 'i') ";
+        default:
+             return " $field $not LIKE $value ";
+    }
+}
+
+
 /**
  * Returns the proper SQL to do MAX
  *
Index: lib/searchlib.php
===================================================================
--- lib/searchlib.php	(revision 140)
+++ lib/searchlib.php	(working copy)
@@ -445,9 +445,7 @@
 function search_generate_SQL($parsetree, $datafield, $metafield, $mainidfield, $useridfield,
                              $userfirstnamefield, $userlastnamefield, $timefield, $instancefield) {
     global $CFG;
-
-    $LIKE = sql_ilike();
-    $NOTLIKE = 'NOT ' . $LIKE;
+    
     if ($CFG->dbfamily == "postgres") {
         $REGEXP = "~*";
         $NOTREGEXP = "!~*";
@@ -480,19 +478,24 @@
         }
 
         switch($type){
-            case TOKEN_STRING: 
-                $SQLString .= "(($datafield $LIKE '%$value%') OR ($metafield $LIKE '%$value%') )";
+            case TOKEN_STRING:
+                $LIKE1 = sql_olike($datafield, $value);
+                $LIKE2 = sql_olike($metafield, $value);
+                $SQLString .= "(($LIKE1) OR ($LIKE2) )";
                 break;
             case TOKEN_EXACT: 
                 $SQLString .= "(($datafield $REGEXP '[[:<:]]".$value."[[:>:]]') OR ($metafield $REGEXP '[[:<:]]".$value."[[:>:]]'))";
                 break; 
             case TOKEN_META: 
                 if ($metafield != '') {
-                    $SQLString .= "($metafield $LIKE '%$value%')";
+                    $LIKE = sql_olike($metafield, $value);
+                    $SQLString .= "($LIKE)";
                 }
                 break;
-            case TOKEN_USER: 
-                $SQLString .= "(($mainidfield = $useridfield) AND (($userfirstnamefield $LIKE '%$value%') OR ($userlastnamefield $LIKE '%$value%')))";
+            case TOKEN_USER:
+                $LIKE1 = sql_olike($userfirstnamefield, $value);
+                $LIKE2 = sql_olike($userlastnamefield, $value);
+                $SQLString .= "(($mainidfield = $useridfield) AND (($LIKE1) OR ($LIKE2)))";
                 break; 
             case TOKEN_USERID: 
                 $SQLString .= "($useridfield = $value)";
@@ -506,8 +509,10 @@
             case TOKEN_DATEFROM: 
                 $SQLString .= "($timefield >= $value)";
                 break; 
-            case TOKEN_NEGATE: 
-                $SQLString .= "(NOT (($datafield  $LIKE '%$value%') OR ($metafield  $LIKE '%$value%')))";
+            case TOKEN_NEGATE:
+                $LIKE1 = sql_olike($datafield, $value);
+                $LIKE2 = sql_olike($metafield, $value);
+                $SQLString .= "(NOT (($LIKE1) OR ($LIKE2)))";
                 break; 
             default:
                 return '';
Index: lib/tablelib.php
===================================================================
--- lib/tablelib.php	(revision 140)
+++ lib/tablelib.php	(working copy)
@@ -490,15 +490,14 @@
             return '';
         }
 
-        $LIKE = sql_ilike();
         if(!empty($this->sess->i_first) && !empty($this->sess->i_last)) {
-            return 'firstname '.$LIKE.' \''.$this->sess->i_first.'%\' AND lastname '.$LIKE.' \''.$this->sess->i_last.'%\'';
+            return sql_olike('firstname', $this->sess->i_first) . ' AND ' . sql_olike('lastname', $this->sess->i_last);
         }
         else if(!empty($this->sess->i_first)) {
-            return 'firstname '.$LIKE.' \''.$this->sess->i_first.'%\'';
+            return sql_olike('firstname', $this->sess->i_first);
         }
         else if(!empty($this->sess->i_last)) {
-            return 'lastname '.$LIKE.' \''.$this->sess->i_last.'%\'';
+            return sql_olike('lastname', $this->sess->i_last);
         }
 
         return '';
Index: mod/questionnaire/lib.php
===================================================================
--- mod/questionnaire/lib.php	(revision 140)
+++ mod/questionnaire/lib.php	(working copy)
@@ -746,9 +746,7 @@
     $QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENANSWERED = 1;
     $QUESTIONNAIRE_STUDENTVIEWRESPONSES_WHENCLOSED = 2;
     $QUESTIONNAIRE_STUDENTVIEWRESPONSES_ALWAYS = 3;
-
-    $LIKE = sql_ilike();
-
+    
     if (empty($courses) || !is_array($courses) || count($courses) == 0) {
         return array();
     }
Index: mod/glossary/db/postgres7.php
===================================================================
--- mod/glossary/db/postgres7.php	(revision 140)
+++ mod/glossary/db/postgres7.php	(working copy)
@@ -190,15 +190,15 @@
     if ($oldversion < 2006082600) {
         $sql1 = "UPDATE {$CFG->prefix}glossary_entries SET definition = REPLACE(definition, '".TRUSTTEXT."', '');";
         $sql2 = "UPDATE {$CFG->prefix}glossary_comments SET comment = REPLACE(comment, '".TRUSTTEXT."', '');";
-        $likecond = sql_ilike()." '%".TRUSTTEXT."%'";
+        $likecond = sql_olike('message', TRUSTTEXT);
         while (true) {
-            if (!count_records_select('glossary_entries', "definition $likecond")) {
+            if (!count_records_select('glossary_entries', $likecond)) {
                 break;
             }
             execute_sql($sql1);
         }
         while (true) {
-            if (!count_records_select('glossary_comments', "comment $likecond")) {
+            if (!count_records_select('glossary_comments', $likecond)) {
                 break;
             }
             execute_sql($sql2);
Index: mod/glossary/db/mysql.php
===================================================================
--- mod/glossary/db/mysql.php	(revision 140)
+++ mod/glossary/db/mysql.php	(working copy)
@@ -424,15 +424,15 @@
     if ($oldversion < 2006082600) {
         $sql1 = "UPDATE {$CFG->prefix}glossary_entries SET definition = REPLACE(definition, '".TRUSTTEXT."', '');";
         $sql2 = "UPDATE {$CFG->prefix}glossary_comments SET comment = REPLACE(comment, '".TRUSTTEXT."', '');";
-        $likecond = sql_ilike()." '%".TRUSTTEXT."%'";
+        $likecond = sql_olike('message', TRUSTTEXT);
         while (true) {
-            if (!count_records_select('glossary_entries', "definition $likecond")) {
+            if (!count_records_select('glossary_entries', $likecond)) {
                 break;
             }
             execute_sql($sql1);
         }
         while (true) {
-            if (!count_records_select('glossary_comments', "comment $likecond")) {
+            if (!count_records_select('glossary_comments', $likecond)) {
                 break;
             }
             execute_sql($sql2);
Index: mod/glossary/editcategories.php
===================================================================
--- mod/glossary/editcategories.php	(revision 140)
+++ mod/glossary/editcategories.php	(working copy)
@@ -140,8 +140,7 @@
 
     } elseif ( $action == "add" ) {
         if ( $confirm ) {
-            $ILIKE = sql_ilike();
-            $dupcategory = get_records_sql("SELECT * FROM {$CFG->prefix}glossary_categories WHERE name $ILIKE '$name' AND glossaryid=$glossary->id");
+            $dupcategory = get_records_sql("SELECT * FROM {$CFG->prefix}glossary_categories WHERE " . sql_olike('name', $name) . " AND glossaryid=$glossary->id");
             if ( $dupcategory ) {
                 echo "<p style=\"text-align:center\">" . get_string("add"). " " . get_string("category","glossary");
 
Index: mod/glossary/sql.php
===================================================================
--- mod/glossary/sql.php	(revision 140)
+++ mod/glossary/sql.php	(working copy)
@@ -134,10 +134,9 @@
 
         $where = '';
         $fullpivot = 0;
-        $LIKE = sql_ilike();
-        $NOTLIKE = 'NOT ' . $LIKE;
 
         switch ( $mode ) {
+      
         case 'search': 
 
             /// Some differences in syntax for PostgreSQL
@@ -184,9 +183,9 @@
                     $aliassearch .= " al.alias $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
                     $definitionsearch .= " ge.definition $NOTREGEXP '(^|[^a-zA-Z0-9])$searchterm([^a-zA-Z0-9]|$)' ";
                 } else {
-                    $conceptsearch .= " ge.concept $LIKE '%$searchterm%' ";
-                    $aliassearch .= " al.alias $LIKE '%$searchterm%' ";
-                    $definitionsearch .= " ge.definition $LIKE '%$searchterm%' ";
+                    $conceptsearch .= sql_olike('ge.concept', $searchterm);
+                    $aliassearch .= sql_olike('al.alias', $searchterm);
+                    $definitionsearch .= sql_olike('ge.definition', $searchterm);
                 }
             }
      
Index: mod/data/lib.php
===================================================================
--- mod/data/lib.php	(revision 140)
+++ mod/data/lib.php	(working copy)
@@ -1420,14 +1420,14 @@
 
 function data_fieldname_exists($name, $dataid, $fieldid=0) {
     global $CFG;
-    $LIKE = sql_ilike();
+    $LIKE = sql_olike('df.name', $name);
     if ($fieldid) {
         return record_exists_sql("SELECT * from {$CFG->prefix}data_fields df
-                                  WHERE df.name $LIKE '$name' AND df.dataid = $dataid
+                                  WHERE $LIKE AND df.dataid = $dataid
                                     AND ((df.id < $fieldid) OR (df.id > $fieldid))");
     } else {
         return record_exists_sql("SELECT * from {$CFG->prefix}data_fields df
-                                  WHERE df.name $LIKE '$name' AND df.dataid = $dataid");
+                                  WHERE $LIKE AND df.dataid = $dataid");
     }
 }
 
Index: mod/data/view.php
===================================================================
--- mod/data/view.php	(revision 140)
+++ mod/data/view.php	(working copy)
@@ -438,8 +438,6 @@
             $groupselect = ' ';
         }
 
-        $ilike = sql_ilike(); //Be case-insensitive
-
         // Init some variables to be used by advanced search
         $advsearchselect = '';
         $advwhere        = '';
@@ -485,7 +483,7 @@
             if (!empty($advanced)) {                                                  //If advanced box is checked.
                 foreach($search_array as $key => $val) {                              //what does $search_array hold?
                     if ($key == DATA_FIRSTNAME or $key == DATA_LASTNAME) {
-                        $searchselect .= " AND $val->field $ilike '%{$val->data}%'";
+                        $searchselect .= " AND " . sql_olike($val->field, $val->data);
                         continue;
                     }
                     $advtables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
@@ -493,7 +491,7 @@
                     $advsearchselect .= ' AND ('.$val->sql.') ';
                 }
             } else if ($search) {
-                $searchselect = " AND (cs.content $ilike '%$search%' OR u.firstname $ilike '%$search%' OR u.lastname $ilike '%$search%' ) ";
+                $searchselect = " AND (" . sql_olike('cs.content', $search) . " OR " . sql_olike('u.firstname', $search) . " OR " . sql_olike('u.lastname', $search) . ") ";
             } else {
                 $searchselect = ' ';
             }
@@ -522,7 +520,7 @@
             if (!empty($advanced)) {                                                  //If advanced box is checked.
                 foreach($search_array as $key => $val) {                              //what does $search_array hold?
                     if ($key == DATA_FIRSTNAME or $key == DATA_LASTNAME) {
-                        $searchselect .= " AND $val->field $ilike '%{$val->data}%'";
+                        $searchselect .= " AND " . sql_olike($val->field, $val->data);
                         continue;
                     }
                     $advtables .= ', '.$CFG->prefix.'data_content c'.$key.' ';
@@ -530,7 +528,7 @@
                     $advsearchselect .= ' AND ('.$val->sql.') ';
                 }
             } else if ($search) {
-                $searchselect = " AND (cs.content $ilike '%$search%' OR u.firstname $ilike '%$search%' OR u.lastname $ilike '%$search%' ) ";
+                $searchselect = " AND " . sql_olike('cs.content', $search) . " OR " . sql_olike('u.firstname', $search) . " OR " . sql_olike('u.lastname', $search) . ") ";
             } else {
                 $searchselect = ' ';
             }
@@ -572,7 +570,7 @@
         }
 
     /// Get the actual records
-        
+       
         if (!$records = get_records_sql($sqlselect, $page * $nowperpage, $nowperpage)) {
             // Nothing to show!
             if ($record) {         // Something was requested so try to show that at least (bug 5132)
Index: mod/data/field/file/field.class.php
===================================================================
--- mod/data/field/file/field.class.php	(revision 140)
+++ mod/data/field/file/field.class.php	(working copy)
@@ -75,7 +75,7 @@
     }
 
     function generate_sql($tablealias, $value) {
-        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') ";
+        return " ({$tablealias}.fieldid = {$this->field->id} AND " . sql_olike($tablealias . 'content', $value) . ") ";
     }
 
     function parse_search_field() {
Index: mod/data/field/multimenu/field.class.php
===================================================================
--- mod/data/field/multimenu/field.class.php	(revision 140)
+++ mod/data/field/multimenu/field.class.php	(working copy)
@@ -144,11 +144,12 @@
             foreach ($selected as $sel) {
                 $likesel = str_replace('%', '\%', $sel);
                 $likeselsel = str_replace('_', '\_', $likesel);
-                $conditions[] = "({$tablealias}.fieldid = {$this->field->id} AND ({$tablealias}.content = '$sel'
-                                                                               OR {$tablealias}.content LIKE '$likesel##%'
-                                                                               OR {$tablealias}.content LIKE '%##$likesel'
-                                                                               OR {$tablealias}.content LIKE '%##$likesel##%'))";
-            }
+                $conditions[] = "({$tablealias}.fieldid = {$this->field->id} AND (DBMS_LOB.SUBSTR({$tablealias}.content, 2000, 1) = '$sel'"
+                                                                               . " OR " . sql_olike($tablealias . '.content', "$likesel##", 3)
+                                                                               . " OR " . sql_olike($tablealias . '.content', "##$likesel", 4)
+                                                                               . " OR " . sql_olike($tablealias . '.content', "##$likesel##", 0)
+                                                                               . "))";
+            }print_r($conditions);
             if ($allrequired) {
                 return " (".implode(" AND ", $conditions).") ";
             } else {
Index: mod/data/field/url/field.class.php
===================================================================
--- mod/data/field/url/field.class.php	(revision 140)
+++ mod/data/field/url/field.class.php	(working copy)
@@ -63,7 +63,7 @@
     }
 
     function generate_sql($tablealias, $value) {
-        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') ";
+        return " ({$tablealias}.fieldid = {$this->field->id} AND " . sql_olike($tablealias . '.content', $value) . ") ";
     }
 
     function display_browse_field($recordid, $template) {
Index: mod/data/field/text/field.class.php
===================================================================
--- mod/data/field/text/field.class.php	(revision 140)
+++ mod/data/field/text/field.class.php	(working copy)
@@ -39,7 +39,7 @@
     }
     
     function generate_sql($tablealias, $value) {
-        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; 
+        return " ({$tablealias}.fieldid = {$this->field->id} AND " . sql_olike($tablealias . '.content', $value) . ") ";
     }
     
 }
Index: mod/data/field/checkbox/field.class.php
===================================================================
--- mod/data/field/checkbox/field.class.php	(revision 140)
+++ mod/data/field/checkbox/field.class.php	(working copy)
@@ -123,10 +123,11 @@
             foreach ($selected as $sel) {
                 $likesel = str_replace('%', '\%', $sel);
                 $likeselsel = str_replace('_', '\_', $likesel);
-                $conditions[] = "({$tablealias}.fieldid = {$this->field->id} AND ({$tablealias}.content = '$sel'
-                                                                               OR {$tablealias}.content LIKE '$likesel##%'
-                                                                               OR {$tablealias}.content LIKE '%##$likesel'
-                                                                               OR {$tablealias}.content LIKE '%##$likesel##%'))";
+                $conditions[] = "({$tablealias}.fieldid = {$this->field->id} AND (DBMS_LOB.SUBSTR({$tablealias}.content, 2000, 1) = '$sel'"
+                                                                               . " OR " . sql_olike($tablealias . '.content', $likesel, 3)
+                                                                               . " OR " . sql_olike($tablealias . '.content', $likesel, 4)
+                                                                               . " OR " . sql_olike($tablealias . '.content', $likesel, 0)
+                                                                               . "))";
             }
             if ($allrequired) {
                 return " (".implode(" AND ", $conditions).") ";
Index: mod/data/field/picture/field.class.php
===================================================================
--- mod/data/field/picture/field.class.php	(revision 140)
+++ mod/data/field/picture/field.class.php	(working copy)
@@ -72,7 +72,7 @@
     }
 
     function generate_sql($tablealias, $value) {
-        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') ";
+        return " ({$tablealias}.fieldid = {$this->field->id} AND " . sql_olike($tablealias . 'content', $value) . ") ";
     }
 
     function display_browse_field($recordid, $template) {
Index: mod/data/field/textarea/field.class.php
===================================================================
--- mod/data/field/textarea/field.class.php	(revision 140)
+++ mod/data/field/textarea/field.class.php	(working copy)
@@ -79,7 +79,7 @@
     }
     
     function generate_sql($tablealias, $value) {
-        return " ({$tablealias}.fieldid = {$this->field->id} AND {$tablealias}.content LIKE '%{$value}%') "; 
+        return " ({$tablealias}.fieldid = {$this->field->id} AND " . sql_olike($tablealias . 'content', $value) . ") ";
     }
     
     function gen_textarea($usehtmleditor, $text='') {
Index: mod/feedback/mapcourse.php
===================================================================
--- mod/feedback/mapcourse.php	(revision 140)
+++ mod/feedback/mapcourse.php	(working copy)
@@ -97,10 +97,10 @@
     echo '<input type="hidden" name="sesskey" value="'.$USER->sesskey.'" />';
     
     $sql = "select c.id, c.shortname from {$CFG->prefix}course c
-            where
-                c.shortname ".sql_ilike()." '%{$searchcourse}%'
-            OR c.fullname ".sql_ilike()." '%{$searchcourse}%'";
-    
+            where "
+            . sql_olike(c.shortname, $searchcourse)
+            . sql_olike(c.fullname, $searchcourse);
+echo $sql;
     if (($courses = get_records_sql_menu($sql)) && !empty($searchcourse)) {
         echo ' ' . get_string('courses') . ': ';
         choose_from_menu ($courses, 'coursefilter', $coursefilter, 'choose');
Index: mod/feedback/analysis_course.php
===================================================================
--- mod/feedback/analysis_course.php	(revision 140)
+++ mod/feedback/analysis_course.php	(working copy)
@@ -150,8 +150,9 @@
                                               'where c.id = fv.course_id and fv.item = fi.id '.
                                               'and fi.feedback = '.$feedback->id.' '.
                                               'and 
-                                              (c.shortname '.sql_ilike().' \'%'.$searchcourse.'%\'
-                                              OR c.fullname '.sql_ilike().' \'%'.$searchcourse.'%\')';
+                                              ('
+                                            . sql_olike(c.shortname, $searchcourse)
+                                            . sql_olike(c.fullname, $searchcourse) . ')';
         
         if ($courses = get_records_sql_menu($sql)) {
 
Index: mod/forum/db/postgres7.php
===================================================================
--- mod/forum/db/postgres7.php	(revision 140)
+++ mod/forum/db/postgres7.php	(working copy)
@@ -228,9 +228,9 @@
     
   if ($oldversion < 2006082700) {
       $sql = "UPDATE {$CFG->prefix}forum_posts SET message = REPLACE(message, '".TRUSTTEXT."', '');";
-      $likecond = sql_ilike()." '%".TRUSTTEXT."%'";
+      $likecond = sql_olike('message', TRUSTTEXT);
       while (true) {
-          if (!count_records_select('forum_posts', "message $likecond")) {
+          if (!count_records_select('forum_posts', $likecond)) {
               break;
           }
           execute_sql($sql);
Index: mod/forum/db/mysql.php
===================================================================
--- mod/forum/db/mysql.php	(revision 140)
+++ mod/forum/db/mysql.php	(working copy)
@@ -279,9 +279,9 @@
 
   if ($oldversion < 2006082700) {
       $sql = "UPDATE {$CFG->prefix}forum_posts SET message = REPLACE(message, '".TRUSTTEXT."', '');";
-      $likecond = sql_ilike()." '%".TRUSTTEXT."%'";
+      $likecond = sql_olike('message', TRUSTTEXT);
       while (true) {
-          if (!count_records_select('forum_posts', "message $likecond")) {
+          if (!count_records_select('forum_posts', $likecond)) {
               break;
           }
           execute_sql($sql);
Index: mod/forum/lib.php
===================================================================
--- mod/forum/lib.php	(revision 140)
+++ mod/forum/lib.php	(working copy)
@@ -1796,8 +1796,6 @@
     $selectdiscussion = "(".implode(" OR ", $where).")";
 
     // Some differences SQL
-    $LIKE = sql_ilike();
-    $NOTLIKE = 'NOT ' . $LIKE;
     if ($CFG->dbfamily == 'postgres') {
         $REGEXP = '~*';
         $NOTREGEXP = '!~*';
Index: mod/wiki/ewikimoodlelib.php
===================================================================
--- mod/wiki/ewikimoodlelib.php	(revision 140)
+++ mod/wiki/ewikimoodlelib.php	(working copy)
@@ -240,7 +240,7 @@
          $sql= "SELECT pagename AS id, version, flags" .
              (EWIKI_DBQUERY_BUFFER && ($field!="pagename") ? ", $field" : "") .
              " FROM " . $CFG->prefix.EWIKI_DB_TABLE_NAME .
-             " WHERE $field " . sql_ilike() . " '%".anydb_escape_string($content)."%'  and wiki=".$wiki_entry->id .
+             " WHERE " . sql_olike($field, anydb_escape_string($content)) . " and wiki=".$wiki_entry->id .
              " ORDER BY id, version ASC";
          $result=get_records_sql($sql);
 
Index: admin/report/spamcleaner/index.php
===================================================================
--- admin/report/spamcleaner/index.php	(revision 140)
+++ admin/report/spamcleaner/index.php	(working copy)
@@ -153,13 +153,11 @@
         $keywords = array($keywords);    // Make it into an array
     }
 
-    $like = sql_ilike();
-
     $keywordfull = array();
     foreach ($keywords as $keyword) {
         $keyword = addslashes($keyword);   // Just to be safe
-        $keywordfull[] = " description $like '%$keyword%' ";
-        $keywordfull2[] = " p.summary $like '%$keyword%' ";
+        $keywordfull[] = sql_olike('description', $keyword);
+        $keywordfull2[] = sql_olike('p.summary', $keyword);
     }
     $conditions = '( '.implode(' OR ', $keywordfull).' )';
     $conditions2 = '( '.implode(' OR ', $keywordfull2).' )';
Index: admin/roles/assign.php
===================================================================
--- admin/roles/assign.php	(revision 140)
+++ admin/roles/assign.php	(working copy)
@@ -281,10 +281,9 @@
         $searchtext = trim($searchtext);
 
         if ($searchtext !== '') {   // Search for a subset of remaining users
-            $LIKE      = sql_ilike();
             $FULLNAME  = sql_fullname();
 
-            $selectsql = " AND ($FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%') ";
+            $selectsql = " AND (" . sql_olike($FULLNAME, $searchtext) . " OR " . sql_olike('email', $searchtext) . ")";
             $select  .= $selectsql;
         } else {
             $selectsql = "";
Index: admin/upgradelogs.php
===================================================================
--- admin/upgradelogs.php	(revision 140)
+++ admin/upgradelogs.php	(working copy)
@@ -48,8 +48,6 @@
         $starttime = time();
         $sleeptime = 0;
 
-        $LIKE = sql_ilike();
-
         if ($cmcount > 10) {
             print_simple_box('This process may take a very long time ... please be patient and let it finish.',
                              'center', '', '#ffcccc');
@@ -68,14 +66,14 @@
                     if ($discussions = get_records("forum_discussions", "forum", $cm->instance)) {
                         foreach ($discussions as $discussion) {
                             execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
-                                         WHERE module = '$cm->name' AND url $LIKE 'discuss.php?d=$discussion->id%'", false);
+                                         WHERE module = '$cm->name' AND " . sql_olike('url', 'discuss.php?d=$discussion->id', 3), false);
                         }
                     }
                     break;
 
                 case "glossary":
                     execute_sql("UPDATE {$CFG->prefix}log SET cmid = '$cm->id'
-                                 WHERE module = '$cm->name' AND url $LIKE 'view.php?id=$cm->id%'", false);
+                                 WHERE module = '$cm->name' AND " . sql_olike('url', 'view.php?id=$cm->id%'), false);
                     break;
 
                 case "quiz":
Index: admin/mnet/enr_course_enrol.php
===================================================================
--- admin/mnet/enr_course_enrol.php	(revision 140)
+++ admin/mnet/enr_course_enrol.php	(working copy)
@@ -232,10 +232,9 @@
     $searchtext = trim($searchtext);
 
     if ($searchtext !== '') {   // Search for a subset of remaining users
-        $LIKE      = sql_ilike();
         $FULLNAME  = sql_fullname();
 
-        $select  .= " AND ($FULLNAME $LIKE '%$searchtext%' OR email $LIKE '%$searchtext%') ";
+        $select  .= " AND (" . sql_olike($FULLNAME, $searchtext) . " OR " . sql_olike('email', $searchtext) . ")";
     }
 
     $sql = ('SELECT id, firstname, lastname, email 
Index: user/index.php
===================================================================
--- user/index.php	(revision 140)
+++ user/index.php	(working copy)
@@ -443,9 +443,8 @@
     $wheresearch = '';
 
     if (!empty($search)) {
-        $LIKE = sql_ilike();
         $fullname  = sql_fullname('u.firstname','u.lastname');
-        $wheresearch .= ' AND ('. $fullname .' '. $LIKE .' \'%'. $search .'%\' OR email '. $LIKE .' \'%'. $search .'%\' OR idnumber '.$LIKE.' \'%'.$search.'%\') ';
+        $wheresearch .= ' AND ('. sql_olike($fullname, $search) . ' OR ' . sql_olike('email', $search) . ' OR ' . sql_olike('idnumber', $search) . ') ';
 
     }
 
Index: user/filters/courserole.php
===================================================================
--- user/filters/courserole.php	(revision 140)
+++ user/filters/courserole.php	(working copy)
@@ -99,7 +99,7 @@
             $where .= " AND c.category=$categoryid";
         }
         if ($value) {
-            $where .= " AND c.shortname ".sql_ilike()." '$value'";
+            $where .= " AND " . sql_olike('c.shortname', $value);
         }
         return "id IN (SELECT userid
                          FROM {$CFG->prefix}role_assignments a
Index: user/filters/profilefield.php
===================================================================
--- user/filters/profilefield.php	(revision 140)
+++ user/filters/profilefield.php	(working copy)
@@ -117,23 +117,19 @@
 
         $where = "";
         $op = " IN ";
-        $ilike = sql_ilike();
+        $olike = sql_olike('data', $value, $operator);
 
         if ($operator < 5 and $value === '') {
             return '';
         }
 
         switch($operator) {
-            case 0: // contains
-                $where = "data $ilike '%$value%'"; break;
-            case 1: // does not contain
-                $where = "data NOT $ilike '%$value%'"; break;
-            case 2: // equal to
-                $where = "data $ilike '$value'"; break;
-            case 3: // starts with
-                $where = "data $ilike '$value%'"; break;
+            case 0: // contains                
+            case 1: // does not contain                
+            case 2: // equal to               
+            case 3: // starts with               
             case 4: // ends with
-                $where = "data $ilike '%$value'"; break;
+                $where = "$olike"; break;
             case 5: // empty
                 $where = "data=''"; break;
             case 6: // is not defined
@@ -150,6 +146,7 @@
         if ($where !== '') {
             $where = "WHERE $where";
         }
+
         return "id $op (SELECT userid FROM {$CFG->prefix}user_info_data $where)";
     }
 
Index: user/filters/text.php
===================================================================
--- user/filters/text.php	(revision 140)
+++ user/filters/text.php	(working copy)
@@ -83,25 +83,8 @@
             return '';
         }
 
-        $ilike = sql_ilike();
-
-        switch($operator) {
-            case 0: // contains
-                $res = "$ilike '%$value%'"; break;
-            case 1: // does not contain
-                $res = "NOT $ilike '%$value%'"; break;
-            case 2: // equal to
-                $res = "$ilike '$value'"; break;
-            case 3: // starts with
-                $res = "$ilike '$value%'"; break;
-            case 4: // ends with
-                $res = "$ilike '%$value'"; break;
-            case 5: // empty
-                $res = "=''"; break;
-            default:
-                return '';
-        }
-        return $field.' '.$res;
+        
+        return sql_olike($field, $data['value'], $operator);
     }
 
     /**
