]> git.mjollnir.org Git - moodle.git/commitdiff
A better way of doing chat_get_latest_message() that doesn't conflict
authormoodler <moodler>
Fri, 25 Jul 2003 09:01:02 +0000 (09:01 +0000)
committermoodler <moodler>
Fri, 25 Jul 2003 09:01:02 +0000 (09:01 +0000)
with the debugging in get_record_sql

mod/chat/lib.php

index a875d435b33c0cd7e107c1a3a9c5c30325019a74..a4629a0dcab349df34e4db7f2d55269ea64814ab 100644 (file)
@@ -183,15 +183,27 @@ function chat_get_users($chatid) {
 }
 
 function chat_get_latest_message($chatid) {
+/// Efficient way to extract just the latest message
+/// Uses ADOdb directly instead of get_record_sql()
+/// because the LIMIT command causes problems with 
+/// the developer debugging in there.
 
-    global $CFG;
+    global $db, $CFG;
 
-    return get_record_sql("SELECT *
-                             FROM {$CFG->prefix}chat_messages 
-                            WHERE chatid = '$chatid' 
-                         ORDER BY timestamp DESC");
+    if (!$rs = $db->Execute("SELECT *
+                               FROM {$CFG->prefix}chat_messages 
+                              WHERE chatid = '$chatid' 
+                           ORDER BY timestamp DESC LIMIT 1")) {
+        return false;
+    }
+    if ($rs->RecordCount() == 1) {
+        return (object)$rs->fields;
+    } else {
+        return false;                 // Found no records
+    }
 }
 
+
 //////////////////////////////////////////////////////////////////////
 
 function chat_login_user($chatid, $version="header_js") {