From 1964ac59077f1551ac147e0b5d02c4592f964890 Mon Sep 17 00:00:00 2001 From: Geoff Munn Date: Tue, 21 Apr 2009 23:14:43 +0000 Subject: [PATCH] Table alterations refactored --- code/MSSQLDatabase.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/code/MSSQLDatabase.php b/code/MSSQLDatabase.php index e8f8355..c126400 100644 --- a/code/MSSQLDatabase.php +++ b/code/MSSQLDatabase.php @@ -251,7 +251,7 @@ class MSSQLDatabase extends Database { $fieldSchemas = $indexSchemas = ""; $alterList = array(); - if($newFields) foreach($newFields as $k => $v) $alterList[] .= "ADD \"$k\" $v"; + if($newFields) foreach($newFields as $k => $v) $alterList[] .= "ALTER TABLE \"$tableName\" ADD \"$k\" $v"; $indexList=$this->IndexList($tableName); @@ -289,7 +289,9 @@ class MSSQLDatabase extends Database { if($alterList) { foreach($alterList as $this_alteration){ - $this->query("ALTER TABLE \"$tableName\" $this_alteration;"); + if($this_alteration!=''){ + $this->query($this_alteration); + } } } @@ -349,7 +351,7 @@ class MSSQLDatabase extends Database { //drop the index if it exists: $alterCol=''; if(isset($indexList[$colName])){ - $alterCol = "\nDROP INDEX \"$tableName\".ix_{$tableName}_{$colName}"; + $alterCol = "\nDROP INDEX \"$tableName\".ix_{$tableName}_{$colName};"; } $prefix="ALTER TABLE \"" . $tableName . "\" ";