Skip to content
Permalink
Browse files

Display column comments on MSSQL. See http://www.heidisql.com/forum.p…

  • Loading branch information...
ansgarbecker committed Oct 30, 2015
1 parent c259410 commit e19d803e648f0425604ffca95df49133c4bcf09c
Showing with 24 additions and 2 deletions.
  1. +24 −2 source/dbconnection.pas
@@ -2629,7 +2629,7 @@ function TMySQLConnection.GetCreateViewCode(Database, Name: String): String;

function TDBConnection.GetCreateCode(Database, Schema, Name: String; NodeType: TListNodeType): String;
var
Cols, Keys, ProcDetails: TDBQuery;
Cols, Keys, ProcDetails, Comments: TDBQuery;
ConstraintName, MaxLen, DataType: String;
ColNames, ArgNames, ArgTypes, Arguments: TStringList;
Rows: TStringList;
@@ -2649,6 +2649,7 @@ function TDBConnection.GetCreateCode(Database, Schema, Name: String; NodeType: T
case NodeType of
lntTable: begin
Result := 'CREATE TABLE '+QuoteIdent(Name)+' (';
Comments := nil;

// Retrieve column details from IS
case Parameters.NetTypeGroup of
@@ -2680,6 +2681,17 @@ function TDBConnection.GetCreateCode(Database, Schema, Name: String; NodeType: T
SchemaClauseIS('TABLE') +
' AND TABLE_NAME='+EscapeString(Name)
);
// Comments in MSSQL. See http://www.heidisql.com/forum.php?t=19576
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(Schema)+
' AND o.name='+EscapeString(Name)
);
end;
end;
while not Cols.Eof do begin
@@ -2714,7 +2726,17 @@ function TDBConnection.GetCreateCode(Database, Schema, Name: String; NodeType: T
end;
// The following is wrong syntax in PostgreSQL, but helps ParseTableStructure to find the comment
if Cols.ColExists('column_comment') then
Result := Result + ' COMMENT ' + EscapeString(Cols.Col('column_comment'));
Result := Result + ' COMMENT ' + EscapeString(Cols.Col('column_comment'))
else if Comments <> nil then begin
// Find column comment from separate result
while not Comments.Eof do begin
if Comments.Col('column')=Cols.Col('COLUMN_NAME') then begin
Result := Result + ' COMMENT ' + EscapeString(Comments.Col('comment'));
Break;
end;
end;
end;

Result := Result + ',';
Cols.Next;
end;

0 comments on commit e19d803

Please sign in to comment.
You can’t perform that action at this time.