Here's what I did to reproduce:
1. Prior to creating the any quiz, I have created a number of true/false and multiple choice questions (I manually had to enter the score for the correct answer because that too would cause an error if left out)
2. Create new quiz, leaving default options (also no questions), providing just a title
3. Save quiz
4. Click on the edit tab and update *any* information
5. Get the following error:

PDOException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'max_score' cannot be null: UPDATE {quiz_node_properties} SET max_score=max_score_for_random * number_of_random_questions + ( SELECT SUM(max_score) FROM {quiz_node_relationship} qnr WHERE qnr.question_status = 1 AND parent_vid = quiz_node_properties.vid) WHERE (vid IN (:db_condition_placeholder_0)) ; Array ( [:db_condition_placeholder_0] => 1009 ) in quiz_update_max_score_properties() (line 2574 of /var/www/www.iprhelpdesk.eu/htdocs/sites/all/modules/quiz/quiz.module).

I also get this error when I try to add questions. Basically I cannot save a modified quiz. This is a vanilla install on Drupal 7.12

Comments

dkliewer’s picture

Status: Needs review » Active
george.plescan’s picture

Same error for max_score on any CRUD for the quiz.

I tried to look at the queries, not much I can say.

I was lucky to have a older dev version which is working.

Can't blame the developers, there is so much to do to make a good testing platform.

lzimmerman’s picture

I added the following to quiz.module at the end of the quiz_validate($node) function for debugging:

if (is_null($max_score_for_random)) {
form_set_error('max_score_for_random', t('No max score is set for random questions.' . $max_score_result));
}

I'm guessing that the failing SQL query is the following, from quiz_update_max_score_properties($quizzes_to_update):

  db_update('quiz_node_properties')
    ->expression('max_score', 'max_score_for_random * number_of_random_questions + (
      SELECT SUM(max_score)
      FROM {quiz_node_relationship} qnr
      WHERE qnr.question_status = ' . QUESTION_ALWAYS . '
      AND parent_vid = quiz_node_properties.vid)')
    ->condition('vid', $quizzes_to_update, 'IN')
    ->execute();

The calculation would fail if "max_score_for_random" in "max_score_for_random * number_of_random_questions" were null.

I have temporarily fixed the problem by replacing the db_update above (around line 2566), adding a conditional which checks whether $max_score_for_random is null (drupal messages set for debugging). If $max_score_random is null, it sets a 'default' of 1 (value from quiz.install):

   // DEBUG: Conditional for null max_score_for_random
  if (!is_null($max_score_for_random)) {
  drupal_set_message("Max score is not NULL; updated.");
  db_update('quiz_node_properties')
    ->expression('max_score', 'max_score_for_random * number_of_random_questions + (
      SELECT SUM(max_score)
      FROM {quiz_node_relationship} qnr
      WHERE qnr.question_status = ' . QUESTION_ALWAYS . '
      AND parent_vid = quiz_node_properties.vid)')
    ->condition('vid', $quizzes_to_update, 'IN')
    ->execute();
  }
  else {
  drupal_set_message("Max score is NULL. Set manually to 1");
	 db_update('quiz_node_properties')
    ->expression('max_score', '1')
    ->condition('vid', $quizzes_to_update, 'IN')
    ->execute();
  }

I'm not sure whether this will have detrimental effects on other quiz behavior (will max_score be set properly if legitimate values become available?), but it did allow my test quiz (one multiple-choice question) to function.

There's probably a deeper error here, and maybe this workaround will help with debugging.

falcon’s picture

Status: Active » Fixed

Fixed, thanks

Status: Fixed » Closed (fixed)

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

  • Commit 8aa37d0 on 7.x-4.x, 7.x-5.x by falcon:
    fixed #1516424 reported by dkliewer: PDOexception when updating a quiz
    
    

  • Commit 8aa37d0 on 7.x-4.x, 7.x-5.x, quiz-pages by falcon:
    fixed #1516424 reported by dkliewer: PDOexception when updating a quiz
    
    

  • Commit 8aa37d0 on 7.x-4.x, 7.x-5.x, quiz-pages, 2269219 by falcon:
    fixed #1516424 reported by dkliewer: PDOexception when updating a quiz
    
    

  • Commit 8aa37d0 on 7.x-4.x, 7.x-5.x, 2269219 by falcon:
    fixed #1516424 reported by dkliewer: PDOexception when updating a quiz