Skip to content

Commit

Permalink
Fix SQLite temp table name must not contain dot
Browse files Browse the repository at this point in the history
  • Loading branch information
mvorisek committed Apr 5, 2024
1 parent 14cd853 commit 2591f16
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion src/Platforms/SqlitePlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,12 @@ public function getAlterTableSQL(TableDiff $diff)
$sql = [];
$tableSql = [];
if (! $this->onSchemaAlterTable($diff, $tableSql)) {
$dataTable = new Table('__temp__' . $table->getName());
$tableName = $table->getName();
if (strpos($tableName, '.') !== false) {
[, $tableName] = explode('.', $tableName, 2);
}

$dataTable = new Table('__temp__' . $tableName);

$newTable = new Table(
$table->getQuotedName($this),
Expand Down
20 changes: 20 additions & 0 deletions tests/Platforms/SqlitePlatformTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,26 @@ public function getAlterTableRenameColumnSQL(): array
];
}

public function testGeneratesAlterTableRenameColumnSQLWithSchema(): void
{
$this->platform->disableSchemaEmulation();

$table = new Table('main.t');
$table->addColumn('a', Types::INTEGER);

$tableDiff = new TableDiff('t');
$tableDiff->fromTable = $table;
$tableDiff->renamedColumns['a'] = new Column('b', Type::getType(Types::INTEGER));

self::assertSame([
'CREATE TEMPORARY TABLE __temp__t AS SELECT a FROM main.t',
'DROP TABLE main.t',
'CREATE TABLE main.t (b INTEGER NOT NULL)',
'INSERT INTO main.t (b) SELECT a FROM __temp__t',
'DROP TABLE __temp__t',
], $this->platform->getAlterTableSQL($tableDiff));
}

/**
* {@inheritDoc}
*/
Expand Down

0 comments on commit 2591f16

Please sign in to comment.