From 92529a70fad80a0fef9f14fd144a31490be583e6 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Tue, 11 Sep 2007 19:07:17 +0000 Subject: [PATCH] Now we aren't guessing check constraint names but getting the real ones under MSSQL. MDL-9356 --- .../classes/generators/mssql/mssql.class.php | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/lib/xmldb/classes/generators/mssql/mssql.class.php b/lib/xmldb/classes/generators/mssql/mssql.class.php index 09e4e0a60ee..4fe1cd4167b 100644 --- a/lib/xmldb/classes/generators/mssql/mssql.class.php +++ b/lib/xmldb/classes/generators/mssql/mssql.class.php @@ -368,14 +368,21 @@ class XMLDBmssql extends XMLDBgenerator { ' ADD ' . $this->getEnumExtraSQL($xmldb_table, $xmldb_field)); } - /** - * Given one XMLDBTable and one XMLDBField, return the SQL statements needded to drop its enum + /** + * 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')); + /// 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(); + } } /**