Infinite loop in auth_db_sync_users.php

Re: Infinite loop in auth_db_sync_users.php

by C Lopez -
Number of replies: 0
I have been looking into this, and it is my feeling that the LEFT JOIN command is theoretically correct, but the problem (in my case, anyway) is that versions pf MySQL before 5.0.1 do not support nested joins. Here we have a command of the form

SELECT * FROM RA LEFT JOIN (C, CN)

And this is a form that explicitly not allowed in MySQL prior to 5.0.1. Basically, these versions of MySQL will just ignore the parentheses. That's what's resulting in this crazy behavior.

Since Moodle is supposed to support MySQL 4.1, the query will have to be rewritten. I think a query of the form

SELECT * FROM RA LEFT JOIN CN LEFT JOIN C

That is,

"SELECT ra.roleid, ra.userid, ra.contextid
FROM {$CFG->prefix}role_assignments ra
LEFT JOIN {$CFG->prefix}context cn
ON ra.contextid = cn.id AND cn.contextlevel = ".CONTEXT_COURSE."
LEFT JOIN {$CFG->prefix}course c ON cn.instanceid = c.id
WHERE ra.enrol = 'database'" .....

will do what was intended here, though it may not be formally equivalent.