Wednesday, September 18, 2013

Spotting a moodle $DB->get_records_sql bug or gotcha...

Over the summer, I helped talk my customer through a process change which improved one of her main workflow habits.  The short of it is this.  I introduced a custom display in the native moodle User grade report. I added the display of an *enrollment status letter, helping those viewing the User grade report know which students are active, completed or dropped at any given time during the year.







One of our teachers noted a few days ago that one of her students was NOT displaying in the drop down list.  When I opened the index.php file located at grade\report\user and looked at my SQL that I introduced to get the enrollment status, I remembered the requirement of using the moodle API function $DB->get_records_sql.

The FIRST COLUMN must be a unique value in the return set.  I have forgotten this more than once using this function.

I had first name as the first column in the SELECT list, there happened to be another student in the course with the same first name, so they were not included.  Im sure this bug was happening in other courses as well.  As soon as I moved the userid to the start of the SELECT list, the missing student magically appeared.

I need to remember this.

Moodle doc that states this.
Me lamenting this very thing previously.

No comments:

Post a Comment