moodle/enrol/category/locallib.php NULL queries

moodle/enrol/category/locallib.php NULL queries

by Ehsan Anwar -
Number of replies: 1

Hi All,

We using moodle 3.1.2 for our production.  Within the file moodle/enrol/category/locallib.php there are a few queries stating .id IS NULL.  Example below.  Can someone explain the reason NULL is being used?

"SELECT DISTINCT ue.userid

              FROM {user_enrolments} ue

         LEFT JOIN {role_assignments} ra ON (ra.roleid $roleids AND ra.contextid $contextids AND ra.userid = ue.userid)

             WHERE ue.enrolid = :instanceid AND ra.id IS NULL";

On our database, running the query select * from mdl_role_assignments where id = null; does not returning anything so a little confused why it is part of the code.

Another example is in forum https://moodle.org/mod/forum/discuss.php?d=153059 where someone shared a query to list all students not enrolled on a course stating where r.id =NULL

SELECT 'u'.'id', 'u'.'username', 'u'.'firstname', 'u'.'lastname', 'u'.'email' FROM 'mdl_user' 'u' LEFT JOIN 'mdl_role_assignments 'r' ON 'r'.'userid' = 'u'.'id' WHERE 'r'.'id' IS NULL AND 'u'.'deleted' = 0

Thanks

Ehsan

Average of ratings: -
In reply to Ehsan Anwar

Re: moodle/enrol/category/locallib.php NULL queries

by Howard Miller -
Picture of Core developers Picture of Documentation writers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

It's not a select as such, it's a 'left join'. It's asking for where the id field of role_assignments is NULL, i.e. the field doesn't exist.