mirror of
https://github.com/silverstripe/silverstripe-mssql
synced 2024-10-22 08:05:53 +02:00
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:
parent
5bd3bcac67
commit
3bba7b9ef1
@ -440,7 +440,6 @@ class MSSQLDatabase extends SS_Database {
|
||||
// First, we split the column specifications into parts
|
||||
// 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?
|
||||
|
||||
$pattern = '/^([\w()]+)\s?((?:not\s)?null)?\s?(default\s[\w\']+)?\s?(check\s?[\w()\'",\s]+)?$/i';
|
||||
$matches=Array();
|
||||
preg_match($pattern, $colSpec, $matches);
|
||||
@ -456,6 +455,11 @@ class MSSQLDatabase extends SS_Database {
|
||||
//This also means we can use internal indexes if they happen to appear.
|
||||
$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 . "\" ";
|
||||
|
||||
@ -1260,6 +1264,18 @@ class MSSQLDatabase extends SS_Database {
|
||||
$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
|
||||
* @param $fields array The list of field names to search on
|
||||
|
Loading…
Reference in New Issue
Block a user