]> git.mjollnir.org Git - moodle.git/commitdiff
rename_field() under postgresql completed.
authorstronk7 <stronk7>
Mon, 2 Oct 2006 17:02:35 +0000 (17:02 +0000)
committerstronk7 <stronk7>
Mon, 2 Oct 2006 17:02:35 +0000 (17:02 +0000)
lib/xmldb/classes/generators/postgres7/postgres7.class.php

index 5e2fe0206ee071a0cc2136982bfe06a57d37182f..2246750cae9ff848b52f7406147b1fc4824ce180 100644 (file)
@@ -43,6 +43,8 @@ class XMLDBpostgres7 extends XMLDBgenerator {
 
     var $rename_table_extra_code = true; //Does the generator need to add code after table rename
 
+    var $rename_column_extra_code = true; //Does the generator need to add code after column rename
+
     var $enum_inline_code = false; //Does the generator need to add inline code in the column definition
 
     var $rename_key_sql = null; //SQL sentence to rename one key (PostgreSQL doesn't support this!)
@@ -167,7 +169,7 @@ class XMLDBpostgres7 extends XMLDBgenerator {
                 $newconstraintname = str_replace($oldconstraintprefix, $newconstraintprefix, $constraint->name);
             /// Add the new constraint
                 $results[] = 'ALTER TABLE ' . $newtablename . ' ADD CONSTRAINT ' . $newconstraintname .
-                             ' CHECK (' . $constraint->description . ')';
+                             ' CHECK ' . $constraint->description;
              }
          }
 
@@ -354,6 +356,26 @@ class XMLDBpostgres7 extends XMLDBgenerator {
         return $results;
     }
 
+    /**
+     * Returns the code (array of statements) needed to execute extra statements on field rename
+     */
+    function getRenameFieldExtraSQL ($xmldb_table, $xmldb_field, $newname) {
+
+        $results = array();
+
+    /// If the field is enum, drop and re-create the check constraint
+        if ($xmldb_field->getEnum()) {
+        /// Drop the current enum
+            $results = array_merge($results, $this->getDropEnumSQL($xmldb_table, $xmldb_field));
+        /// Change field name
+            $xmldb_field->setName($newname);
+        /// Recreate the enum
+            $results = array_merge($results, $this->getCreateEnumSQL($xmldb_table, $xmldb_field));
+        }
+
+        return $results;
+    }
+
     /**
      * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to create its enum 
      * (usually invoked from getModifyEnumSQL()