comments on columns
Show the comments in the list of columns of a table. Generate SQL to set them.
This commit is contained in:
parent
9d58af8cd2
commit
d6aeef492d
5 changed files with 23 additions and 3 deletions
|
|
@ -77,6 +77,9 @@ QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation,
|
||||||
case CollationCol:
|
case CollationCol:
|
||||||
c = tr("Collation");
|
c = tr("Collation");
|
||||||
break;
|
break;
|
||||||
|
case CommentCol:
|
||||||
|
c = tr("Comment");
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
v = c;
|
v = c;
|
||||||
|
|
@ -200,6 +203,9 @@ QVariant ColumnTableModel::getData(const QModelIndex &index) const
|
||||||
v = col->objectName();
|
v = col->objectName();
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case CommentCol:
|
||||||
|
v = t.description;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@ public:
|
||||||
DefaultCol,
|
DefaultCol,
|
||||||
ForeignKeyCol,
|
ForeignKeyCol,
|
||||||
CollationCol,
|
CollationCol,
|
||||||
|
CommentCol,
|
||||||
|
|
||||||
colCount };
|
colCount };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@
|
||||||
#include "TablesTableModel.h"
|
#include "TablesTableModel.h"
|
||||||
#include "TriggerPage.h"
|
#include "TriggerPage.h"
|
||||||
#include "SqlFormattingUtils.h"
|
#include "SqlFormattingUtils.h"
|
||||||
|
#include "catalog/PgAttributeContainer.h"
|
||||||
#include "catalog/PgIndexContainer.h"
|
#include "catalog/PgIndexContainer.h"
|
||||||
#include "catalog/PgTriggerContainer.h"
|
#include "catalog/PgTriggerContainer.h"
|
||||||
#include "widgets/CatalogConstraintPage.h"
|
#include "widgets/CatalogConstraintPage.h"
|
||||||
|
|
@ -218,6 +219,15 @@ void CatalogTablesPage::updateSqlTab(const std::optional<PgClass> &table)
|
||||||
create_sql += "COMMENT ON TABLE " + table->fullyQualifiedQuotedObjectName()
|
create_sql += "COMMENT ON TABLE " + table->fullyQualifiedQuotedObjectName()
|
||||||
+ " IS " + dollarQuoteString(table->description) + ";\n";
|
+ " IS " + dollarQuoteString(table->description) + ";\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto && cols = m_catalog->attributes()->getColumnsForRelation(table->oid());
|
||||||
|
for (auto && col : cols) {
|
||||||
|
if (!col.description.isEmpty()) {
|
||||||
|
create_sql += "COMMENT ON COLUMN " + table->fullyQualifiedQuotedObjectName()
|
||||||
|
+ "." + quoteIdent(col.name) + " IS " + dollarQuoteString(col.description) + ";\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
m_tableSql->setPlainText(drop_sql % "\n\n" % create_sql);
|
m_tableSql->setPlainText(drop_sql % "\n\n" % create_sql);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@ public:
|
||||||
|
|
||||||
QString defaultValue; ///< Comes from pg_attrdef table
|
QString defaultValue; ///< Comes from pg_attrdef table
|
||||||
QString sername, serschema; // serial sequence name and schema
|
QString sername, serschema; // serial sequence name and schema
|
||||||
|
QString description; ///< from pg_description
|
||||||
|
|
||||||
bool operator==(Key _k) const { return relid == std::get<0>(_k) && num == std::get<1>(_k); }
|
bool operator==(Key _k) const { return relid == std::get<0>(_k) && num == std::get<1>(_k); }
|
||||||
bool operator==(const QString &n) const { return name == n; }
|
bool operator==(const QString &n) const { return name == n; }
|
||||||
|
|
|
||||||
|
|
@ -12,14 +12,16 @@ std::string PgAttributeContainer::getLoadQuery() const
|
||||||
std::string q = R"__(
|
std::string q = R"__(
|
||||||
SELECT attrelid, attname, atttypid, attstattarget,
|
SELECT attrelid, attname, atttypid, attstattarget,
|
||||||
attnum, attndims, atttypmod, attnotnull, atthasdef, attisdropped,
|
attnum, attndims, atttypmod, attnotnull, atthasdef, attisdropped,
|
||||||
attislocal, attcollation, attacl, attoptions, pg_get_expr(def.adbin, def.adrelid) AS def_value, cs.relname AS sername, ns.nspname AS serschema)__";
|
attislocal, attcollation, attacl, attoptions, pg_get_expr(def.adbin, def.adrelid) AS def_value,
|
||||||
|
cs.relname AS sername, ns.nspname AS serschema, d.description)__";
|
||||||
if (m_catalog.serverVersion() >= 100000)
|
if (m_catalog.serverVersion() >= 100000)
|
||||||
q += ", attidentity";
|
q += ", attidentity";
|
||||||
q += R"__(
|
q += R"__(
|
||||||
FROM pg_catalog.pg_attribute AS att
|
FROM pg_catalog.pg_attribute AS att
|
||||||
LEFT JOIN pg_attrdef AS def ON attrelid=adrelid AND attnum=adnum
|
LEFT JOIN pg_attrdef AS def ON attrelid=adrelid AND attnum=adnum
|
||||||
LEFT JOIN (pg_depend JOIN pg_class cs ON classid='pg_class'::regclass AND objid=cs.oid AND cs.relkind='S') ON refobjid=att.attrelid AND refobjsubid=att.attnum
|
LEFT JOIN (pg_depend JOIN pg_class cs ON classid='pg_class'::regclass AND objid=cs.oid AND cs.relkind='S') ON refobjid=att.attrelid AND refobjsubid=att.attnum
|
||||||
LEFT JOIN pg_namespace ns ON ns.oid=cs.relnamespace)__";
|
LEFT JOIN pg_namespace ns ON ns.oid=cs.relnamespace
|
||||||
|
LEFT JOIN pg_catalog.pg_description AS d ON (objoid=attrelid AND d.objsubid=attnum))__";
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
}
|
}
|
||||||
|
|
@ -31,7 +33,7 @@ PgAttribute PgAttributeContainer::loadElem(const Pgsql::Row &row)
|
||||||
col >> v.relid >> v.name >> v.typid >> v.stattarget
|
col >> v.relid >> v.name >> v.typid >> v.stattarget
|
||||||
>> v.num >> v.ndims >> v.typmod >> v.notnull >> v.hasdef >> v.isdropped
|
>> v.num >> v.ndims >> v.typmod >> v.notnull >> v.hasdef >> v.isdropped
|
||||||
>> v.islocal >> v.collation >> v.acl >> v.options >> v.defaultValue
|
>> v.islocal >> v.collation >> v.acl >> v.options >> v.defaultValue
|
||||||
>> v.sername >> v.serschema;
|
>> v.sername >> v.serschema >> v.description;
|
||||||
if (m_catalog.serverVersion() >= 100000)
|
if (m_catalog.serverVersion() >= 100000)
|
||||||
col >> v.identity;
|
col >> v.identity;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue