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";
|
$newColsSpec[] = "\"" . (($name == $oldName) ? $newName : $name) . "\" $spec";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// SQLite doesn't support direct renames through ALTER TABLE
|
||||||
$queries = array(
|
$queries = array(
|
||||||
"BEGIN TRANSACTION",
|
"BEGIN TRANSACTION",
|
||||||
"CREATE TABLE \"{$tableName}_renamefield_{$oldName}\" (" . implode(',', $newColsSpec) . ")",
|
"CREATE TABLE \"{$tableName}_renamefield_{$oldName}\" (" . implode(',', $newColsSpec) . ")",
|
||||||
@ -438,15 +439,21 @@ class SQLite3Database extends SS_Database {
|
|||||||
"COMMIT"
|
"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($queries as $query) $this->query($query.';');
|
||||||
|
|
||||||
foreach($indexList as $indexName => $indexSpec) {
|
// Recreate the indexes
|
||||||
|
foreach($oldIndexList as $indexName => $indexSpec) {
|
||||||
$renamedIndexSpec = array();
|
$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));
|
$this->createIndex($tableName, $indexName, implode(',', $renamedIndexSpec));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user