ENHANCEMENT Added MSSQLDatabase::fulltextIndexExists() to check if an index exists before dropping it in MSSQLDatabase::alterTableAlterColumn()

BUGFIX Fixed alterting field types with a fulltext index on a table - an error would complain that a fulltext index exists, which needs to be dropped before the column can be altered
This commit is contained in:
Sean Harvey 2009-12-07 05:38:26 +00:00
parent 5bd3bcac67
commit 3bba7b9ef1

View File

@ -440,7 +440,6 @@ class MSSQLDatabase extends SS_Database {
// First, we split the column specifications into parts // First, we split the column specifications into parts
// TODO: this returns an empty array for the following string: int(11) not null auto_increment // TODO: this returns an empty array for the following string: int(11) not null auto_increment
// on second thoughts, why is an auto_increment field being passed through? // on second thoughts, why is an auto_increment field being passed through?
$pattern = '/^([\w()]+)\s?((?:not\s)?null)?\s?(default\s[\w\']+)?\s?(check\s?[\w()\'",\s]+)?$/i'; $pattern = '/^([\w()]+)\s?((?:not\s)?null)?\s?(default\s[\w\']+)?\s?(check\s?[\w()\'",\s]+)?$/i';
$matches=Array(); $matches=Array();
preg_match($pattern, $colSpec, $matches); preg_match($pattern, $colSpec, $matches);
@ -457,6 +456,11 @@ class MSSQLDatabase extends SS_Database {
$alterCol = "\nDROP INDEX \"$tableName\"." . $indexList[$colName]['indexname'] . ';'; $alterCol = "\nDROP INDEX \"$tableName\"." . $indexList[$colName]['indexname'] . ';';
} }
// fulltext indexes need to be dropped if alterting a table
if($this->fulltextIndexExists($tableName)) {
$alterCol .= "\nDROP FULLTEXT INDEX ON \"$tableName\";";
}
$prefix="ALTER TABLE \"" . $tableName . "\" "; $prefix="ALTER TABLE \"" . $tableName . "\" ";
// Remove the old default prior to adjusting the column. // Remove the old default prior to adjusting the column.
@ -1260,6 +1264,18 @@ class MSSQLDatabase extends SS_Database {
$this->query("SET IDENTITY_INSERT \"$table\" " . ($allow ? "ON" : "OFF")); $this->query("SET IDENTITY_INSERT \"$table\" " . ($allow ? "ON" : "OFF"));
} }
/**
* Check if a fulltext index exists on a particular table name.
* @return boolean TRUE index exists | FALSE index does not exist
*/
function fulltextIndexExists($tableName) {
return (bool) $this->query("
SELECT 1 FROM sys.fulltext_indexes i
JOIN sys.objects o ON i.object_id = o.object_id
WHERE o.name = '$tableName'
")->value();
}
/** /**
* Returns a SQL fragment for querying a fulltext search index * Returns a SQL fragment for querying a fulltext search index
* @param $fields array The list of field names to search on * @param $fields array The list of field names to search on