blob: d677034188c6d797783a671a7d41981bfcfd6a79 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
|
<?php
// replace fetchTableColumns by this one in vendor/doctrine/dbal/src/Schema/SQLiteSchemaManager.php at line 466
protected function fetchTableColumns(string $databaseName, ?string $tableName = null): array
{
$rows = parent::fetchTableColumns($databaseName, $tableName);
$sqlByTable = $pkColumnNamesByTable = $foreignKeyColumnsByTable = $result = [];
foreach ($rows as $row) {
$tableName = $row['table_name'];
$sqlByTable[$tableName] ??= $this->getCreateTableSQL($tableName);
if ($row['pk'] !== 0 && $row['pk'] !== '0') {
$pkColumnNamesByTable[$tableName][] = $row['name'];
}
}
// -----
$foreignKeyRows = $this->connection->fetchAllAssociative(
<<<'SQL'
SELECT t.name AS table_name,
p."from" AS column_name
FROM sqlite_master t
JOIN pragma_foreign_key_list(t.name) p
WHERE t.type = 'table'
SQL,
);
foreach ($foreignKeyRows as $foreignKeyRow) {
$foreignKeyColumnsByTable[$foreignKeyRow['table_name']]
[$foreignKeyRow['column_name']] = true;
}
// -----
foreach ($rows as $row) {
$tableName = $row['table_name'];
$columnName = $row['name'];
$tableSQL = $sqlByTable[$tableName];
$result[] = array_merge($row, [
// -----
'autoincrement' => isset($pkColumnNamesByTable[$tableName])
&& $pkColumnNamesByTable[$tableName] === [$columnName]
&& $row['type'] === 'INTEGER'
&& ! isset($foreignKeyColumnsByTable[$tableName][$columnName]),
// -----
'collation' => $this->parseColumnCollationFromSQL($columnName, $tableSQL),
'comment' => $this->parseColumnCommentFromSQL($columnName, $tableSQL),
]);
}
return $result;
}
|