After creating a quiz and adding one short answer question to it, I cannot delete the question. When I attempt to do so, I get the following error:
PDOException: SQLSTATE[22012]: Division by zero: 1365 Division by 0: UPDATE {quiz_node_results} SET score=ROUND( 100 * ( SELECT COALESCE (SUM(a.points_awarded), 0) FROM {quiz_node_results_answers} a WHERE a.result_id = {quiz_node_results}.result_id ) / ( SELECT max_score FROM {quiz_node_properties} qnp WHERE qnp.vid = {quiz_node_results}.vid ) ) WHERE (vid IN (:db_condition_placeholder_0, :db_condition_placeholder_1, :db_condition_placeholder_2)) ; Array ( [:db_condition_placeholder_0] => 8 [:db_condition_placeholder_1] => 11 [:db_condition_placeholder_2] => ) in quiz_update_max_score_properties() (line 2610 of [snipped]/sites/all/modules/quiz/quiz.module).
Comment | File | Size | Author |
---|---|---|---|
#2 | quiz-unable_to_delete_last_question-1728390-2.patch | 1.22 KB | paalj |
Comments
Comment #1
bart.hanssens CreditAttribution: bart.hanssens commentedMight work on other systems, depending on the configuration of MySQL (not tested on PostgreSQL)
(http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html#sqlmode_erro...)
Comment #2
paalj CreditAttribution: paalj commentedI have analyzed this one.
To reproduce this, the quiz must have been taken. I.e, there must exist at least one related row in the quiz_node_results table. The same problem applies to all question types, and happens when the last question for a quiz is deleted.
The problem lies in the way quiz_update_max_score_properties function (quiz.module). The SQL in the last db_update() gets zero as max_score and uses it as then denominator in a division. Therefore we get a division by zero...
The patch attached solves this in the SQL by checking if the max_score is zero. If so, zero is "returned" instead of doing the division.
Comment #3
djroshi CreditAttribution: djroshi commentedI have tested your patch and it does seem to address the divide by zero issue when deleting quiz questions so thank you.
Comment #4
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae commentedFixed along #1537814: Delete content multichoice error.
Comment #6
Sivaji_Ganesh_Jojodae CreditAttribution: Sivaji_Ganesh_Jojodae commentedComment #4 is misunderstanding. This issue still needs work. Patch in comment #2 is the best of solutions we have now, else need to think about rewriting nested sql query.
Comment #7
djdevinThis issue is being closed because it was filed against a version that is no longer supported. If the issue still persists in the latest version of Quiz, please open a new issue.