Skip to content

Commit

Permalink
Fixing bug 3977: sort of. Check for mysql >= 4 or postgres, do a smar…
Browse files Browse the repository at this point in the history
…ter query with a UNION. Otherwise, do the same old query. This is not very good for mysql 3.23 users with large datasets, but not much else I can do.
  • Loading branch information
mjollnir_ committed Aug 31, 2005
1 parent e2629fc commit 18c26f9
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
22 changes: 22 additions & 0 deletions lib/datalib.php
Expand Up @@ -2972,5 +2972,27 @@ function sql_isnull($fieldname) {
}
}

/**
* Checks for pg or mysql > 4
*/

function check_db_compat() {
global $CFG,$db;

if ($CFG->dbtype == 'postgres7') {
return true;
}

if (!$rs = $db->Execute("SELECT version();")) {
return false;
}

if (intval($rs->fields[0]) <= 3) {
return false;
}

return true;
}

// vim:autoindent:expandtab:shiftwidth=4:tabstop=4:tw=140:
?>
13 changes: 12 additions & 1 deletion message/lib.php
Expand Up @@ -1023,7 +1023,10 @@ function message_get_participants() {

global $CFG;

return get_records_sql("SELECT DISTINCT u.id, u.id
// the first query is VERY intensive on large dbs, but
// the second won't work with mysql < 4
if (!check_db_compat()) {
return get_records_sql("SELECT DISTINCT u.id, u.id
FROM {$CFG->prefix}user as u,
{$CFG->prefix}message as m,
{$CFG->prefix}message_read as mr,
Expand All @@ -1034,6 +1037,14 @@ function message_get_participants() {
OR mr.useridto = u.id
OR mc.userid = u.id
OR mc.contactid = u.id");
} else {
return get_records_sql("SELECT useridfrom,useridfrom FROM {$CFG->prefix}message
UNION SELECT useridto,useridto FROM {$CFG->prefix}message
UNION SELECT useridfrom,useridfrom FROM {$CFG->prefix}message_read
UNION SELECT useridto,useridto FROM {$CFG->prefix}message_read
UNION SELECT userid,userid FROM {$CFG->prefix}message_contacts
UNION SELECT contactid,contactid from {$CFG->prefix}message_contacts");
}
}

?>

0 comments on commit 18c26f9

Please sign in to comment.