Moodle
  1. Moodle
  2. MDL-9265

Can't create a true/false question: I get --> Could not insert quiz answer "true")! error

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Critical Critical
    • Resolution: Duplicate
    • Affects Version/s: 1.8
    • Fix Version/s: None
    • Component/s: Questions
    • Labels:
      None
    • Environment:
      moodle 1.8+
      sunos
      mysql database
    • Database:
      MySQL
    • Affected Branches:
      MOODLE_18_STABLE
    • Rank:
      7935

      Description

      When i make a new true/false question, i get error: Could not insert quiz answer "true")!
      Adding an echo to the truefalse/questiontype.php database send me the error --> Column 'fraction' cannot be null

      I think that the problem has in the new variable correctaswer, that send 'null' to the fraction:

      $true->fraction = $question->correctanswer;

      All tables are correct.
      Any idea?

      Raül

        Issue Links

          Activity

          Hide
          Tim Hunt added a comment -

          This is a known issue, caused by not deleting redundant files when uploading. This thread has more details, including information about what you need to do to solve the problem.

          http://moodle.org/mod/forum/discuss.php?d=68051#p308427

          Show
          Tim Hunt added a comment - This is a known issue, caused by not deleting redundant files when uploading. This thread has more details, including information about what you need to do to solve the problem. http://moodle.org/mod/forum/discuss.php?d=68051#p308427
          Hide
          James Dugal added a comment -

          Tim, can we re-open this report? I have a testbed installation of 1.8+ (tarball of 5/23/07) and encountered the same inability to add a t/f question from a Blackboard V6+ import. I got the same error on the screen (Could not insert quiz answer "true"). I also found these messages in the Apache error log:
          ===============
          [Wed May 30 14:48:03 2007] [error] PHP Notice: Undefined property: correctanswer in /var/www/htdocs/moodle18/question/type/truefalse/questiontype.php on line 38
          [Wed May 30 14:48:03 2007] [error] PHP Notice: Column 'fraction' cannot be null<br /><br />INSERT INTO mdl_question_answers ( QUESTION, ANSWER, FRACTION, FEEDBACK ) VALUES ( 230, 'True', null, '' )<ul style="text-align: left"><li>line 1419 of lib/dmllib.php: call to debugging()</li><li>line 40 of question/type/truefalse/questiontype.php: call to insert_record()</li><li>line 211 of question/format.php: call to question_truefalse_qtype->save_question_options()</li><li>line 176 of question/import.php: call to qformat_blackboard_6->importprocess()</li></ul> in /var/www/htdocs/moodle18/lib/weblib.php on line 5876
          [Wed May 30 14:48:03 2007] [error] DEBUG2: question/type/truefalse/questiontype.php: Column 'fraction' cannot be null
          ===========
          (the last message was a debug command I added per your advice ... line numbers are thus changed).

          So the fundamental problem is that $question->correctanswer is undefined, and thus instead of assigning a zero to $true->fraction, it assigns a NULL value. But NULLs are not allowed in the mdl_question_answers table (fraction column). I first changed the two affected lines to
          $true->fraction = (int)$question->correctanswer;

          which will work, but does log an undefined variable msg to the Apache error log. I then used
          $true->fraction = isset($question->correctanswer) ? (int)$question->correctanswer : 0;

          I suspect a better solution would be to track down why $question->correctanswer is not defined, instead of being defined as zero.

          Regards,
          – James

          Show
          James Dugal added a comment - Tim, can we re-open this report? I have a testbed installation of 1.8+ (tarball of 5/23/07) and encountered the same inability to add a t/f question from a Blackboard V6+ import. I got the same error on the screen (Could not insert quiz answer "true"). I also found these messages in the Apache error log: =============== [Wed May 30 14:48:03 2007] [error] PHP Notice: Undefined property: correctanswer in /var/www/htdocs/moodle18/question/type/truefalse/questiontype.php on line 38 [Wed May 30 14:48:03 2007] [error] PHP Notice: Column 'fraction' cannot be null<br /><br />INSERT INTO mdl_question_answers ( QUESTION, ANSWER, FRACTION, FEEDBACK ) VALUES ( 230, 'True', null, '' )<ul style="text-align: left"><li>line 1419 of lib/dmllib.php: call to debugging()</li><li>line 40 of question/type/truefalse/questiontype.php: call to insert_record()</li><li>line 211 of question/format.php: call to question_truefalse_qtype->save_question_options()</li><li>line 176 of question/import.php: call to qformat_blackboard_6->importprocess()</li></ul> in /var/www/htdocs/moodle18/lib/weblib.php on line 5876 [Wed May 30 14:48:03 2007] [error] DEBUG2: question/type/truefalse/questiontype.php: Column 'fraction' cannot be null =========== (the last message was a debug command I added per your advice ... line numbers are thus changed). So the fundamental problem is that $question->correctanswer is undefined, and thus instead of assigning a zero to $true->fraction, it assigns a NULL value. But NULLs are not allowed in the mdl_question_answers table (fraction column). I first changed the two affected lines to $true->fraction = (int)$question->correctanswer; which will work, but does log an undefined variable msg to the Apache error log. I then used $true->fraction = isset($question->correctanswer) ? (int)$question->correctanswer : 0; I suspect a better solution would be to track down why $question->correctanswer is not defined, instead of being defined as zero. Regards, – James
          Hide
          Tim Hunt added a comment -

          Howard, this looks like something you have already fixed. Why would people still be experiencing problems? I'm confused, which is why I am asking you.

          Show
          Tim Hunt added a comment - Howard, this looks like something you have already fixed. Why would people still be experiencing problems? I'm confused, which is why I am asking you.
          Hide
          James Dugal added a comment -

          I feel I should add this update: my proposed work-around can't reliably set the correct answer! All the T/F answers in me meagre test cases seem to be "false" which can't be right!
          --James

          Show
          James Dugal added a comment - I feel I should add this update: my proposed work-around can't reliably set the correct answer! All the T/F answers in me meagre test cases seem to be "false" which can't be right! --James
          Hide
          Howard Miller added a comment -

          Attached is a replacement for question/format/blackboard_6/format.php

          Could somebody replace the file in their (1.8) install and see if it helps.

          Show
          Howard Miller added a comment - Attached is a replacement for question/format/blackboard_6/format.php Could somebody replace the file in their (1.8) install and see if it helps.

            People

            • Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: