From 89a9688099defd46c370c0323e17047e5639e314 Mon Sep 17 00:00:00 2001 From: stronk7 Date: Sat, 11 Aug 2007 00:15:25 +0000 Subject: [PATCH] MSSQL requires to drop defaults before performing one change of type and, sometimes, a change of length. --- lib/xmldb/classes/generators/mssql/mssql.class.php | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/lib/xmldb/classes/generators/mssql/mssql.class.php b/lib/xmldb/classes/generators/mssql/mssql.class.php index 452c44668e..808324d593 100644 --- a/lib/xmldb/classes/generators/mssql/mssql.class.php +++ b/lib/xmldb/classes/generators/mssql/mssql.class.php @@ -295,6 +295,7 @@ class XMLDBmssql extends XMLDBgenerator { $olddefault = empty($metac->has_default) ? null : strtok($metac->default_value, ':'); $typechanged = true; //By default, assume that the column type has changed + $lengthchanged = true; //By default, assume that the column length has changed /// Detect if we are changing the type of the column if (($xmldb_field->getType() == XMLDB_TYPE_INTEGER && substr($oldmetatype, 0, 1) == 'I') || @@ -306,8 +307,14 @@ class XMLDBmssql extends XMLDBgenerator { $typechanged = false; } - /// If type has changed drop the default if exists - if ($typechanged) { + /// Detect if we are changing the length of the column, not always necessary to drop defaults + /// if only the length changes, but it's safe to do it always + if ($xmldb_field->getLength() == $oldlength) { + $lengthchanged = false; + } + + /// If type or length have changed drop the default if exists + if ($typechanged || $lengthchanged) { $results = $this->getDropDefaultSQL($xmldb_table, $xmldb_field); } @@ -316,7 +323,7 @@ class XMLDBmssql extends XMLDBgenerator { $results = array_merge($results, parent::getAlterFieldSQL($xmldb_table, $xmldb_field)); // Call parent /// Finally, process the default clause to add it back if necessary - if ($typechanged) { + if ($typechanged || $lengthchanged) { $results = array_merge($results, $this->getCreateDefaultSQL($xmldb_table, $xmldb_field)); } -- 2.39.5