Skip to content

Commit b55c861

Browse files
committed
Fixing SQLServer table level comments
1 parent e4478a0 commit b55c861

File tree

1 file changed

+18
-10
lines changed

1 file changed

+18
-10
lines changed

lib/Doctrine/DBAL/Platforms/SQLServerPlatform.php

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,20 +1693,28 @@ private function generateIdentifierName($identifier)
16931693
return strtoupper(dechex(crc32($identifier->getName())));
16941694
}
16951695

1696+
public function getCommentOnTableSQL(string $tableName, ?string $comment) : string
1697+
{
1698+
return sprintf(
1699+
'EXEC sys.sp_addextendedproperty @name=N\'MS_Description\',
1700+
@value=N%s , @level0type=N\'SCHEMA\',@level0name=N\'dbo\',
1701+
@level1type=N\'TABLE\',@level1name=N%s',
1702+
$this->quoteStringLiteral((string) $comment),
1703+
$this->quoteStringLiteral($tableName)
1704+
);
1705+
}
1706+
16961707
public function getListTableMetadataSQL(string $table) : string
16971708
{
16981709
return sprintf(
16991710
<<<'SQL'
1700-
SELECT td.value AS [table_comment],
1701-
FROM sysobjects t
1702-
INNER JOIN sysusers u
1703-
ON u.uid = t.uid
1704-
LEFT OUTER JOIN sys.extended_properties td
1705-
ON td.major_id = t.id
1706-
AND td.minor_id = 0
1707-
AND td.name = 'MS_Description'
1708-
WHERE t.type = %s
1709-
ORDER BY t.name, c.colorder
1711+
SELECT
1712+
p.value AS [table_comment]
1713+
FROM
1714+
sys.tables AS tbl
1715+
INNER JOIN sys.extended_properties AS p ON p.major_id=tbl.object_id AND p.minor_id=0 AND p.class=1
1716+
WHERE
1717+
(tbl.name=N%s and SCHEMA_NAME(tbl.schema_id)=N'dbo' and p.name=N'MS_Description')
17101718
SQL
17111719
,
17121720
$this->quoteStringLiteral($table)

0 commit comments

Comments
 (0)