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).

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

bart.hanssens’s picture

Might 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...)

paalj’s picture

Component: Code - Short/long answer » Code - Quiz core
Status: Active » Needs review
FileSize
1.22 KB

I 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.

djroshi’s picture

I have tested your patch and it does seem to address the divide by zero issue when deleting quiz questions so thank you.

Sivaji_Ganesh_Jojodae’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

Sivaji_Ganesh_Jojodae’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work

Comment #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.

djdevin’s picture

Status: Needs work » Closed (outdated)

This 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.