]> git.mjollnir.org Git - moodle.git/commitdiff
data, forum, glossary: use sql_ilike() for a portable LIKE operator
authormartinlanghoff <martinlanghoff>
Tue, 26 Sep 2006 05:08:18 +0000 (05:08 +0000)
committermartinlanghoff <martinlanghoff>
Tue, 26 Sep 2006 05:08:18 +0000 (05:08 +0000)
mod/data/lib.php
mod/forum/lib.php
mod/glossary/sql.php

index 373771abf162b9890a1390d69f9be104b0c847d4..9d494070ae96293471474b17c011a7bec882a852 100755 (executable)
@@ -1223,13 +1223,14 @@ function data_get_post_actions() {
 function data_fieldname_exists($name, $dataid, $fieldid=0) {
     global $CFG;
 
+    $LIKE = sql_ilike();
     if ($fieldid) { 
         return record_exists_sql("SELECT * from {$CFG->prefix}data_fields AS df 
-                                  WHERE df.name LIKE '$name' AND df.dataid = $dataid
+                                  WHERE df.name $LIKE '$name' AND df.dataid = $dataid
                                     AND ((df.id < $fieldid) OR (df.id > $fieldid))");
     } else {
         return record_exists_sql("SELECT * from {$CFG->prefix}data_fields AS df 
-                                  WHERE df.name LIKE '$name' AND df.dataid = $dataid");
+                                  WHERE df.name $LIKE '$name' AND df.dataid = $dataid");
     }
 }
 
index 0c959b295646460e16003332f0c3ebccb8e8071c..4d1b13498fc578d56efd2ff46bfb9660237c9b0f 100644 (file)
@@ -755,6 +755,7 @@ function forum_user_complete($course, $user, $mod, $forum) {
 
 function forum_print_overview($courses,&$htmlarray) {
     global $USER, $CFG;
+    $LIKE = sql_ilike();
 
     if (empty($courses) || !is_array($courses) || count($courses) == 0) {
         return array();
@@ -774,7 +775,7 @@ function forum_print_overview($courses,&$htmlarray) {
     }
     $sql = substr($sql,0,-3); // take off the last OR
 
-    $sql .= ") AND l.module = 'forum' AND action LIKE 'add post%' "
+    $sql .= ") AND l.module = 'forum' AND action $LIKE 'add post%' "
         ." AND userid != ".$USER->id." GROUP BY cmid,l.course,instance";
     
     if (!$new = get_records_sql($sql)) {
@@ -856,6 +857,7 @@ function forum_print_recent_activity($course, $isteacher, $timestart) {
 /// messages posted in the course since that date
 
     global $CFG;
+    $LIKE = sql_ilike();
 
     $heading = false;
     $content = false;
@@ -863,7 +865,7 @@ function forum_print_recent_activity($course, $isteacher, $timestart) {
     if (!$logs = get_records_select('log', 'time > \''.$timestart.'\' AND '.
                                            'course = \''.$course->id.'\' AND '.
                                            'module = \'forum\' AND '.
-                                           'action LIKE \'add %\' ', 'time ASC')){
+                                           'action $LIKE \'add %\' ', 'time ASC')){
         return false;
     }
 
@@ -1264,15 +1266,13 @@ function forum_search_posts($searchterms, $courseid=0, $limitfrom=0, $limitnum=5
     $selectdiscussion .= ")";
 
 
-    // Some differences in syntax for PostgreSQL.
+    // Some differences SQL
+    $LIKE = sql_ilike();
+    $NOTLIKE = 'NOT ' . $LIKE;
     if ($CFG->dbtype == 'postgres7') {
-        $LIKE = 'ILIKE';           // Case-insensitive
-        $NOTLIKE = 'NOT ILIKE';    // Case-insensitive
         $REGEXP = '~*';
         $NOTREGEXP = '!~*';
-    } else {                       // Note the LIKE are casesensitive for Oracle. Oracle 10g is required to use 
-        $LIKE = 'LIKE';            // the caseinsensitive search using regexp_like() or NLS_COMP=LINGUISTIC :-(
-        $NOTLIKE = 'NOT LIKE';     // See http://docs.moodle.org/en/XMLDB_Problems#Case-insensitive_searches
+    } else {
         $REGEXP = 'REGEXP';
         $NOTREGEXP = 'NOT REGEXP';
     }
index 16ef6da89d77397684b9e0354e024c8cd00383dd..64dd5d06fe6e192a90c5aedde55ee21a045536b4 100644 (file)
 
         $where = '';
         $fullpivot = 0;
-        if ($CFG->dbtype == "postgres7") {
-            $LIKE = "ILIKE";   // case-insensitive
-        } else {
-            $LIKE = "LIKE";
-        }
+        $LIKE = sql_ilike();
+        $NOTLIKE = 'NOT ' . $LIKE;
 
         switch ( $mode ) {
         case 'search': 
 
             /// Some differences in syntax for PostgreSQL
             if ($CFG->dbtype == "postgres7") {
-                $LIKE = "ILIKE";   // case-insensitive
-                $NOTLIKE = "NOT ILIKE";   // case-insensitive
                 $REGEXP = "~*";
                 $NOTREGEXP = "!~*";
             } else {
-                $LIKE = "LIKE";
-                $NOTLIKE = "NOT LIKE";
                 $REGEXP = "REGEXP";
                 $NOTREGEXP = "NOT REGEXP";
             }