Skip to content

Commit

Permalink
Display column comments on MSSQL. See http://www.heidisql.com/forum.p…
Browse files Browse the repository at this point in the history
  • Loading branch information
ansgarbecker committed Oct 30, 2015
1 parent c259410 commit e19d803
Showing 1 changed file with 24 additions and 2 deletions.
26 changes: 24 additions & 2 deletions source/dbconnection.pas
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -2629,7 +2629,7 @@ function TMySQLConnection.GetCreateViewCode(Database, Name: String): String;


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


// Retrieve column details from IS // Retrieve column details from IS
case Parameters.NetTypeGroup of case Parameters.NetTypeGroup of
Expand Down Expand Up @@ -2680,6 +2681,17 @@ function TDBConnection.GetCreateCode(Database, Schema, Name: String; NodeType: T
SchemaClauseIS('TABLE') + SchemaClauseIS('TABLE') +
' AND TABLE_NAME='+EscapeString(Name) ' 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;
end; end;
while not Cols.Eof do begin while not Cols.Eof do begin
Expand Down Expand Up @@ -2714,7 +2726,17 @@ function TDBConnection.GetCreateCode(Database, Schema, Name: String; NodeType: T
end; end;
// The following is wrong syntax in PostgreSQL, but helps ParseTableStructure to find the comment // The following is wrong syntax in PostgreSQL, but helps ParseTableStructure to find the comment
if Cols.ColExists('column_comment') then 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 + ','; Result := Result + ',';
Cols.Next; Cols.Next;
end; end;
Expand Down

0 comments on commit e19d803

Please sign in to comment.