Show in constraint list and in generated SQL when a constraint is inherited
This commit is contained in:
parent
60fb4ce285
commit
ccd88d0578
5 changed files with 50 additions and 22 deletions
|
|
@ -55,6 +55,9 @@ QVariant ConstraintModel::headerData(int section, Qt::Orientation orientation, i
|
||||||
case SupportingIndexCol:
|
case SupportingIndexCol:
|
||||||
c = tr("Supporting index");
|
c = tr("Supporting index");
|
||||||
break;
|
break;
|
||||||
|
case InheritedCol:
|
||||||
|
c = tr("Inherited");
|
||||||
|
break;
|
||||||
// case DefinitionCol:
|
// case DefinitionCol:
|
||||||
// c = tr("Definition");
|
// c = tr("Definition");
|
||||||
// break;
|
// break;
|
||||||
|
|
@ -85,11 +88,17 @@ int ConstraintModel::columnCount(const QModelIndex &) const
|
||||||
// return v;
|
// return v;
|
||||||
//}
|
//}
|
||||||
|
|
||||||
Oid ConstraintModel::getType(int ) const
|
Oid ConstraintModel::getType(int col) const
|
||||||
{
|
{
|
||||||
Oid oid = Pgsql::varchar_oid;
|
Oid oid;
|
||||||
|
switch (col) {
|
||||||
return oid;
|
case InheritedCol:
|
||||||
|
oid = Pgsql::bool_oid;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
oid = Pgsql::varchar_oid;
|
||||||
|
}
|
||||||
|
return oid;
|
||||||
}
|
}
|
||||||
|
|
||||||
QString IconForConstraintType(ConstraintType ct)
|
QString IconForConstraintType(ConstraintType ct)
|
||||||
|
|
@ -128,25 +137,27 @@ QVariant ConstraintModel::getData(const QModelIndex &index) const
|
||||||
const auto &t = m_constraints[row];
|
const auto &t = m_constraints[row];
|
||||||
|
|
||||||
const int col = index.column();
|
const int col = index.column();
|
||||||
QString s;
|
|
||||||
switch (col) {
|
switch (col) {
|
||||||
case TypeCol:
|
case TypeCol:
|
||||||
s = IconForConstraintType(t.type);
|
v = IconForConstraintType(t.type);
|
||||||
break;
|
break;
|
||||||
case NameCol:
|
case NameCol:
|
||||||
s = t.objectName();
|
v = t.objectName();
|
||||||
break;
|
break;
|
||||||
case NsCol:
|
case NsCol:
|
||||||
s = t.nsName();
|
v = t.nsName();
|
||||||
break;
|
break;
|
||||||
case SupportingIndexCol:
|
case SupportingIndexCol:
|
||||||
s = getIndexDisplayString(*m_catalog, t.indid);
|
v = getIndexDisplayString(*m_catalog, t.indid);
|
||||||
break;
|
break;
|
||||||
|
case InheritedCol:
|
||||||
|
v = t.isInherited();
|
||||||
|
break;
|
||||||
// case DefinitionCol:
|
// case DefinitionCol:
|
||||||
// s = t.definition;
|
// s = t.definition;
|
||||||
// break;
|
// break;
|
||||||
}
|
}
|
||||||
v = s;
|
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ public:
|
||||||
NameCol, ///
|
NameCol, ///
|
||||||
NsCol, ///
|
NsCol, ///
|
||||||
SupportingIndexCol,
|
SupportingIndexCol,
|
||||||
|
InheritedCol,
|
||||||
// DefinitionCol,
|
// DefinitionCol,
|
||||||
colCount };
|
colCount };
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,21 @@ void CatalogConstraintPage::setFilter(const std::optional<PgClass> &cls)
|
||||||
|
|
||||||
void CatalogConstraintPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
void CatalogConstraintPage::tableView_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
||||||
{
|
{
|
||||||
auto rijen = selectedRows();
|
m_definitionView->setPlainText(
|
||||||
QString drops;
|
generateSql(
|
||||||
QString creates;
|
selectedRows()
|
||||||
for (auto rij : rijen) {
|
)
|
||||||
const PgConstraint constraint = m_constraintModel->constraint(rij);
|
);
|
||||||
drops += constraint.dropSql() % "\n";
|
}
|
||||||
creates += constraint.createSql() % "\n";
|
|
||||||
}
|
QString CatalogConstraintPage::generateSql(const std::unordered_set<int> &rijen)
|
||||||
m_definitionView->setPlainText(drops % "\n" % creates);
|
{
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ private:
|
||||||
|
|
||||||
ConstraintModel *m_constraintModel = nullptr;
|
ConstraintModel *m_constraintModel = nullptr;
|
||||||
|
|
||||||
|
QString generateSql(const std::unordered_set<int> &rows);
|
||||||
private slots:
|
private slots:
|
||||||
void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
void tableView_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include "PgConstraint.h"
|
#include "PgConstraint.h"
|
||||||
#include "SqlFormattingUtils.h"
|
#include "SqlFormattingUtils.h"
|
||||||
|
#include <QStringBuilder>
|
||||||
|
|
||||||
void operator<<(ConstraintType &s, const Pgsql::Value &v)
|
void operator<<(ConstraintType &s, const Pgsql::Value &v)
|
||||||
{
|
{
|
||||||
|
|
@ -176,10 +177,16 @@ QString PgConstraint::typeName() const
|
||||||
|
|
||||||
QString PgConstraint::dropSql() const
|
QString PgConstraint::dropSql() const
|
||||||
{
|
{
|
||||||
return getDropConstraintDefinition(catalog(), *this);
|
if (isInherited())
|
||||||
|
return "-- " % objectName() % " is inherited";
|
||||||
|
|
||||||
|
return getDropConstraintDefinition(catalog(), *this);
|
||||||
}
|
}
|
||||||
|
|
||||||
QString PgConstraint::createSql() const
|
QString PgConstraint::createSql() const
|
||||||
{
|
{
|
||||||
return getAlterTableConstraintDefinition(catalog(), *this);
|
if (isInherited())
|
||||||
|
return "-- " % objectName() % " is inherited";
|
||||||
|
|
||||||
|
return getAlterTableConstraintDefinition(catalog(), *this);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue