Skip to content

Commit 3347eeb

Browse files
committed
🐛 Oracle: fix comment retrieval on table with reserved keyword name
Fix SQLite comment retrieval when using quoted identifier as well
1 parent 2b09bad commit 3347eeb

File tree

4 files changed

+15
-9
lines changed

4 files changed

+15
-9
lines changed

docs/en/reference/testing.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ then run the following command:
7979

8080
.. code-block:: console
8181
82-
$ phpunit -c ci/github/pdo_mysql.xml
82+
$ phpunit -c ci/github/phpunit/pdo_mysql.xml
8383
8484
We do not currently have specific instructions on how to run a Database
8585
server, but we do recommend Docker as a convenient way to do so.

src/Schema/OracleSchemaManager.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,13 @@ protected function fetchTableOptionsByTable(string $databaseName, ?string $table
512512

513513
$sql .= ' FROM ALL_TAB_COMMENTS WHERE ' . implode(' AND ', $conditions);
514514

515-
/** @var array<string,array<string,mixed>> $metadata */
516-
$metadata = $this->_conn->executeQuery($sql, $params)
517-
->fetchAllAssociativeIndexed();
515+
/** @var array<array{TABLE_NAME: string, COMMENTS: string|null}> $metadata */
516+
$metadata = $this->_conn->executeQuery($sql, $params)->fetchAllAssociative();
518517

519518
$tableOptions = [];
520-
foreach ($metadata as $table => $data) {
521-
$data = array_change_key_case($data, CASE_LOWER);
519+
foreach ($metadata as $data) {
520+
$data = array_change_key_case($data, CASE_LOWER);
521+
$table = $this->_getPortableTableDefinition($data);
522522

523523
$tableOptions[$table] = [
524524
'comment' => $data['comments'],

src/Schema/SqliteSchemaManager.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -582,7 +582,7 @@ private function getCreateTableSQL(string $table): string
582582
AND name = ?
583583
SQL
584584
,
585-
[$table],
585+
[trim($table, '"')], // Unquote the identifier
586586
);
587587

588588
if ($sql !== false) {

tests/Functional/Schema/SchemaManagerFunctionalTestCase.php

+8-2
Original file line numberDiff line numberDiff line change
@@ -1677,9 +1677,11 @@ public function testIntrospectReservedKeywordTableViaListTableDetails(): void
16771677
$this->createReservedKeywordTables();
16781678

16791679
$user = $this->schemaManager->introspectTable('"user"');
1680-
self::assertCount(2, $user->getColumns());
1680+
self::assertCount(3, $user->getColumns());
16811681
self::assertCount(2, $user->getIndexes());
16821682
self::assertCount(1, $user->getForeignKeys());
1683+
self::assertSame('table comment', $user->getComment());
1684+
self::assertSame('column comment', $user->getColumn('user')->getComment());
16831685
}
16841686

16851687
public function testIntrospectReservedKeywordTableViaListTables(): void
@@ -1690,9 +1692,11 @@ public function testIntrospectReservedKeywordTableViaListTables(): void
16901692

16911693
$user = $this->findTableByName($tables, 'user');
16921694
self::assertNotNull($user);
1693-
self::assertCount(2, $user->getColumns());
1695+
self::assertCount(3, $user->getColumns());
16941696
self::assertCount(2, $user->getIndexes());
16951697
self::assertCount(1, $user->getForeignKeys());
1698+
self::assertSame('table comment', $user->getComment());
1699+
self::assertSame('column comment', $user->getColumn('user')->getComment());
16961700
}
16971701

16981702
private function createReservedKeywordTables(): void
@@ -1705,7 +1709,9 @@ private function createReservedKeywordTables(): void
17051709
$schema = new Schema();
17061710

17071711
$user = $schema->createTable('user');
1712+
$user->setComment('table comment');
17081713
$user->addColumn('id', Types::INTEGER);
1714+
$user->addColumn('user', Types::INTEGER)->setComment('column comment');
17091715
$user->addColumn('group_id', Types::INTEGER);
17101716
$user->setPrimaryKey(['id']);
17111717
$user->addForeignKeyConstraint('group', ['group_id'], ['id']);

0 commit comments

Comments
 (0)