Skip to content
Permalink
Browse files

Fix always empty comment on PostgreSQL columns. Closes #859

  • Loading branch information
ansgarbecker committed Jan 20, 2020
1 parent d5e5a82 commit c76695c0d819642e2ed5ce63cf5dc95aae98e7c9
Showing with 30 additions and 1 deletion.
  1. +30 −1 source/dbconnection.pas
@@ -601,6 +601,7 @@ TPgConnection = class(TDBConnection)
function GetRowCount(Obj: TDBObject): Int64; override;
property LastRawResults: TPGRawResults read FLastRawResults;
property RegClasses: TOidStringPairs read FRegClasses;
function GetTableColumns(Table: TDBObject): TTableColumnList; override;
function GetTableKeys(Table: TDBObject): TTableKeyList; override;
end;

@@ -4671,7 +4672,7 @@ function TAdoDBConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
TableCol: TTableColumn;
begin
Result := inherited;
// Comments in MSSQL. See http://www.heidisql.com/forum.php?t=19576
// Column 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 '+
@@ -4698,6 +4699,34 @@ function TAdoDBConnection.GetTableColumns(Table: TDBObject): TTableColumnList;

end;

function TPgConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
var
Comments: TDBQuery;
TableCol: TTableColumn;
begin
Result := inherited;
// Column comments in Postgre. See issue #859
// Todo: add current schema to WHERE clause?
Comments := GetResults('SELECT a.attname AS column, des.description AS comment'+
' FROM pg_attribute AS a, pg_description AS des, pg_class AS pgc'+
' WHERE'+
' pgc.oid = a.attrelid'+
' AND des.objoid = pgc.oid'+
' AND pg_table_is_visible(pgc.oid)'+
' AND pgc.relname = '+EscapeString(Table.Name)+
' AND a.attnum = des.objsubid'
);
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;
end;

function TSQLiteConnection.GetTableColumns(Table: TDBObject): TTableColumnList;
var
ColQuery: TDBQuery;

0 comments on commit c76695c

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