Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
A better way of doing chat_get_latest_message() that doesn't conflict
with the debugging in get_record_sql
  • Loading branch information
moodler committed Jul 25, 2003
1 parent 30e72d4 commit 5a8625e
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions mod/chat/lib.php
Expand Up @@ -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") {
Expand Down

0 comments on commit 5a8625e

Please sign in to comment.