From b4464372afc9af4c365b5c864bc4cd630fedda8d Mon Sep 17 00:00:00 2001
From: stronk7 <stronk7>
Date: Sat, 11 Aug 2007 21:50:25 +0000
Subject: [PATCH] Detect CHAR + NOT NULL FIELDS + '' (empty) defaults. They
 shouldn't be in XMLDB definitions at all. Convert the default to the proper
 one and output it via xmldb debug.

---
 lib/xmldb/classes/XMLDBField.class.php | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/lib/xmldb/classes/XMLDBField.class.php b/lib/xmldb/classes/XMLDBField.class.php
index 1d77b12dfe..3bcaa8df53 100644
--- a/lib/xmldb/classes/XMLDBField.class.php
+++ b/lib/xmldb/classes/XMLDBField.class.php
@@ -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'])) {
-- 
2.39.5