MINOR FIX: ID column protected against index and column alterations

This commit is contained in:
Geoff Munn 2009-07-28 21:15:27 +00:00
parent 82dcbb89d2
commit 396384e709

View File

@ -461,8 +461,11 @@ class MSSQLDatabase extends Database {
//drop the index if it exists: //drop the index if it exists:
$alterCol=''; $alterCol='';
if(isset($indexList[$colName])){ if(isset($indexList[$colName]) && $colName!='ID'){
$alterCol = "\nDROP INDEX \"$tableName\".ix_{$tableName}_{$colName};"; //$alterCol = "\nDROP INDEX \"$tableName\".ix_{$tableName}_{$colName};";
//The indexname value should hold the name of the index, so we don't have to construct it outselves.
//This also means we can use internal indexes if they happen to appear.
$alterCol = "\nDROP INDEX \"$tableName\"." . $indexList[$colName]['indexname'] . ';';
} }
$prefix="ALTER TABLE \"" . $tableName . "\" "; $prefix="ALTER TABLE \"" . $tableName . "\" ";
@ -473,6 +476,8 @@ class MSSQLDatabase extends Database {
} }
if(isset($matches[1])) { if(isset($matches[1])) {
//We will prevent any changes being made to the ID column. Primary key indexes will have a fit if we do anything here.
if($colName!='ID'){
$alterCol .= ";\n$prefix ALTER COLUMN \"$colName\" $matches[1]"; $alterCol .= ";\n$prefix ALTER COLUMN \"$colName\" $matches[1]";
// SET null / not null // SET null / not null
@ -493,6 +498,7 @@ class MSSQLDatabase extends Database {
} }
} }
}
return isset($alterCol) ? $alterCol : ''; return isset($alterCol) ? $alterCol : '';
} }