Moodle

Manual grading view does not work on PostgreSQL

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: 1.9, 1.9.1, 1.9.2
  • Fix Version/s: 1.9.3
  • Component/s: Quiz
  • Labels:
    None
  • Environment:
    Postgres
  • Database:
    PostgreSQL
  • Affected Branches:
    MOODLE_19_STABLE
  • Fixed Branches:
    MOODLE_19_STABLE

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

Activity

Hide
Tim Hunt added a comment -

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.

Show
Tim Hunt added a comment - 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.

People

Vote (0)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: