]> git.mjollnir.org Git - moodle.git/commitdiff
Instead of looking for current default value, fetch from
authorstronk7 <stronk7>
Sat, 11 Aug 2007 21:47:22 +0000 (21:47 +0000)
committerstronk7 <stronk7>
Sat, 11 Aug 2007 21:47:22 +0000 (21:47 +0000)
the generator the *real* default value that the table will have.

lib/ddllib.php

index 81946bf4730190bd73db231cf2389b2c0f75d943..7a2b21df647eecaca4b596d24e75c4a8d311dbde 100644 (file)
@@ -319,7 +319,7 @@ function field_exists($table, $field) {
         $exists = false;
     }
 
-/// Re-set original debug 
+/// Re-set original debug
     $db->debug = $olddbdebug;
 
     return $exists;
@@ -348,7 +348,7 @@ function index_exists($table, $index) {
         $exists = false;
     }
 
-/// Re-set original debug 
+/// Re-set original debug
     $db->debug = $olddbdebug;
 
     return $exists;
@@ -746,14 +746,20 @@ function add_field($table, $field, $continue=true, $feedback=true) {
         return false;
     }
 
+/// Load the needed generator
+    $classname = 'XMLDB' . $CFG->dbtype;
+    $generator = new $classname();
+    $generator->setPrefix($CFG->prefix);
+
 /// Check the field doesn't exist
     if (field_exists($table, $field)) {
         debugging('Field ' . $field->getName() . ' exists. Create skipped', DEBUG_DEVELOPER);
         return true;
     }
 
-/// If NOT NULL and no default given, check the table is empty
-    if ($field->getNotNull() && $field->getDefault() === NULL && count_records($table->getName())) {
+/// If NOT NULL and no default given (we ask the generator about the
+/// *real* default that will be used) check the table is empty
+    if ($field->getNotNull() && $generator->getDefaultValue($field) === 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;
     }