I have the following problem. I've switched on logging of failed SQL queries is moodle (cool feature BTW).
As a result in my error log I have hundreds of lines like these:
[Wed Nov 29 12:26:01 2006] [error] [client 88.88.888.888] SQL Duplicate entry '0-2515' for key 2 in /var/moodle/mod/quiz/locallib.php on line 470. STATEMENT: INSERT INTO mdl_question_sessions ( QUESTIONID, NEWEST, NEWGRADED ) VALUES ( 2515, 589065, 589065 ), referer: http://site.domain.name.pl/mod/quiz/index.php?id=82
[Wed Nov 29 12:26:01 2006] [error] [client 88.88.888.888] SQL Duplicate entry '0-2516' for key 2 in /var/moodle/mod/quiz/locallib.php on line 470. STATEMENT: INSERT INTO mdl_question_sessions ( QUESTIONID, NEWEST, NEWGRADED ) VALUES ( 2516, 589066, 589066 ), referer: http://site.domain.name.pl/mod/quiz/index.php?id=82
[Wed Nov 29 12:26:01 2006] [error] [client 88.88.888.888] SQL Duplicate entry '0-2517' for key 2 in /var/moodle/mod/quiz/locallib.php on line 470. STATEMENT: INSERT INTO mdl_question_sessions ( QUESTIONID, NEWEST, NEWGRADED ) VALUES ( 2517, 589067, 589067 ), referer: http://site.domain.name.pl/mod/quiz/index.php?id=82
[Wed Nov 29 12:26:01 2006] [error] [client 88.88.888.888] SQL Duplicate entry '0-2518' for key 2 in /var/moodle/mod/quiz/locallib.php on line 470. STATEMENT: INSERT INTO mdl_question_sessions ( QUESTIONID, NEWEST, NEWGRADED ) VALUES ( 2518, 589068, 589068 ), referer: http://site.domain.name.pl/mod/quiz/index.php?id=82
[Wed Nov 29 12:26:01 2006] [error] [client 88.88.888.888] SQL Duplicate entry '0-2519' for key 2 in /var/moodle/mod/quiz/locallib.php on line 470. STATEMENT: INSERT INTO mdl_question_sessions ( QUESTIONID, NEWEST, NEWGRADED ) VALUES ( 2519, 589069, 589069 ), referer: http://site.domain.name.pl/mod/quiz/index.php?id=82
[Wed Nov 29 12:26:01 2006] [error] [client 88.88.888.888] SQL Duplicate entry '0-2520' for key 2 in /var/moodle/mod/quiz/locallib.php on line 470. STATEMENT: INSERT INTO mdl_question_sessions ( QUESTIONID, NEWEST, NEWGRADED ) VALUES ( 2520, 589070, 589070 ), referer: http://site.domain.name.pl/mod/quiz/index.php?id=82
The offending records from mdl_question_sessions are shown in the attachement.
The function, which is causing the problem is somehow connected with the upgrade to newer "quiz model", but I am not sure how it is working.
Our students have some problems while saving their quiz attempts, maybe there is some connection with this?
Is there any way to avoid this error, like correcting the source code or cleaning the database in a right way?
I am using Moodle 1.6.3+ (version from 26.11.2006) upgraded from 1.6.1+, which was upgraded from 1.4.X on Linux Gentoo with Mysql 5 (using InnoDB tables) and PHP 5.
Thank you for help in advance.
The problem is the 0 in the attemptid column, but I have no idea how those values came to be zero. It would be helpful if you could investigate where these are coming from.
I think, I've fund the problem:
File: /mod/quiz/locallib.php,
Function: quiz_upgrade_states(..)
[line ~450] states:
(*) $newest->attemptid = $attempt->uniqueid;
$questionlist = quiz_questions_in_quiz($attempt->layout);
if ($questionlist and $states = get_records_select('question_states', "attempt = '$attempt->uniqueid' AND question IN ($questionlist)")) {
foreach ($states as $state) {
$session->newgraded = $state->id;
$session->newest = $state->id;
$session->questionid = $state->question;
insert_record('question_sessions', $session, false);
}
The problem is that $session->attemptid ==null.
$newest->attemptid (*) is not null, and it's not used. Changing it to $session->attemptid =... seems to solve the problem.
File: /mod/quiz/locallib.php,
Function: quiz_upgrade_states(..)
[line ~450] states:
(*) $newest->attemptid = $attempt->uniqueid;
$questionlist = quiz_questions_in_quiz($attempt->layout);
if ($questionlist and $states = get_records_select('question_states', "attempt = '$attempt->uniqueid' AND question IN ($questionlist)")) {
foreach ($states as $state) {
$session->newgraded = $state->id;
$session->newest = $state->id;
$session->questionid = $state->question;
insert_record('question_sessions', $session, false);
}
The problem is that $session->attemptid ==null.
$newest->attemptid (*) is not null, and it's not used. Changing it to $session->attemptid =... seems to solve the problem.