]> git.mjollnir.org Git - moodle.git/commitdiff
Added functions to retrieve the proper add and drop field SQL.
authorstronk7 <stronk7>
Tue, 12 Sep 2006 22:15:00 +0000 (22:15 +0000)
committerstronk7 <stronk7>
Tue, 12 Sep 2006 22:15:00 +0000 (22:15 +0000)
lib/xmldb/classes/generators/XMLDBGenerator.class.php

index 9fa7d1f475f0b41687a09a97d1e0be35e936cafe..7c7b6c75531268d81d61f7d813786cbfea442435 100644 (file)
@@ -453,6 +453,47 @@ class XMLDBgenerator {
         return $results;
     }
 
+    /**
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to add the field to the table
+     */
+    function getAddFieldSQL($xmldb_table, $xmldb_field) {
+
+        $results = array();
+
+    /// Get the quoted name of the table and field
+        $tablename = $this->getEncQuoted($this->prefix . $xmldb_table->getName());
+
+    /// Build the standard alter table add
+        $results[] = 'ALTER TABLE ' . $tablename . ' ADD ' . $this->getFieldSQL($xmldb_field);
+
+    /// If the DB has extra enum code
+        if ($this->enum_extra_code) {
+        /// If it's enum add the extra code
+            if ($xmldb_field->getEnum()) {
+                $results[] = 'ALTER TABLE ' . $tablename . ' ADD ' . $this->getEnumExtraSQL($xmldb_table, $xmldb_field);
+            }
+        }
+
+        return $results;
+    }
+
+    /**
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop the field from the table
+     */
+    function getDropFieldSQL($xmldb_table, $xmldb_field) {
+
+        $results = array();
+
+    /// Get the quoted name of the table and field
+        $tablename = $this->getEncQuoted($this->prefix . $xmldb_table->getName());
+        $fieldname = $this->getEncQuoted($xmldb_field->getName());
+
+    /// Build the standard alter table drop
+        $results[] = 'ALTER TABLE ' . $tablename . ' DROP COLUMN ' . $fieldname;
+
+        return $results;
+    }
+
     /**
      * Given three strings (table name, list of fields (comma separated) and suffix), create the proper object name
      * quoting it if necessary