]> git.mjollnir.org Git - moodle.git/commitdiff
Added getDefaultValue() for better handling of default values
authorstronk7 <stronk7>
Sun, 1 Oct 2006 15:47:48 +0000 (15:47 +0000)
committerstronk7 <stronk7>
Sun, 1 Oct 2006 15:47:48 +0000 (15:47 +0000)
lib/xmldb/classes/generators/XMLDBGenerator.class.php

index 113dd3261f801ac9c79e644691827bb76ba21478..36f8980300800cab26e5fc7abb9a3831f67fdde0 100644 (file)
@@ -428,19 +428,18 @@ class XMLDBgenerator {
     }
 
     /**
-     * Give one XMLDBField, returns the correct "default clause" for the current configuration
+     * Give one XMLDBField, returns the correct "default value" for the current configuration
      */
-    function getDefaultClause ($xmldb_field) {
+    function getDefaultValue ($xmldb_field) {
 
-        $default = '';
+        $default = null;
 
         if ($xmldb_field->getDefault() != NULL) {
-            $default = ' DEFAULT ';
             if ($xmldb_field->getType() == XMLDB_TYPE_CHAR ||
                 $xmldb_field->getType() == XMLDB_TYPE_TEXT) {
-                    $default .= "'" . addslashes($xmldb_field->getDefault()) . "'";
+                    $default = "'" . addslashes($xmldb_field->getDefault()) . "'";
             } else {
-                $default .= $xmldb_field->getDefault();
+                $default = $xmldb_field->getDefault();
             }
         } else {
         /// We force default '' for not null char columns without proper default
@@ -448,20 +447,34 @@ class XMLDBgenerator {
             if ($this->default_for_char !== NULL &&
                 $xmldb_field->getType() == XMLDB_TYPE_CHAR &&
                 $xmldb_field->getNotNull()) {
-                $default = ' DEFAULT ' . "'" . $this->default_for_char . "'";
+                $default = "'" . $this->default_for_char . "'";
             } else {
             /// If the DB requires to explicity define some clause to drop one default, do it here
             /// never applying defaults to TEXT and BINARY fields
                 if ($this->drop_default_clause_required &&
                     $xmldb_field->getType() != XMLDB_TYPE_TEXT &&
                     $xmldb_field->getType() != XMLDB_TYPE_BINARY && !$xmldb_field->getNotNull()) {
-                    $default = ' DEFAULT ' . $this->drop_default_clause;
+                    $default = $this->drop_default_clause;
                 }
             }
         }
         return $default;
     }
 
+    /**
+     * Given one XMLDBField, returns the correct "default clause" for the current configuration
+     */
+    function getDefaultClause ($xmldb_field) {
+
+        $defaultvalue = $this->getDefaultValue ($xmldb_field);
+
+        if ($defaultvalue !== null) {
+            return ' DEFAULT ' . $defaultvalue;
+        } else {
+            return null;
+        }
+    }
+
     /**
      * Given one correct XMLDBTable and the new name, returns the SQL statements
      * to rename it (inside one array)