Moodle

can't use the word null in a question answer

Details

  • Type: Bug Bug
  • Status: Closed Closed
  • Priority: Minor Minor
  • Resolution: Fixed
  • Affects Version/s: 1.7
  • Fix Version/s: 1.7, 1.8
  • Component/s: Questions
  • Labels:
    None
  • Environment:
    IE and FF - but i suspect it's on the server, actually...

Description

When you have a question that has the word NULL as a possible answer, it causes weird behaviour.

This manifested itself first at school with 1.5.4.. where a question in a python class had null as the answer. I think the teacher had imported the test using GIFT, and probably had never previewed it. When one tried to take the test, ti simply wouldn't display. Thru some lengthy trial and error I isolated it down to a question that had blank answers, but for which null would have been one good answer. When i put it in, the question could not save, or saved but led to the error.

I just tried it in 1.7 and found this:
When you create a fresh question, putting the word null, without quote, lower-case, it gives this error:
Column 'answer' cannot be null

INSERT INTO mdl_question_answers ( QUESTION, ANSWER, FRACTION, FEEDBACK ) VALUES ( 3, null, -1, '' )

if you continue you go back to the site home page.

What's peculiar is that with enough going back and forth you can actually get the value to save (i.e. by editing the question after it did not save successfully, so it may be unique to an INSERT situation, while UPDATE may work fine. This theory is further confirmed by the fact that i was able to EDIT a question to include the word null, but when I saved it as a new question, it choked as before.

This does not seem to apply to upper-case NULL, and is not a problem if the answer is in quotes.

Issue Links

Activity

Hide
Tim Hunt added a comment -

This is actually caused by what I consider a bug in the database abstraction layer. I've asked Eloy what he thinks the best way to solve it is.

Show
Tim Hunt added a comment - This is actually caused by what I consider a bug in the database abstraction layer. I've asked Eloy what he thinks the best way to solve it is.
Hide
Martin Dougiamas added a comment -

This will probably need changes to adodb or insert_record, which we really want to try to avoid at this stage, and will probably be fixed by the prepared statements work in 1.8 anyway.

Bumping to 1.8

Show
Martin Dougiamas added a comment - This will probably need changes to adodb or insert_record, which we really want to try to avoid at this stage, and will probably be fixed by the prepared statements work in 1.8 anyway. Bumping to 1.8
Hide
Eloy Lafuente (stronk7) added a comment -

Just adding some info to this about the reply posted by ADOdb guy:

http://phplens.com/lens/lensforum/msgs.php?id=15902

Perhaps we should consider to upgrade, if released, and use the trick specified by John? That release of ADOdb is expected to fix some other bugs currently in code (problems detecting PG version, MetaXXX improvements..).

For your consideration. Ciao

Show
Eloy Lafuente (stronk7) added a comment - Just adding some info to this about the reply posted by ADOdb guy: http://phplens.com/lens/lensforum/msgs.php?id=15902 Perhaps we should consider to upgrade, if released, and use the trick specified by John? That release of ADOdb is expected to fix some other bugs currently in code (problems detecting PG version, MetaXXX improvements..). For your consideration. Ciao
Hide
Petr Škoda (skodak) added a comment -

new adodb v4.93 is in HEAD, it should be possible to solve it now

Show
Petr Škoda (skodak) added a comment - new adodb v4.93 is in HEAD, it should be possible to solve it now
Hide
Tim Hunt added a comment -

Eloy, I am proposing to commit the patch:

Index: lib/setup.php
===================================================================
RCS file: /cvsroot/moodle/moodle/lib/setup.php,v
retrieving revision 1.181
diff -u -r1.181 setup.php
— lib/setup.php 9 Oct 2006 10:12:42 -0000 1.181
+++ lib/setup.php 17 Oct 2006 10:57:39 -0000
@@ -119,6 +119,10 @@

$db = &ADONewConnection($CFG->dbtype);

+ // See MDL-6760 for why this is necessary. In Moodle 1.8, once we start using NULLs properly,
+ // we probably want to change this value to ''.
+ $db->null2null = 'A long random string that will never, ever match something we want to insert into the database, I hope. \'';
+
error_reporting(0); // Hide errors

if (!isset($CFG->dbpersist) or !empty($CFG->dbpersist)) { // Use persistent connection (default)

Is that OK with you?

Show
Tim Hunt added a comment - Eloy, I am proposing to commit the patch: Index: lib/setup.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/setup.php,v retrieving revision 1.181 diff -u -r1.181 setup.php — lib/setup.php 9 Oct 2006 10:12:42 -0000 1.181 +++ lib/setup.php 17 Oct 2006 10:57:39 -0000 @@ -119,6 +119,10 @@ $db = &ADONewConnection($CFG->dbtype); + // See MDL-6760 for why this is necessary. In Moodle 1.8, once we start using NULLs properly, + // we probably want to change this value to ''. + $db->null2null = 'A long random string that will never, ever match something we want to insert into the database, I hope. \''; + error_reporting(0); // Hide errors if (!isset($CFG->dbpersist) or !empty($CFG->dbpersist)) { // Use persistent connection (default) Is that OK with you?
Hide
Eloy Lafuente (stronk7) added a comment -

I think yes! Go, go, go...

Show
Eloy Lafuente (stronk7) added a comment - I think yes! Go, go, go...
Hide
Tim Hunt added a comment -

I left it for a while to to make sure nothing else seemed broken. Now it is checkid in. Yay!

It's a pity we can't backport the fix to Moodle 1.6.

Show
Tim Hunt added a comment - I left it for a while to to make sure nothing else seemed broken. Now it is checkid in. Yay! It's a pity we can't backport the fix to Moodle 1.6.
Hide
Ken Wilson added a comment -

Confirmed OK in testing (possible combinations in a multiple choice quiz: NULL, null, NOT NULL). Thanks. Now closed.

Show
Ken Wilson added a comment - Confirmed OK in testing (possible combinations in a multiple choice quiz: NULL, null, NOT NULL). Thanks. Now closed.

Dates

  • Created:
    Updated:
    Resolved: