Skip to content

Commit

Permalink
🐛 Oracle: fix comment retrieval on table with reserved keyword name
Browse files Browse the repository at this point in the history
  • Loading branch information
homersimpsons committed Feb 4, 2025
1 parent 2b09bad commit d0fb9ec
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
2 changes: 1 addition & 1 deletion docs/en/reference/testing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ then run the following command:

.. code-block:: console
$ phpunit -c ci/github/pdo_mysql.xml
$ phpunit -c ci/github/phpunit/pdo_mysql.xml
We do not currently have specific instructions on how to run a Database
server, but we do recommend Docker as a convenient way to do so.
Expand Down
10 changes: 5 additions & 5 deletions src/Schema/OracleSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -512,13 +512,13 @@ protected function fetchTableOptionsByTable(string $databaseName, ?string $table

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

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

Check warning on line 516 in src/Schema/OracleSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/OracleSchemaManager.php#L516

Added line #L516 was not covered by tests

$tableOptions = [];
foreach ($metadata as $table => $data) {
$data = array_change_key_case($data, CASE_LOWER);
foreach ($metadata as $data) {
$data = array_change_key_case($data, CASE_LOWER);
$table = $this->_getPortableTableDefinition($data);

Check warning on line 521 in src/Schema/OracleSchemaManager.php

View check run for this annotation

Codecov / codecov/patch

src/Schema/OracleSchemaManager.php#L519-L521

Added lines #L519 - L521 were not covered by tests

$tableOptions[$table] = [
'comment' => $data['comments'],
Expand Down
10 changes: 8 additions & 2 deletions tests/Functional/Schema/SchemaManagerFunctionalTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -1677,9 +1677,11 @@ public function testIntrospectReservedKeywordTableViaListTableDetails(): void
$this->createReservedKeywordTables();

$user = $this->schemaManager->introspectTable('"user"');
self::assertCount(2, $user->getColumns());
self::assertCount(3, $user->getColumns());
self::assertCount(2, $user->getIndexes());
self::assertCount(1, $user->getForeignKeys());
self::assertSame('table comment', $user->getComment());
self::assertSame('column comment', $user->getColumn('user')->getComment());
}

public function testIntrospectReservedKeywordTableViaListTables(): void
Expand All @@ -1690,9 +1692,11 @@ public function testIntrospectReservedKeywordTableViaListTables(): void

$user = $this->findTableByName($tables, 'user');
self::assertNotNull($user);
self::assertCount(2, $user->getColumns());
self::assertCount(3, $user->getColumns());
self::assertCount(2, $user->getIndexes());
self::assertCount(1, $user->getForeignKeys());
self::assertSame('table comment', $user->getComment());
self::assertSame('column comment', $user->getColumn('user')->getComment());
}

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

$user = $schema->createTable('user');
$user->setComment('table comment');
$user->addColumn('id', Types::INTEGER);
$user->addColumn('user', Types::INTEGER)->setComment('column comment');
$user->addColumn('group_id', Types::INTEGER);
$user->setPrimaryKey(['id']);
$user->addForeignKeyConstraint('group', ['group_id'], ['id']);
Expand Down

0 comments on commit d0fb9ec

Please sign in to comment.