Details
-
Type:
Bug
-
Status:
Closed
-
Priority:
Minor
-
Resolution: Won't Fix
-
Affects Version/s: 1.8.2
-
Fix Version/s: None
-
Component/s: Exercise
-
Labels:None
-
Environment:Linux, Apache 2, MySQL 5.0.27, PHP 5.1.6, Moodle 1.8.2+ (2007021520)
-
Database:MySQL
-
Affected Branches:MOODLE_18_STABLE
Description
When going to the Grades page I get an SQL syntax error. The traceback goes to the exercise_get_best_submission_grades() function in mod/exercise/locallib.php. The current code (MOODLE_18_STABLE) of the function reads as follows:
function exercise_get_best_submission_grades($exercise) {
// Returns the grades of students' best submissions
global $CFG;
// make sure it works on the site course
$select = "u.course = '$exercise->course' AND";
if ($exercise->course == SITEID) {
$select = '';
}
return get_records_sql("SELECT DISTINCT s.userid, MAX(a.grade) AS grade FROM
{$CFG->prefix}exercise_submissions s,
{$CFG->prefix}exercise_assessments a
WHERE $select
AND s.exerciseid = $exercise->id
AND s.late = 0
AND a.submissionid = s.id
GROUP BY s.userid");
}
According to the CVS log several inconsistencies were introduced in the 1.22 revision of locallib.php (http://eu.cvs.moodle.org/moodle/moodle/mod/exercise/locallib.php?r1=1.21&r2=1.22&pathrev=MOODLE_18_STABLE).
1) The $select variable ends with an 'AND'; the WHERE clause starts 'WHERE $select AND s.exerciseid = $exercise->id'; so two ANDs stand next to each other.
2) The $select variable contains the 'u.course' reference but the main SQL statement does not give the 'u' alias name.
If I get it right, the function can be shortened to this (patch attached):
function exercise_get_best_submission_grades($exercise) {
// Returns the grades of students' best submissions
global $CFG;
return get_records_sql("SELECT DISTINCT s.userid, MAX(a.grade) AS grade FROM
{$CFG->prefix}exercise_submissions s,
{$CFG->prefix}exercise_assessments a
WHERE s.exerciseid = $exercise->id
AND s.late = 0
AND a.submissionid = s.id
GROUP BY s.userid");
}
Exercise ist not longer supported in 1.8 ... did you install the modul manually?
Peter