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 OptionsCol: return tr("Options");
|
||||
case AclCol: return tr("ACL");
|
||||
case CommentCol: return tr("Comment");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -140,7 +141,7 @@ QVariant TablesTableModel::headerData(int section, Qt::Orientation orientation,
|
|||
// Basic functionality:
|
||||
int TablesTableModel::rowCount(const QModelIndex &) const
|
||||
{
|
||||
return m_tables.size();
|
||||
return static_cast<int>(m_tables.size());
|
||||
}
|
||||
|
||||
int TablesTableModel::columnCount(const QModelIndex &) const
|
||||
|
|
@ -159,6 +160,7 @@ Oid TablesTableModel::getType(int column) const
|
|||
case KindCol:
|
||||
case OptionsCol:
|
||||
case AclCol:
|
||||
case CommentCol:
|
||||
default:
|
||||
oid = Pgsql::varchar_oid;
|
||||
}
|
||||
|
|
@ -176,6 +178,7 @@ QVariant TablesTableModel::getData(const QModelIndex &index) const
|
|||
case TablespaceCol: return getTablespaceDisplayString(*m_catalog, t.tablespace);
|
||||
case OptionsCol: break;
|
||||
case AclCol: return t.aclString();
|
||||
case CommentCol: return t.description;
|
||||
}
|
||||
|
||||
return QVariant();
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ public:
|
|||
TablespaceCol,
|
||||
OptionsCol,
|
||||
AclCol,
|
||||
CommentCol,
|
||||
colCount };
|
||||
|
||||
TablesTableModel(QObject *parent);
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@
|
|||
#include "SqlCodePreview.h"
|
||||
#include "TablesTableModel.h"
|
||||
#include "TriggerPage.h"
|
||||
#include "SqlFormattingUtils.h"
|
||||
#include "catalog/PgIndexContainer.h"
|
||||
#include "catalog/PgTriggerContainer.h"
|
||||
#include "widgets/CatalogConstraintPage.h"
|
||||
|
|
@ -186,22 +187,26 @@ void CatalogTablesPage::updateSqlTab(const std::optional<PgClass> &table)
|
|||
// table details (inherits etc)
|
||||
|
||||
// Indexes
|
||||
drop_sql += "-- drop Indexes\n";
|
||||
create_sql += "-- create Indexes\n";
|
||||
auto && indexes = m_catalog->indexes()->getIndexesForTable(table->oid());
|
||||
for (auto && index : indexes) {
|
||||
drop_sql += index.dropSql() % "\n";
|
||||
create_sql += index.createSql() % "\n";
|
||||
}
|
||||
if (!indexes.empty()) {
|
||||
drop_sql += "-- drop Indexes\n";
|
||||
create_sql += "-- create Indexes\n";
|
||||
for (auto && index : indexes) {
|
||||
drop_sql += index.dropSql() % "\n";
|
||||
create_sql += index.createSql() % "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Triggers
|
||||
drop_sql += "-- drop Triggers\n";
|
||||
create_sql += "-- create Triggers\n";
|
||||
auto && triggers = m_catalog->triggers()->getTriggersForRelation(table->oid());
|
||||
for (auto && trg : triggers) {
|
||||
drop_sql += trg.dropSql() % "\n";
|
||||
create_sql += trg.createSql() % "\n";
|
||||
}
|
||||
auto && triggers = m_catalog->triggers()->getTriggersForRelation(table->oid());
|
||||
if (!triggers.empty()) {
|
||||
drop_sql += "-- drop Triggers\n";
|
||||
create_sql += "-- create Triggers\n";
|
||||
for (auto && trg : triggers) {
|
||||
drop_sql += trg.dropSql() % "\n";
|
||||
create_sql += trg.createSql() % "\n";
|
||||
}
|
||||
}
|
||||
|
||||
// Privileges
|
||||
create_sql += "-- set Privileges\n";
|
||||
|
|
@ -209,6 +214,10 @@ void CatalogTablesPage::updateSqlTab(const std::optional<PgClass> &table)
|
|||
|
||||
// Comments
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue