Show in constraint list and in generated SQL when a constraint is inherited

This commit is contained in:
eelke 2023-01-21 10:27:17 +01:00
parent 60fb4ce285
commit ccd88d0578
5 changed files with 50 additions and 22 deletions

View file

@ -55,6 +55,9 @@ QVariant ConstraintModel::headerData(int section, Qt::Orientation orientation, i
case SupportingIndexCol:
c = tr("Supporting index");
break;
case InheritedCol:
c = tr("Inherited");
break;
// case DefinitionCol:
// c = tr("Definition");
// break;
@ -85,11 +88,17 @@ int ConstraintModel::columnCount(const QModelIndex &) const
// return v;
//}
Oid ConstraintModel::getType(int ) const
Oid ConstraintModel::getType(int col) const
{
Oid oid = Pgsql::varchar_oid;
return oid;
Oid oid;
switch (col) {
case InheritedCol:
oid = Pgsql::bool_oid;
break;
default:
oid = Pgsql::varchar_oid;
}
return oid;
}
QString IconForConstraintType(ConstraintType ct)
@ -128,25 +137,27 @@ QVariant ConstraintModel::getData(const QModelIndex &index) const
const auto &t = m_constraints[row];
const int col = index.column();
QString s;
switch (col) {
switch (col) {
case TypeCol:
s = IconForConstraintType(t.type);
v = IconForConstraintType(t.type);
break;
case NameCol:
s = t.objectName();
v = t.objectName();
break;
case NsCol:
s = t.nsName();
v = t.nsName();
break;
case SupportingIndexCol:
s = getIndexDisplayString(*m_catalog, t.indid);
v = getIndexDisplayString(*m_catalog, t.indid);
break;
case InheritedCol:
v = t.isInherited();
break;
// case DefinitionCol:
// s = t.definition;
// break;
}
v = s;
return v;
}

View file

@ -19,6 +19,7 @@ public:
NameCol, ///
NsCol, ///
SupportingIndexCol,
InheritedCol,
// DefinitionCol,
colCount };

View file

@ -34,13 +34,21 @@ void CatalogConstraintPage::setFilter(const std::optional<PgClass> &cls)
void CatalogConstraintPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
{
auto rijen = selectedRows();
QString drops;
QString creates;
for (auto rij : rijen) {
const PgConstraint constraint = m_constraintModel->constraint(rij);
drops += constraint.dropSql() % "\n";
creates += constraint.createSql() % "\n";
}
m_definitionView->setPlainText(drops % "\n" % creates);
m_definitionView->setPlainText(
generateSql(
selectedRows()
)
);
}
QString CatalogConstraintPage::generateSql(const std::unordered_set<int> &rijen)
{
QString drops;
QString creates;
for (auto rij : rijen) {
const PgConstraint constraint = m_constraintModel->constraint(rij);
drops += constraint.dropSql() % "\n";
creates += constraint.createSql() % "\n";
}
return drops % "\n" % creates;
}

View file

@ -22,6 +22,7 @@ private:
ConstraintModel *m_constraintModel = nullptr;
QString generateSql(const std::unordered_set<int> &rows);
private slots:
void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
};