]> git.mjollnir.org Git - moodle.git/commitdiff
Added support to change_field_enum() across all RDBMS
authorstronk7 <stronk7>
Sat, 30 Sep 2006 17:03:17 +0000 (17:03 +0000)
committerstronk7 <stronk7>
Sat, 30 Sep 2006 17:03:17 +0000 (17:03 +0000)
lib/xmldb/classes/XMLDBTable.class.php
lib/xmldb/classes/generators/XMLDBGenerator.class.php
lib/xmldb/classes/generators/mssql/mssql.class.php
lib/xmldb/classes/generators/mysql/mysql.class.php
lib/xmldb/classes/generators/oci8po/oci8po.class.php
lib/xmldb/classes/generators/postgres7/postgres7.class.php

index 79c5027b475d41ab9210fed57c99e0b614adc0a0..11c9c1e0e241a0620dd3d644293db8d307209f25 100644 (file)
@@ -891,6 +891,24 @@ class XMLDBTable extends XMLDBObject {
         return $results;
     }
 
+    /**
+     * This function will return the SQL code needed to modify the enum of one field in the table for the specified DB and
+     * prefix. Just one simple wrapper over generators.
+     */
+    function getModifyEnumSQL ($dbtype, $prefix, $xmldb_field, $statement_end=true) {
+
+        $results = array();
+
+        $classname = 'XMLDB' . $dbtype;
+        $generator = new $classname();
+        $generator->setPrefix($prefix);
+        $results = $generator->getModifyEnumSQL($this, $xmldb_field);
+        if ($statement_end) {
+            $results = $generator->getEndedStatements($results);
+        }
+        return $results;
+    }
+
     /**
      * This function will return the SQL code needed to modify the default of one field in the table for the specified DB and
      * prefix. Just one simple wrapper over generators.
index 5a2fe8721d1687d01373ac00d62b35e62b7845ce..feae0b6ba07a897c4032df984ed096a6aef6d5ff 100644 (file)
@@ -577,7 +577,28 @@ class XMLDBgenerator {
 
     /// Add the after clause if necesary
         if ($this->add_after_clause && $xmldb_field->getPrevious()) {
-            $altertable .= ' after ' . $this->getEncQuoted($xmldb_field->getPrevious());
+            $alter .= ' after ' . $this->getEncQuoted($xmldb_field->getPrevious());
+        }
+
+        return $results;
+    }
+
+    /**
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to modify the enum of the field in the table
+     */
+    function getModifyEnumSQL($xmldb_table, $xmldb_field) {
+
+        $results = array();
+
+    /// Get the quoted name of the table and field
+        $tablename = $this->getTableName($xmldb_table);
+        $fieldname = $this->getEncQuoted($xmldb_field->getName());
+
+    /// Decide if we are going to create or to drop the enum (based exclusively in the values passed!)
+        if (!$xmldb_field->getEnum()) {
+            $results = $this->getDropEnumSQL($xmldb_table, $xmldb_field); //Drop
+        } else {
+            $results = $this->getCreateEnumSQL($xmldb_table, $xmldb_field); //Create/modify
         }
 
         return $results;
@@ -971,6 +992,22 @@ class XMLDBgenerator {
         return array('Code for table drop goes to getDropTableExtraSQL(). Can be disabled with drop_table_extra_code=false;');
     }
 
+    /**
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */
+    function getDropEnumSQL($xmldb_table, $xmldb_field) {
+        return array('Code to drop one enum goes to getDropEnumSQL()');
+    }
+
+    /**
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to add its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */
+    function getCreateEnumSQL($xmldb_table, $xmldb_field) {
+        return array('Code to create one enum goes to getCreateEnumSQL()');
+    }
+
     /**
      * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its default 
      * (usually invoked from getModifyDefaultSQL()
@@ -984,7 +1021,7 @@ class XMLDBgenerator {
      * (usually invoked from getModifyDefaultSQL()
      */
     function getCreateDefaultSQL($xmldb_table, $xmldb_field) {
-        return array('Code to create one default goes to getCreate()');
+        return array('Code to create one default goes to getCreateDefaultSQL()');
     }
 
     /**
index 912e62260633a672d78fbc88c7f5ea0217ae7b98..761556cdb726d0b08a6a26b0db0eaa1b056a37da 100644 (file)
@@ -250,6 +250,26 @@ class XMLDBmssql extends XMLDBgenerator {
         return $results;
     }
 
+    /**
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */
+    function getCreateEnumSQL($xmldb_table, $xmldb_field) {
+    /// All we have to do is to create the check constraint
+        return array('ALTER TABLE ' . $this->getTableName($xmldb_table) .
+                     ' ADD ' . $this->getEnumExtraSQL($xmldb_table, $xmldb_field));
+    }
+
+    /**     
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */
+    function getDropEnumSQL($xmldb_table, $xmldb_field) {
+    /// All we have to do is to drop the check constraint
+        return array('ALTER TABLE ' . $this->getTableName($xmldb_table) .
+                     ' DROP CONSTRAINT ' . $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck'));
+    }
+
     /**
      * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its default 
      * (usually invoked from getModifyDefaultSQL()
index fd052e01365d58dba79c9bb58630c490e177b0ff..99c7b1cc2cc28e82d44990b18447d63e0915986f 100644 (file)
@@ -160,6 +160,24 @@ class XMLDBmysql extends XMLDBGenerator {
         return $dbtype;
     }
 
+    /**
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */
+    function getCreateEnumSQL($xmldb_table, $xmldb_field) {
+    /// For MySQL, just alter the field
+        return $this->getAlterFieldSQL($xmldb_table, $xmldb_field);
+    }
+
+    /**     
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */
+    function getDropEnumSQL($xmldb_table, $xmldb_field) {
+    /// For MySQL, just alter the field
+        return $this->getAlterFieldSQL($xmldb_table, $xmldb_field);
+    }
+
     /**
      * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its default 
      * (usually invoked from getModifyDefaultSQL()
index 0e74f031b42b5a72ac73df9e86ee508f8f72acba..0a2ba5e96af970fb385ba909bc144fda9cd61bd9 100644 (file)
@@ -347,6 +347,26 @@ class XMLDBoci8po extends XMLDBgenerator {
         return $results;
     }
 
+    /**
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */
+    function getCreateEnumSQL($xmldb_table, $xmldb_field) {
+    /// All we have to do is to create the check constraint
+        return array('ALTER TABLE ' . $this->getTableName($xmldb_table) . 
+                     ' ADD ' . $this->getEnumExtraSQL($xmldb_table, $xmldb_field));
+    }
+                                                       
+    /**     
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */         
+    function getDropEnumSQL($xmldb_table, $xmldb_field) {
+    /// All we have to do is to drop the check constraint
+        return array('ALTER TABLE ' . $this->getTableName($xmldb_table) . 
+                     ' DROP CONSTRAINT ' . $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck'));
+    }   
+
     /**
      * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its default 
      * (usually invoked from getModifyDefaultSQL()
index 0e747b5240bb9ef37a4982bc198e56cf9bb066f9..7cd11c3a3dee0e8618799534920ba1bd56dad2fb 100644 (file)
@@ -259,6 +259,26 @@ class XMLDBpostgres7 extends XMLDBgenerator {
         return $results;
     }
 
+    /**
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */
+    function getCreateEnumSQL($xmldb_table, $xmldb_field) {
+    /// All we have to do is to create the check constraint
+        return array('ALTER TABLE ' . $this->getTableName($xmldb_table) .
+                     ' ADD ' . $this->getEnumExtraSQL($xmldb_table, $xmldb_field));
+    }
+
+    /**     
+     * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum 
+     * (usually invoked from getModifyEnumSQL()
+     */
+    function getDropEnumSQL($xmldb_table, $xmldb_field) {
+    /// All we have to do is to drop the check constraint
+        return array('ALTER TABLE ' . $this->getTableName($xmldb_table) .
+                     ' DROP CONSTRAINT ' . $this->getNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck'));
+    }
+
     /**
      * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its default 
      * (usually invoked from getModifyDefaultSQL()