mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
BUG Ignore col quotes in renameTable()
This commit is contained in:
parent
356872236a
commit
7c9156ebaf
@ -429,6 +429,7 @@ class SQLite3Database extends SS_Database {
|
||||
$newColsSpec[] = "\"" . (($name == $oldName) ? $newName : $name) . "\" $spec";
|
||||
}
|
||||
|
||||
// SQLite doesn't support direct renames through ALTER TABLE
|
||||
$queries = array(
|
||||
"BEGIN TRANSACTION",
|
||||
"CREATE TABLE \"{$tableName}_renamefield_{$oldName}\" (" . implode(',', $newColsSpec) . ")",
|
||||
@ -438,15 +439,21 @@ class SQLite3Database extends SS_Database {
|
||||
"COMMIT"
|
||||
);
|
||||
|
||||
$indexList = $this->indexList($tableName);
|
||||
// Remember original indexes
|
||||
$oldIndexList = $this->indexList($tableName);
|
||||
|
||||
// Then alter the table column
|
||||
foreach($queries as $query) $this->query($query.';');
|
||||
|
||||
foreach($indexList as $indexName => $indexSpec) {
|
||||
// Recreate the indexes
|
||||
foreach($oldIndexList as $indexName => $indexSpec) {
|
||||
$renamedIndexSpec = array();
|
||||
foreach(explode(',', $indexSpec) as $col) $renamedIndexSpec[] = $col == $oldName ? $newName : $col;
|
||||
foreach(explode(',', $indexSpec) as $col) {
|
||||
$col = trim($col, '"'); // remove quotes
|
||||
$renamedIndexSpec[] = ($col == $oldName) ? $newName : $col;
|
||||
}
|
||||
$this->createIndex($tableName, $indexName, implode(',', $renamedIndexSpec));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user