From 3aa0777cdaa8761545a066d7125ac8a2ddff7f52 Mon Sep 17 00:00:00 2001 From: Ansgar Becker Date: Thu, 9 Jan 2020 21:27:09 +0100 Subject: [PATCH] Issue #12: Get column comments in MSSQL back. See http://www.heidisql.com/forum.php?t=19576 --- source/dbconnection.pas | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/source/dbconnection.pas b/source/dbconnection.pas index d12e8138..f015bcc0 100644 --- a/source/dbconnection.pas +++ b/source/dbconnection.pas @@ -553,6 +553,7 @@ type function ConnectionInfo: TStringList; override; function GetLastResults: TDBQueryList; override; property LastRawResults: TAdoRawResults read FLastRawResults; + function GetTableColumns(Table: TDBObject): TTableColumnList; override; end; TPGRawResults = Array of PPGresult; @@ -4784,6 +4785,38 @@ begin end; +function TAdoDBConnection.GetTableColumns(Table: TDBObject): TTableColumnList; +var + Comments: TDBQuery; + TableCol: TTableColumn; +begin + Result := inherited; + // Comments in MSSQL. See http://www.heidisql.com/forum.php?t=19576 + try + Comments := GetResults('SELECT c.name AS '+QuoteIdent('column')+', prop.value AS '+QuoteIdent('comment')+' '+ + 'FROM sys.extended_properties AS prop '+ + 'INNER JOIN sys.all_objects o ON prop.major_id = o.object_id '+ + 'INNER JOIN sys.schemas s ON o.schema_id = s.schema_id '+ + 'INNER JOIN sys.columns AS c ON prop.major_id = c.object_id AND prop.minor_id = c.column_id '+ + 'WHERE '+ + ' prop.name='+EscapeString('MS_Description')+ + ' AND s.name='+EscapeString(Table.Schema)+ + ' AND o.name='+EscapeString(Table.Name) + ); + while not Comments.Eof do begin + for TableCol in Result do begin + if TableCol.Name = Comments.Col('column') then begin + TableCol.Comment := Comments.Col('comment'); + Break; + end; + end; + Comments.Next; + end; + except // Fails on old servers + on E:EDbError do; + end; + +end; function TSQLiteConnection.GetTableColumns(Table: TDBObject): TTableColumnList; var