Details
Description
When you try to view the Manual grading view in a quiz, you see no attempts. If you look in the pgsql logs, you see:
ERROR: function sum(boolean) does not exist
HINT: No function matches the given name and argument types. You may need to add explicit type casts.
STATEMENT: SELECT qs.question, COUNT(1) AS totalattempts, SUM(qs.event IN (3,6,9)) AS gradedattempts FROM mdl_quiz_attempts qa, mdl_question_sessions qns, mdl_question_states qs WHERE qa.quiz = 7880 AND qa.userid IN (131639,16,15,13) AND qns.attemptid = qa.uniqueid AND qns.newgraded = qs.id AND qs.question IN (381795) GROUP BY qs.question
The offending statement is in mod/quiz/report/reportlib.php - quiz_get_total_qas_graded_and_ungraded
In order to fix it, we need to cast to an integer type, but of course MySQL supports a different type then the other supported DB. So I changed (starting at line 57):
function quiz_get_total_qas_graded_and_ungraded($quiz, $questionids, $userids){
global $CFG;
$sql = "SELECT qs.question, COUNT(1) AS totalattempts, " .
"SUM(CAST((qs.event IN (".QUESTION_EVENTS_GRADED.")) AS signed)) AS gradedattempts " .
"FROM " .
To:
function quiz_get_total_qas_graded_and_ungraded($quiz, $questionids, $userids){
global $CFG;
if ($CFG->dbfamily == 'mysql') {
$inttype = 'SIGNED';
} else {
$inttype = 'INT';
}
$sql = "SELECT qs.question, COUNT(1) AS totalattempts, " .
"SUM(CAST((qs.event IN (".QUESTION_EVENTS_GRADED.")) AS ".$inttype.")) AS gradedattempts " .
"FROM " .
Thoughts?
Issue Links
| This issue is duplicated by: | ||||
| MDL-15165 | Essay quiz Manual grading "these are no attempts to show" when there are actually attempts |
|
|
|
The correct fix is actually
SUM(CASE WHEN (qs.event IN (".QUESTION_EVENTS_GRADED.")) THEN 1 ELSE 0 END) AS gradedattempts
This was already done in 2.0 dev. Backporting.