]> git.mjollnir.org Git - moodle.git/commitdiff
Prevent add_field() to work if we are adding one not null field
authorstronk7 <stronk7>
Sat, 21 Oct 2006 18:19:47 +0000 (18:19 +0000)
committerstronk7 <stronk7>
Sat, 21 Oct 2006 18:19:47 +0000 (18:19 +0000)
to one non-empty table without specifying its default value.

Merged from MOODLE_17_STABLE

lib/ddllib.php

index ea316768e94bad863dcdc4d4d3271e559a4f4d1a..5166994653087547f9f02c88acc890a2586e8d4a 100644 (file)
@@ -678,6 +678,12 @@ function add_field($table, $field, $continue=true, $feedback=true) {
         return true;
     }
 
+/// If NOT NULL and no default given, check the table is empty
+    if ($field->getNotNull() && $field->getDefault() === NULL && count_records($table->getName())) {
+        debugging('Field ' . $field->getName() . ' cannot be added. Not null fields added to non empty tables require default value. Create skipped', DEBUG_DEVELOPER);
+         return true;
+    }
+
     if(!$sqlarr = $table->getAddFieldSQL($CFG->dbtype, $CFG->prefix, $field, false)) {
         return true; //Empty array = nothing to do = no error
     }