Permalink
Browse files

MDL-26416 avoid subtracting two unsigned ints, which breaks MySQL sin…

…ce 5.5.5.
  • Loading branch information...
timhunt committed Feb 18, 2011
1 parent bbc2d0b commit 19a9f1124d03be35efae735639911f4c94b8407f
Showing with 9 additions and 1 deletion.
  1. +9 −1 mod/quiz/report/overview/report.php
@@ -220,7 +220,15 @@ function display($quiz, $cm, $course) {
qa.sumgrades,
qa.timefinish,
qa.timestart,
- qa.timefinish - qa.timestart AS duration';
+ CASE WHEN qa.timefinish = 0 THEN null
+ WHEN qa.timefinish > qa.timestart THEN qa.timefinish - qa.timestart
+ ELSE 0 END AS duration';
+ // To explain that last bit, in MySQL, qa.timestart and qa.timefinish
+ // are unsigned. Since MySQL 5.5.5, when they introduced strict mode,
+ // subtracting a larger unsigned int from a smaller one gave an error.
+ // Therefore, we avoid doing that. timefinish can be non-zero and less
+ // than timestart when you have two load-balanced servers with very
+ // badly synchronised clocks, and a student does a really quick attempt.
// This part is the same for all cases - join users and quiz_attempts tables
$from = '{user} u ';

0 comments on commit 19a9f11

Please sign in to comment.