Show moer information about the indexes.
This commit is contained in:
parent
8c20bd6a02
commit
61645d44ac
5 changed files with 110 additions and 25 deletions
|
|
@ -7,7 +7,7 @@
|
||||||
#include "ResultTableModelUtil.h"
|
#include "ResultTableModelUtil.h"
|
||||||
#include "ColumnTableModel.h"
|
#include "ColumnTableModel.h"
|
||||||
#include "ConstraintModel.h"
|
#include "ConstraintModel.h"
|
||||||
#include "NamespaceFilterWidget.h"
|
//#include "NamespaceFilterWidget.h"
|
||||||
#include "IconColumnDelegate.h"
|
#include "IconColumnDelegate.h"
|
||||||
#include "IndexModel.h"
|
#include "IndexModel.h"
|
||||||
#include "SqlFormattingUtils.h"
|
#include "SqlFormattingUtils.h"
|
||||||
|
|
@ -43,6 +43,7 @@ TablesPage::TablesPage(MainWindow *parent)
|
||||||
font.setFixedPitch(true);
|
font.setFixedPitch(true);
|
||||||
font.setPointSize(10);
|
font.setPointSize(10);
|
||||||
ui->constraintSqlEdit->setFont(font);
|
ui->constraintSqlEdit->setFont(font);
|
||||||
|
ui->indexSqlEdit->setFont(font);
|
||||||
|
|
||||||
SetTableViewDefault(ui->indexesTable);
|
SetTableViewDefault(ui->indexesTable);
|
||||||
m_indexModel = new IndexModel(this);
|
m_indexModel = new IndexModel(this);
|
||||||
|
|
@ -50,8 +51,8 @@ TablesPage::TablesPage(MainWindow *parent)
|
||||||
ui->indexesTable->setItemDelegate(new PgLabItemDelegate(ui->indexesTable));
|
ui->indexesTable->setItemDelegate(new PgLabItemDelegate(ui->indexesTable));
|
||||||
ui->indexesTable->setItemDelegateForColumn(0, delegate);
|
ui->indexesTable->setItemDelegateForColumn(0, delegate);
|
||||||
|
|
||||||
m_namespaceFilterWidget = new NamespaceFilterWidget(this);
|
//m_namespaceFilterWidget = new NamespaceFilterWidget(this);
|
||||||
ui->verticalLayoutTableView->addWidget(m_namespaceFilterWidget);
|
//ui->verticalLayoutTableView->addWidget(m_namespaceFilterWidget);
|
||||||
|
|
||||||
|
|
||||||
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
connect(ui->tableListTable->selectionModel(), &QItemSelectionModel::currentRowChanged, this,
|
||||||
|
|
@ -63,6 +64,9 @@ TablesPage::TablesPage(MainWindow *parent)
|
||||||
connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
connect(ui->constraintsTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||||
&TablesPage::constraintsTable_selectionChanged);
|
&TablesPage::constraintsTable_selectionChanged);
|
||||||
|
|
||||||
|
connect(ui->indexesTable->selectionModel(), &QItemSelectionModel::selectionChanged, this,
|
||||||
|
&TablesPage::indexesTable_selectionChanged);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
TablesPage::~TablesPage()
|
TablesPage::~TablesPage()
|
||||||
|
|
@ -75,11 +79,12 @@ void TablesPage::setCatalog(std::shared_ptr<PgDatabaseCatalog> cat)
|
||||||
m_catalog = cat;
|
m_catalog = cat;
|
||||||
m_tablesModel->setCatalog(cat);
|
m_tablesModel->setCatalog(cat);
|
||||||
ui->tableListTable->resizeColumnsToContents();
|
ui->tableListTable->resizeColumnsToContents();
|
||||||
m_namespaceFilterWidget->init(cat->namespaces());
|
// m_namespaceFilterWidget->init(cat->namespaces());
|
||||||
|
|
||||||
auto highlighter = new SqlSyntaxHighlighter(ui->constraintSqlEdit->document());
|
auto highlighter = new SqlSyntaxHighlighter(ui->constraintSqlEdit->document());
|
||||||
highlighter->setTypes(*cat->types());
|
highlighter->setTypes(*cat->types());
|
||||||
|
highlighter = new SqlSyntaxHighlighter(ui->indexSqlEdit->document());
|
||||||
|
highlighter->setTypes(*cat->types());
|
||||||
}
|
}
|
||||||
|
|
||||||
void TablesPage::tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
void TablesPage::tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||||
|
|
@ -98,24 +103,26 @@ void TablesPage::tableListTable_currentRowChanged(const QModelIndex ¤t, co
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TablesPage::constraintsTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
//void TablesPage::constraintsTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous)
|
||||||
{
|
//{
|
||||||
if (current.row() != previous.row()) {
|
// if (current.row() != previous.row()) {
|
||||||
// QString drop_definition = m_constraintModel->dropDefinition(current.row());
|
//// QString drop_definition = m_constraintModel->dropDefinition(current.row());
|
||||||
// QString create_definition = m_constraintModel->createDefinition(current.row());
|
//// QString create_definition = m_constraintModel->createDefinition(current.row());
|
||||||
const PgConstraint& constraint = m_constraintModel->constraint(current.row());
|
// const PgConstraint& constraint = m_constraintModel->constraint(current.row());
|
||||||
QString drop = getDropConstraintDefinition(*m_catalog, constraint);
|
// QString drop = getDropConstraintDefinition(*m_catalog, constraint);
|
||||||
QString add = getConstraintDefinition(*m_catalog, constraint);
|
// QString add = getConstraintDefinition(*m_catalog, constraint);
|
||||||
|
|
||||||
ui->constraintSqlEdit->setPlainText(drop % QString::fromUtf16(u"\n") % add);
|
// ui->constraintSqlEdit->setPlainText(drop % QString::fromUtf16(u"\n") % add);
|
||||||
}
|
// }
|
||||||
}
|
//}
|
||||||
|
|
||||||
void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
||||||
{
|
{
|
||||||
const auto indexes = ui->constraintsTable->selectionModel()->selectedIndexes();
|
const auto indexes = ui->constraintsTable->selectionModel()->selectedIndexes();
|
||||||
boost::container::flat_set<int> rijen;
|
boost::container::flat_set<int> rijen;
|
||||||
for (const auto e : indexes) rijen.insert(e.row());
|
for (const auto e : indexes)
|
||||||
|
rijen.insert(e.row());
|
||||||
|
|
||||||
QString drops;
|
QString drops;
|
||||||
QString creates;
|
QString creates;
|
||||||
for (auto rij : rijen) {
|
for (auto rij : rijen) {
|
||||||
|
|
@ -126,6 +133,24 @@ void TablesPage::constraintsTable_selectionChanged(const QItemSelection &/*selec
|
||||||
ui->constraintSqlEdit->setPlainText(drops % "\n" % creates);
|
ui->constraintSqlEdit->setPlainText(drops % "\n" % creates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TablesPage::indexesTable_selectionChanged(const QItemSelection &/*selected*/, const QItemSelection &/*deselected*/)
|
||||||
|
{
|
||||||
|
const auto indexes = ui->indexesTable->selectionModel()->selectedIndexes();
|
||||||
|
boost::container::flat_set<int> rijen;
|
||||||
|
for (const auto e : indexes)
|
||||||
|
rijen.insert(e.row());
|
||||||
|
|
||||||
|
QString drops;
|
||||||
|
QString creates;
|
||||||
|
for (auto rij : rijen) {
|
||||||
|
const PgIndex index = m_indexModel->getIndex(rij);
|
||||||
|
//drops += getDropIndexDefinition(*m_catalog, index) % "\n";
|
||||||
|
creates += getIndexDefinition(*m_catalog, index) % "\n";
|
||||||
|
}
|
||||||
|
ui->indexSqlEdit->setPlainText(drops % "\n" % creates);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void TablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
void TablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
||||||
{
|
{
|
||||||
PgClass table = m_tablesModel->getTable(index.row());
|
PgClass table = m_tablesModel->getTable(index.row());
|
||||||
|
|
|
||||||
|
|
@ -34,13 +34,14 @@ private:
|
||||||
ColumnTableModel* m_columnsModel = nullptr;
|
ColumnTableModel* m_columnsModel = nullptr;
|
||||||
ConstraintModel* m_constraintModel = nullptr;
|
ConstraintModel* m_constraintModel = nullptr;
|
||||||
IndexModel* m_indexModel = nullptr;
|
IndexModel* m_indexModel = nullptr;
|
||||||
NamespaceFilterWidget* m_namespaceFilterWidget;
|
//NamespaceFilterWidget* m_namespaceFilterWidget;
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
|
|
||||||
void tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
void tableListTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void constraintsTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
// void constraintsTable_currentRowChanged(const QModelIndex ¤t, const QModelIndex &previous);
|
||||||
void constraintsTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
void constraintsTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
|
void indexesTable_selectionChanged(const QItemSelection &selected, const QItemSelection &deselected);
|
||||||
void on_tableListTable_doubleClicked(const QModelIndex &index);
|
void on_tableListTable_doubleClicked(const QModelIndex &index);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,8 +6,8 @@
|
||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>1041</width>
|
<width>993</width>
|
||||||
<height>830</height>
|
<height>754</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
|
|
@ -38,7 +38,7 @@
|
||||||
</widget>
|
</widget>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>1</number>
|
<number>2</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="columnsTab">
|
<widget class="QWidget" name="columnsTab">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
|
@ -76,7 +76,13 @@
|
||||||
</attribute>
|
</attribute>
|
||||||
<layout class="QVBoxLayout" name="verticalLayout_4">
|
<layout class="QVBoxLayout" name="verticalLayout_4">
|
||||||
<item>
|
<item>
|
||||||
|
<widget class="QSplitter" name="splitter_3">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
<widget class="QTableView" name="indexesTable"/>
|
<widget class="QTableView" name="indexesTable"/>
|
||||||
|
<widget class="QPlainTextEdit" name="indexSqlEdit"/>
|
||||||
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@
|
||||||
#include "PgAttributeContainer.h"
|
#include "PgAttributeContainer.h"
|
||||||
#include "PgClass.h"
|
#include "PgClass.h"
|
||||||
#include "PgClassContainer.h"
|
#include "PgClassContainer.h"
|
||||||
|
#include "PgIndex.h"
|
||||||
#include "PgNamespace.h"
|
#include "PgNamespace.h"
|
||||||
#include "PgNamespaceContainer.h"
|
#include "PgNamespaceContainer.h"
|
||||||
#include "PgDatabaseCatalog.h"
|
#include "PgDatabaseCatalog.h"
|
||||||
|
|
@ -19,7 +20,7 @@ bool identNeedsQuotes(QString ident)
|
||||||
if (ident[0].isDigit())
|
if (ident[0].isDigit())
|
||||||
return true;
|
return true;
|
||||||
for (auto c : ident)
|
for (auto c : ident)
|
||||||
if (c < 'a' && c > 'z' && c != '_')
|
if ((c < 'a' || c > 'z') && c != '_')
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
auto kw = getPgsqlKeyword(ident);
|
auto kw = getPgsqlKeyword(ident);
|
||||||
|
|
@ -170,6 +171,57 @@ QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstr
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString getIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &index)
|
||||||
|
{
|
||||||
|
PgClass table_class = catalog.classes()->getByKey(index.relid);
|
||||||
|
PgClass index_class = catalog.classes()->getByKey(index.indexrelid);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
QString result;
|
||||||
|
result = "CREATE ";
|
||||||
|
if (index.isunique)
|
||||||
|
result += "UNIQUE ";
|
||||||
|
result += "INDEX "
|
||||||
|
// % quoteIdent(getIndexDisplayString(catalog, index.indexrelid))
|
||||||
|
% quoteIdent(index_class.name)
|
||||||
|
% "\n ON " % genFQTableName(catalog, table_class);
|
||||||
|
// % "\n USING " % index_class.am lookup in pg_am table
|
||||||
|
return result;
|
||||||
|
|
||||||
|
#if 0
|
||||||
|
+ wxT("\n USING ") + GetIndexType()
|
||||||
|
+ wxT("\n (");
|
||||||
|
if (GetProcName().IsNull())
|
||||||
|
str += GetQuotedColumns();
|
||||||
|
else
|
||||||
|
{
|
||||||
|
str += GetQuotedSchemaPrefix(GetProcNamespace()) + qtIdent(GetProcName()) + wxT("(") + GetQuotedColumns() + wxT(")");
|
||||||
|
if (!this->GetOperatorClasses().IsNull())
|
||||||
|
str += wxT(" ") + GetOperatorClasses();
|
||||||
|
}
|
||||||
|
|
||||||
|
str += wxT(")");
|
||||||
|
|
||||||
|
if (GetConnection()->BackendMinimumVersion(8, 2) && GetFillFactor().Length() > 0)
|
||||||
|
str += wxT("\n WITH (FILLFACTOR=") + GetFillFactor() + wxT(")");
|
||||||
|
|
||||||
|
if (GetConnection()->BackendMinimumVersion(8, 0) && tablespace != GetDatabase()->GetDefaultTablespace())
|
||||||
|
str += wxT("\nTABLESPACE ") + qtIdent(tablespace);
|
||||||
|
|
||||||
|
AppendIfFilled(str, wxT("\n WHERE "), GetConstraint());
|
||||||
|
|
||||||
|
str += wxT(";\n");
|
||||||
|
|
||||||
|
if (GetConnection()->BackendMinimumVersion(7, 5))
|
||||||
|
if (GetIsClustered())
|
||||||
|
str += wxT("ALTER TABLE ") + GetQuotedSchemaPrefix(GetIdxSchema()) + qtIdent(GetIdxTable())
|
||||||
|
+ wxT(" CLUSTER ON ") + qtIdent(GetName())
|
||||||
|
+ wxT(";\n");
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
wxString sql;
|
wxString sql;
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@
|
||||||
class PgClass;
|
class PgClass;
|
||||||
class PgConstraint;
|
class PgConstraint;
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
|
class PgIndex;
|
||||||
|
|
||||||
bool identNeedsQuotes(QString ident);
|
bool identNeedsQuotes(QString ident);
|
||||||
QString quoteIdent(QString ident);
|
QString quoteIdent(QString ident);
|
||||||
|
|
@ -13,7 +14,7 @@ QString quoteIdent(QString ident);
|
||||||
QString genFQTableName(const PgDatabaseCatalog &catalog, const PgClass &cls);
|
QString genFQTableName(const PgDatabaseCatalog &catalog, const PgClass &cls);
|
||||||
QString getDropConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
QString getDropConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
||||||
QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
QString getConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
||||||
|
QString getIndexDefinition(const PgDatabaseCatalog &catalog, const PgIndex &index);
|
||||||
QString getForeignKeyConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
QString getForeignKeyConstraintDefinition(const PgDatabaseCatalog &catalog, const PgConstraint &constraint);
|
||||||
|
|
||||||
#endif // SQLFORMATTINGUTILS_H
|
#endif // SQLFORMATTINGUTILS_H
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue