Skip to content

Commit 58c18cc

Browse files
committed
Adding table level comments to Oracle
1 parent b55c861 commit 58c18cc

File tree

3 files changed

+41
-5
lines changed

3 files changed

+41
-5
lines changed

lib/Doctrine/DBAL/Platforms/OraclePlatform.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1182,4 +1182,30 @@ public function getBlobTypeDeclarationSQL(array $field)
11821182
{
11831183
return 'BLOB';
11841184
}
1185+
1186+
public function getListTableCommentsSQL(string $table, string $database = null) : string
1187+
{
1188+
$table = $this->normalizeIdentifier($table);
1189+
$table = $this->quoteStringLiteral($table->getName());
1190+
1191+
$tableCommentsName = 'user_tab_comments';
1192+
$ownerCondition = '';
1193+
1194+
if ($database !== null && $database !== '/') {
1195+
$database = $this->normalizeIdentifier($database);
1196+
$database = $this->quoteStringLiteral($database->getName());
1197+
$tableCommentsName = 'all_tab_comments';
1198+
$ownerCondition = ' AND owner = ' . $database;
1199+
}
1200+
1201+
return sprintf(
1202+
<<<'SQL'
1203+
SELECT comments FROM %s WHERE table_name = %s%s
1204+
SQL
1205+
,
1206+
$tableCommentsName,
1207+
$table,
1208+
$ownerCondition
1209+
);
1210+
}
11851211
}

lib/Doctrine/DBAL/Schema/OracleSchemaManager.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Doctrine\DBAL\DBALException;
66
use Doctrine\DBAL\Driver\DriverException;
77
use Doctrine\DBAL\Platforms\OraclePlatform;
8+
use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
89
use Doctrine\DBAL\Types\Type;
910
use Throwable;
1011
use const CASE_LOWER;
@@ -382,4 +383,18 @@ private function killUserSessions($user)
382383
);
383384
}
384385
}
386+
387+
public function listTableDetails($tableName)
388+
{
389+
$table = parent::listTableDetails($tableName);
390+
391+
/** @var OraclePlatform $platform */
392+
$platform = $this->_platform;
393+
$sql = $platform->getListTableCommentsSQL($tableName);
394+
395+
$tableOptions = $this->_conn->fetchAssoc($sql);
396+
$table->addOption('comment', $tableOptions['COMMENTS']);
397+
398+
return $table;
399+
}
385400
}

tests/Doctrine/Tests/DBAL/Functional/Schema/OracleSchemaManagerTest.php

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -285,9 +285,4 @@ public function testCreateAndListSequences() : void
285285
{
286286
self::markTestSkipped("Skipped for uppercase letters are contained in sequences' names. Fix the schema manager in 3.0.");
287287
}
288-
289-
public function testCommentInTable() : void
290-
{
291-
self::markTestSkipped('Table level comments are not supported on Oracle');
292-
}
293288
}

0 commit comments

Comments
 (0)