commit 76b1e0d6c97035a2d4e1619a446c65fce1608e06
Author: Jonathon Fowler <fowlerj@usq.edu.au>
Date:   Thu Dec 23 10:56:22 2010 +1000

    Oracle sql fixes in search function
    
     * no 'AS' in table aliases
     * CLOB comparison needs sql_compare_text
     * Oracle does not understand building queries via parameter substitution

diff --git a/search/documents/chat_document.php b/search/documents/chat_document.php
index e4cf354..3ad25e1 100644
--- a/search/documents/chat_document.php
+++ b/search/documents/chat_document.php
@@ -97,10 +97,18 @@ function chat_get_session_tracks($chat_id, $fromtime = 0, $totime = 0) {
         $groupmode = $course->groupmode;
     }
 
-    $fromtimeclause = ($fromtime) ? "AND timestamp >= {$fromtime}" : '';
-    $totimeclause = ($totime) ? "AND timestamp <= {$totime}" : '';
+    $clause = "chatid = :chatid";
+    $params = array('chatid' => $chat_id);
+    if ($fromtime) {
+        $clause .= " AND timestamp >= :fromtime";
+        $params['fromtime'] = $fromtime;
+    }
+    if ($totime) {
+        $clause .= " AND timestamp <= :totime";
+        $params['totime'] = $totime;
+    }
     $tracks = array();
-    $messages = $DB->get_records_select('chat_messages', "chatid = :chatid :from :to", array('chatid' => $chat_id, 'from' => $fromtimeclause, 'to' => $totimeclause), 'timestamp DESC');
+    $messages = $DB->get_records_select('chat_messages', $clause, $params, 'timestamp DESC');
     if ($messages){
         // splits discussions against groups
         $groupedMessages = array();
diff --git a/search/documents/data_document.php b/search/documents/data_document.php
index 499a922..5d194e7 100644
--- a/search/documents/data_document.php
+++ b/search/documents/data_document.php
@@ -122,8 +122,8 @@ function data_get_records($database_id, $typematch = '*', $recordid = 0) {
         SELECT
            c.*
         FROM 
-            {data_content} as c,
-            {data_records} as r
+            {data_content} c,
+            {data_records} r
         WHERE
             c.recordid = r.id AND
             r.dataid = ? 
@@ -166,9 +166,9 @@ function data_get_comments($database_id) {
           c.timecreated,
           r.dataid
        FROM
-          {data_records} as r
+          {data_records} r
        JOIN
-          {comments} as c ON c.contextid = r.id
+          {comments} c ON c.contextid = r.id
        WHERE
           r.dataid = ?
     ";
@@ -438,4 +438,4 @@ function data_link_post_processing($title){
     return mb_convert_encoding($title, 'auto', 'UTF-8');
 }
 
-?>
\ No newline at end of file
+?>
diff --git a/search/documents/resource_document.php b/search/documents/resource_document.php
index 529d762..f0641d3 100644
--- a/search/documents/resource_document.php
+++ b/search/documents/resource_document.php
@@ -94,16 +94,17 @@ function resource_get_content_for_index(&$notneeded) {
 
     // the resources have been moved into modules of their own. indexing need to be created for these.
     // for a temporary fix (until MDL-24856 is fixed) pointing this query to a table that is copy of the old resource table schema.
+    $alltext = $DB->sql_compare_text('alltext');
     $query = "
         SELECT 
             id as trueid,
             r.*
         FROM 
-            {resource_old} as r
+            {resource_old} r
         WHERE
-            alltext != '' AND
-            alltext != ' ' AND
-            alltext != '&nbsp;' AND
+            $alltext != '' AND
+            $alltext != ' ' AND
+            $alltext != '&nbsp;' AND
             type != 'file'
     ";
     if ($resources = $DB->get_records_sql($query)){ 
@@ -136,9 +137,9 @@ function resource_get_content_for_index(&$notneeded) {
                r.type as type,
                r.timemodified as timemodified
             FROM 
-                {resource_old} as r,
-                {course_modules} as cm,
-                {modules} as m
+                {resource_old} r,
+                {course_modules} cm,
+                {modules} m
             WHERE 
                r.type = 'file' AND
                cm.instance = r.id AND
@@ -237,6 +238,7 @@ function resource_single_document($id, $itemtype) {
     global $CFG, $DB;
     
     // rewriting with legacy moodle databse API
+    $ralltext = $DB->sql_compare_text('r.alltext');
     $query = "
         SELECT 
            r.id as trueid,
@@ -249,18 +251,18 @@ function resource_single_document($id, $itemtype) {
            r.type as type,
            r.timemodified as timemodified
         FROM 
-            {resource} as r,
-            {course_modules} as cm,
-            {modules} as m
+            {resource} r,
+            {course_modules} cm,
+            {modules} m
         WHERE 
             cm.instance = r.id AND
             cm.course = r.course AND
             cm.module = m.id AND
             m.name = 'resource' AND
             ((r.type != 'file' AND
-            r.alltext != '' AND 
-            r.alltext != ' ' AND 
-            r.alltext != '&nbsp;') OR 
+            $ralltext != '' AND 
+            $ralltext != ' ' AND 
+            $ralltext != '&nbsp;') OR 
             r.type = 'file') AND 
             r.id = '?'
     ";
@@ -360,4 +362,4 @@ function resource_link_post_processing($title){
     }
     return mb_convert_encoding($title, 'auto', 'UTF-8');
 }
-?>
\ No newline at end of file
+?>
