Skip to content

Commit

Permalink
Fixing SQLServer table level comments
Browse files Browse the repository at this point in the history
  • Loading branch information
moufmouf committed Apr 15, 2019
1 parent e4478a0 commit b55c861
Showing 1 changed file with 18 additions and 10 deletions.
28 changes: 18 additions & 10 deletions lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php
Original file line number Diff line number Diff line change
Expand Up @@ -1693,20 +1693,28 @@ private function generateIdentifierName($identifier)
return strtoupper(dechex(crc32($identifier->getName())));
}

public function getCommentOnTableSQL(string $tableName, ?string $comment) : string
{
return sprintf(
'EXEC sys.sp_addextendedproperty @name=N\'MS_Description\',
@value=N%s , @level0type=N\'SCHEMA\',@level0name=N\'dbo\',
@level1type=N\'TABLE\',@level1name=N%s',
$this->quoteStringLiteral((string) $comment),
$this->quoteStringLiteral($tableName)
);
}

public function getListTableMetadataSQL(string $table) : string
{
return sprintf(
<<<'SQL'
SELECT td.value AS [table_comment],
FROM sysobjects t
INNER JOIN sysusers u
ON u.uid = t.uid
LEFT OUTER JOIN sys.extended_properties td
ON td.major_id = t.id
AND td.minor_id = 0
AND td.name = 'MS_Description'
WHERE t.type = %s
ORDER BY t.name, c.colorder
SELECT
p.value AS [table_comment]
FROM
sys.tables AS tbl
INNER JOIN sys.extended_properties AS p ON p.major_id=tbl.object_id AND p.minor_id=0 AND p.class=1
WHERE
(tbl.name=N%s and SCHEMA_NAME(tbl.schema_id)=N'dbo' and p.name=N'MS_Description')
SQL
,
$this->quoteStringLiteral($table)
Expand Down

0 comments on commit b55c861

Please sign in to comment.