]> git.mjollnir.org Git - moodle.git/commitdiff
Detect CHAR + NOT NULL FIELDS + '' (empty) defaults. They shouldn't be in
authorstronk7 <stronk7>
Sat, 11 Aug 2007 21:50:25 +0000 (21:50 +0000)
committerstronk7 <stronk7>
Sat, 11 Aug 2007 21:50:25 +0000 (21:50 +0000)
XMLDB definitions at all. Convert the default to the proper one and
output it via xmldb debug.

lib/xmldb/classes/XMLDBField.class.php

index 1d77b12dfe42ffd47d964f62ab7d2d9aba9eed51..3bcaa8df53f3eeac38657bc7e52c0b1a64574262 100644 (file)
@@ -93,7 +93,7 @@ class XMLDBField extends XMLDBObject {
                 $this->enumvalues[] = $value;
             }
         }
-        $this->default = $default;
+        $this->setDefault($default);
 
         $this->previous = $previous;
     }
@@ -230,6 +230,13 @@ class XMLDBField extends XMLDBObject {
      * Set the field default
      */
     function setDefault($default) {
+    /// Check, warn and auto-fix '' (empty) defaults for CHAR NOT NULL columns, changing them
+    /// to NULL so XMLDB will apply the proper default
+        if ($this->type == XMLDB_TYPE_CHAR && $this->notnull && $default === '') {
+            $this->errormsg = 'XMLDB has detected one CHAR NOT NULL column (' . $this->name . ") with '' (empty string) as DEFAULT value. This type of columns must have one meaningful DEFAULT declared or none (NULL). XMLDB have fixed it automatically changing it to none (NULL). The process will continue ok and proper defaults will be created accordingly with each DB requirements. Please fix it in source (XML and/or upgrade script) to avoid this message to be displayed.";
+            $this->debug($this->errormsg);
+            $default = NULL;
+        }
         $this->default = $default;
     }
 
@@ -346,7 +353,7 @@ class XMLDBField extends XMLDBObject {
         }
 
         if (isset($xmlarr['@']['DEFAULT'])) {
-            $this->default = trim($xmlarr['@']['DEFAULT']);
+            $this->setDefault(trim($xmlarr['@']['DEFAULT']));
         }
 
         if (isset($xmlarr['@']['ENUM'])) {