]> git.mjollnir.org Git - moodle.git/commitdiff
Bah, Oracle requires the default clause BEFORE the not null clause.
authorstronk7 <stronk7>
Wed, 16 Aug 2006 23:45:18 +0000 (23:45 +0000)
committerstronk7 <stronk7>
Wed, 16 Aug 2006 23:45:18 +0000 (23:45 +0000)
lib/xmldb/classes/generators/XMLDBGenerator.class.php
lib/xmldb/classes/generators/oci8po/oci8po.class.php

index bc90e79ca614b5fdee432deb3b21cee063c87125..7bcc0c263436b52ca7aa2045636f1f9b38e416b0 100644 (file)
@@ -49,6 +49,8 @@ class XMLDBgenerator {
     var $unsigned_allowed = true;    // To define in the generator must handle unsigned information
     var $default_for_char = null;      // To define the default to set for NOT NULLs CHARs without default (null=do nothing)
 
+    var $default_after_null = true;  //To decide if the default clause of each field must go after the null clause
+
     var $primary_key_name = null; //To force primary key names to one string (null=no force)
 
     var $primary_keys = true;  // Does the generator build primary keys
@@ -274,9 +276,17 @@ class XMLDBgenerator {
                 $field .= ' unsigned';
             }
         }
-    /// The not null
+    /// Calculate the not null clause
         if ($xmldb_field->getNotNull()) {
-            $field .= ' NOT NULL';
+            $notnull = ' NOT NULL';
+        }
+    /// Calculate the default clause
+        $default = $this->getDefaultClause($xmldb_field);
+    /// Based on default_after_null, set both clauses properly
+        if ($this->default_after_null) {
+            $field .= $notnull . $default;
+        } else {
+            $field .= $default . $notnull;
         }
     /// The sequence
         if ($xmldb_field->getSequence()) {
@@ -287,24 +297,6 @@ class XMLDBgenerator {
                 return $this->getEncQuoted($xmldb_field->getName()) . ' ' . $this->sequence_name;
             }
         }
-    /// The default
-        if ($xmldb_field->getDefault() != NULL) {
-            $field .= ' default ';
-            if ($xmldb_field->getType() == XMLDB_TYPE_CHAR ||
-                $xmldb_field->getType() == XMLDB_TYPE_TEXT) {
-                    $field .= "'" . $xmldb_field->getDefault() . "'";
-            } else {
-                $field .= $xmldb_field->getDefault();
-            }
-        } else {
-        /// We force default '' for not null char columns without proper default
-        /// some day this should be out!
-            if ($this->default_for_char !== NULL && 
-                $xmldb_field->getType() == XMLDB_TYPE_CHAR &&
-                $xmldb_field->getNotNull()) {
-                $field .= ' default ' . "'" . $this->default_for_char . "'";
-            }
-        }
         return $field;
     }
 
@@ -337,7 +329,7 @@ class XMLDBgenerator {
                 if ($this->foreign_keys) {
                     $key = $this->getNameForObject($xmldb_table->getName(), implode(', ', $xmldb_key->getFields()), 'fk');
                     $key .= ' FOREIGN KEY (' . implode(', ', $this->getEncQuoted($xmldb_key->getFields())) . ')';
-                    $key .= ' REFERENCES ' . $this->getEncQuoted($xmldb_key->getRefTable());
+                    $key .= ' REFERENCES ' . $this->getEncQuoted($this->prefix . $xmldb_key->getRefTable());
                     $key .= ' (' . implode(', ', $this->getEncQuoted($xmldb_key->getRefFields())) . ')';
                 }
                 break;
@@ -346,6 +338,33 @@ class XMLDBgenerator {
         return $key;
     }
 
+    /**
+     * Give one XMLDBField, returns the correct "default clause" for the current configuration
+     */
+    function getDefaultClause ($xmldb_field) {
+
+        $default = '';
+
+        if ($xmldb_field->getDefault() != NULL) {
+            $default = ' default ';
+            if ($xmldb_field->getType() == XMLDB_TYPE_CHAR ||
+                $xmldb_field->getType() == XMLDB_TYPE_TEXT) {
+                    $default .= "'" . $xmldb_field->getDefault() . "'";
+            } else {
+                $default .= $xmldb_field->getDefault();
+            }
+        } else {
+        /// We force default '' for not null char columns without proper default
+        /// some day this should be out!
+            if ($this->default_for_char !== NULL && 
+                $xmldb_field->getType() == XMLDB_TYPE_CHAR &&
+                $xmldb_field->getNotNull()) {
+                $default .= ' default ' . "'" . $this->default_for_char . "'";
+            }
+        }
+        return $default;
+    }
+
     /**
      * Given three strings (table name, list of fields (comma separated) and suffix), create the proper object name
      */
index 396ba3250602cc514333b95bb943b71ad5b08362..769add5c1ab93410e27eb32fea78697a457d386a 100644 (file)
@@ -37,6 +37,8 @@ class XMLDBoci8po extends XMLDBgenerator {
     var $unsigned_allowed = false;    // To define in the generator must handle unsigned information
     var $default_for_char = '';      // To define the default to set for NOT NULLs CHARs without default (null=do nothing)
 
+    var $default_after_null = false;  //To decide if the default clause of each field must go after the null clause
+
     var $foreign_keys = false; // Does the generator build foreign keys
 
     var $primary_index = false;// Does the generator need to build one index for primary keys