comments on tables
Show them in the list of tables. Genereate SQL to set the comment.
This commit is contained in:
parent
7fbc828326
commit
9d58af8cd2
5 changed files with 34 additions and 18 deletions
|
|
@ -131,6 +131,7 @@ QVariant TablesTableModel::headerData(int section, Qt::Orientation orientation,
|
||||||
case TablespaceCol: return tr("Tablespace");
|
case TablespaceCol: return tr("Tablespace");
|
||||||
case OptionsCol: return tr("Options");
|
case OptionsCol: return tr("Options");
|
||||||
case AclCol: return tr("ACL");
|
case AclCol: return tr("ACL");
|
||||||
|
case CommentCol: return tr("Comment");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -140,7 +141,7 @@ QVariant TablesTableModel::headerData(int section, Qt::Orientation orientation,
|
||||||
// Basic functionality:
|
// Basic functionality:
|
||||||
int TablesTableModel::rowCount(const QModelIndex &) const
|
int TablesTableModel::rowCount(const QModelIndex &) const
|
||||||
{
|
{
|
||||||
return m_tables.size();
|
return static_cast<int>(m_tables.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
int TablesTableModel::columnCount(const QModelIndex &) const
|
int TablesTableModel::columnCount(const QModelIndex &) const
|
||||||
|
|
@ -159,6 +160,7 @@ Oid TablesTableModel::getType(int column) const
|
||||||
case KindCol:
|
case KindCol:
|
||||||
case OptionsCol:
|
case OptionsCol:
|
||||||
case AclCol:
|
case AclCol:
|
||||||
|
case CommentCol:
|
||||||
default:
|
default:
|
||||||
oid = Pgsql::varchar_oid;
|
oid = Pgsql::varchar_oid;
|
||||||
}
|
}
|
||||||
|
|
@ -176,6 +178,7 @@ QVariant TablesTableModel::getData(const QModelIndex &index) const
|
||||||
case TablespaceCol: return getTablespaceDisplayString(*m_catalog, t.tablespace);
|
case TablespaceCol: return getTablespaceDisplayString(*m_catalog, t.tablespace);
|
||||||
case OptionsCol: break;
|
case OptionsCol: break;
|
||||||
case AclCol: return t.aclString();
|
case AclCol: return t.aclString();
|
||||||
|
case CommentCol: return t.description;
|
||||||
}
|
}
|
||||||
|
|
||||||
return QVariant();
|
return QVariant();
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ public:
|
||||||
TablespaceCol,
|
TablespaceCol,
|
||||||
OptionsCol,
|
OptionsCol,
|
||||||
AclCol,
|
AclCol,
|
||||||
|
CommentCol,
|
||||||
colCount };
|
colCount };
|
||||||
|
|
||||||
TablesTableModel(QObject *parent);
|
TablesTableModel(QObject *parent);
|
||||||
|
|
|
||||||
|
|
@ -10,6 +10,7 @@
|
||||||
#include "SqlCodePreview.h"
|
#include "SqlCodePreview.h"
|
||||||
#include "TablesTableModel.h"
|
#include "TablesTableModel.h"
|
||||||
#include "TriggerPage.h"
|
#include "TriggerPage.h"
|
||||||
|
#include "SqlFormattingUtils.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"
|
||||||
|
|
@ -186,22 +187,26 @@ void CatalogTablesPage::updateSqlTab(const std::optional<PgClass> &table)
|
||||||
// table details (inherits etc)
|
// table details (inherits etc)
|
||||||
|
|
||||||
// Indexes
|
// Indexes
|
||||||
drop_sql += "-- drop Indexes\n";
|
|
||||||
create_sql += "-- create Indexes\n";
|
|
||||||
auto && indexes = m_catalog->indexes()->getIndexesForTable(table->oid());
|
auto && indexes = m_catalog->indexes()->getIndexesForTable(table->oid());
|
||||||
for (auto && index : indexes) {
|
if (!indexes.empty()) {
|
||||||
drop_sql += index.dropSql() % "\n";
|
drop_sql += "-- drop Indexes\n";
|
||||||
create_sql += index.createSql() % "\n";
|
create_sql += "-- create Indexes\n";
|
||||||
}
|
for (auto && index : indexes) {
|
||||||
|
drop_sql += index.dropSql() % "\n";
|
||||||
|
create_sql += index.createSql() % "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Triggers
|
// Triggers
|
||||||
drop_sql += "-- drop Triggers\n";
|
auto && triggers = m_catalog->triggers()->getTriggersForRelation(table->oid());
|
||||||
create_sql += "-- create Triggers\n";
|
if (!triggers.empty()) {
|
||||||
auto && triggers = m_catalog->triggers()->getTriggersForRelation(table->oid());
|
drop_sql += "-- drop Triggers\n";
|
||||||
for (auto && trg : triggers) {
|
create_sql += "-- create Triggers\n";
|
||||||
drop_sql += trg.dropSql() % "\n";
|
for (auto && trg : triggers) {
|
||||||
create_sql += trg.createSql() % "\n";
|
drop_sql += trg.dropSql() % "\n";
|
||||||
}
|
create_sql += trg.createSql() % "\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Privileges
|
// Privileges
|
||||||
create_sql += "-- set Privileges\n";
|
create_sql += "-- set Privileges\n";
|
||||||
|
|
@ -209,6 +214,10 @@ void CatalogTablesPage::updateSqlTab(const std::optional<PgClass> &table)
|
||||||
|
|
||||||
// Comments
|
// Comments
|
||||||
create_sql += "-- set Comments table + columns\n";
|
create_sql += "-- set Comments table + columns\n";
|
||||||
//
|
if (!table->description.isEmpty()) {
|
||||||
|
create_sql += "COMMENT ON TABLE " + table->fullyQualifiedQuotedObjectName()
|
||||||
|
+ " IS " + dollarQuoteString(table->description) + ";\n";
|
||||||
|
}
|
||||||
|
//
|
||||||
m_tableSql->setPlainText(drop_sql % "\n\n" % create_sql);
|
m_tableSql->setPlainText(drop_sql % "\n\n" % create_sql);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -49,6 +49,8 @@ public:
|
||||||
std::vector<QString> options;
|
std::vector<QString> options;
|
||||||
QString viewdef;
|
QString viewdef;
|
||||||
|
|
||||||
|
QString description; // from pg_description
|
||||||
|
|
||||||
using PgNamespaceObject::PgNamespaceObject;
|
using PgNamespaceObject::PgNamespaceObject;
|
||||||
|
|
||||||
QString kindString() const;
|
QString kindString() const;
|
||||||
|
|
|
||||||
|
|
@ -11,13 +11,14 @@ std::string PgClassContainer::getLoadQuery() const
|
||||||
" relowner, relam, relfilenode, reltablespace, relpages, "
|
" relowner, relam, relfilenode, reltablespace, relpages, "
|
||||||
" reltuples, reltoastrelid, relisshared, relpersistence, "
|
" reltuples, reltoastrelid, relisshared, relpersistence, "
|
||||||
" relkind, relispopulated, relfrozenxid, relminmxid, "
|
" relkind, relispopulated, relfrozenxid, relminmxid, "
|
||||||
" reloptions, relacl, pg_get_viewdef(oid)";
|
" reloptions, d.description, relacl, pg_get_viewdef(oid)";
|
||||||
|
|
||||||
if (lessThenVersion(120000))
|
if (lessThenVersion(120000))
|
||||||
q += ", relhasoids ";
|
q += ", relhasoids ";
|
||||||
|
|
||||||
q +=
|
q +=
|
||||||
"\nFROM pg_catalog.pg_class \n"
|
"\nFROM pg_catalog.pg_class \n"
|
||||||
|
" LEFT JOIN pg_catalog.pg_description AS d ON (objoid=pg_class.oid AND objsubid=0) \n"
|
||||||
"WHERE relkind IN ('r', 'i', 'p', 'I', 'v', 'm', 'f')";
|
"WHERE relkind IN ('r', 'i', 'p', 'I', 'v', 'm', 'f')";
|
||||||
|
|
||||||
return q;
|
return q;
|
||||||
|
|
@ -35,8 +36,8 @@ PgClass PgClassContainer::loadElem(const Pgsql::Row &row)
|
||||||
col >> v.type >> v.oftype
|
col >> v.type >> v.oftype
|
||||||
>> owner >> v.am >> v.filenode >> v.tablespace >> v.pages_est
|
>> owner >> v.am >> v.filenode >> v.tablespace >> v.pages_est
|
||||||
>> v.tuples_est >> v.toastrelid >> v.isshared >> v.persistence
|
>> v.tuples_est >> v.toastrelid >> v.isshared >> v.persistence
|
||||||
>> v.kind >> v.ispopulated >> v.frozenxid >> v.minmxid
|
>> v.kind >> v.ispopulated >> v.frozenxid >> v.minmxid
|
||||||
>> v.options;
|
>> v.options >> v.description;
|
||||||
|
|
||||||
|
|
||||||
v.setOwnerOid(owner);
|
v.setOwnerOid(owner);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue