Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SQLite generated columns #6135

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Schema/SqliteSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ protected function _getPortableTableIndexesList($tableIndexes, $tableName = null
$indexBuffer = [];

// fetch primary
$indexArray = $this->_conn->fetchAllAssociative('SELECT * FROM PRAGMA_TABLE_INFO (?)', [$tableName]);
$indexArray = $this->_conn->fetchAllAssociative('SELECT * FROM PRAGMA_TABLE_XINFO (?)', [$tableName]);

usort(
$indexArray,
Expand Down Expand Up @@ -684,7 +684,7 @@ protected function selectTableColumns(string $databaseName, ?string $tableName =
SELECT t.name AS table_name,
c.*
FROM sqlite_master t
JOIN pragma_table_info(t.name) c
JOIN pragma_table_xinfo(t.name) c
SQL;

$conditions = [
Expand Down
23 changes: 23 additions & 0 deletions tests/Functional/Schema/SqliteSchemaManagerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -291,4 +291,27 @@ public function testNoWhitespaceInForeignKeyReference(): void
self::assertSame('users', $foreignKey->getForeignTableName());
self::assertSame(['id'], $foreignKey->getForeignColumns());
}

public function testGeneratedColumnsGetListed(): void
{
$this->dropTableIfExists('users');

$ddl = <<<'DDL'
CREATE TABLE "users" (
"id" INTEGER,
"a" INTEGER,
"b" INTEGER AS (a*2),
"c" INT GENERATED ALWAYS AS (a*2) VIRTUAL,
"d" INT GENERATED ALWAYS AS (a*2) STORED
);
DDL;

$this->connection->executeStatement($ddl);
$users = $this->schemaManager->introspectTable('users');

$this->assertTrue($users->hasColumn('a'));
$this->assertTrue($users->hasColumn('b'));
$this->assertTrue($users->hasColumn('c'));
$this->assertTrue($users->hasColumn('d'));
}
}
Loading