]> git.mjollnir.org Git - moodle.git/commitdiff
Now we aren't guessing check constraint names
authorstronk7 <stronk7>
Tue, 11 Sep 2007 19:06:38 +0000 (19:06 +0000)
committerstronk7 <stronk7>
Tue, 11 Sep 2007 19:06:38 +0000 (19:06 +0000)
but getting the real ones under PostgreSQL. MDL-9356

lib/xmldb/classes/generators/postgres7/postgres7.class.php

index e9c383235886165981021d8881b392f19101ce71..5f1489e2c2cc37dab29e30e81a7212b5410df018 100644 (file)
@@ -400,14 +400,21 @@ class XMLDBpostgres7 extends XMLDBgenerator {
                      ' 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->getStandardNameForObject($xmldb_table->getName(), $xmldb_field->getName(), 'ck'));
+    /// Let's introspect to know the real name of the check constraint
+        if ($check_constraints = $this->getCheckConstraintsFromDB($xmldb_table, $xmldb_field)) {
+            $check_constraint = array_shift($check_constraints); /// Get the 1st (should be only one)
+            $constraint_name = strtolower($check_constraint->name); /// Extract the REAL name
+        /// All we have to do is to drop the check constraint
+            return array('ALTER TABLE ' . $this->getTableName($xmldb_table) .
+                     ' DROP CONSTRAINT ' . $constraint_name);
+        } else { /// Constraint not found. Nothing to do
+            return array();
+        }
     }
 
     /**