In the list of columns displayed for a table a set of columns is appended describing the indexes on the table.
This commit is contained in:
parent
aef9b914b1
commit
172e2bcd1d
9 changed files with 95 additions and 43 deletions
|
|
@ -128,7 +128,7 @@ bool ASyncDBConnection::send(const std::string &command, Pgsql::Params params, o
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ASyncDBConnection::async_query_handler(boost::system::error_code ec, std::size_t s, on_result_callback on_result)
|
void ASyncDBConnection::async_query_handler(boost::system::error_code ec, std::size_t /*s*/, on_result_callback on_result)
|
||||||
{
|
{
|
||||||
if (ec == boost::system::errc::success) {
|
if (ec == boost::system::errc::success) {
|
||||||
bool finished = false;
|
bool finished = false;
|
||||||
|
|
|
||||||
|
|
@ -248,7 +248,7 @@ void BackupDialog::on_btnStart_clicked()
|
||||||
p->start(program, arguments);
|
p->start(program, arguments);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BackupDialog::on_backupFormat_currentIndexChanged(int index)
|
void BackupDialog::on_backupFormat_currentIndexChanged(int /*index*/)
|
||||||
{
|
{
|
||||||
int format_index = ui->backupFormat->currentIndex();
|
int format_index = ui->backupFormat->currentIndex();
|
||||||
auto format_model_base = ui->backupFormat->model();
|
auto format_model_base = ui->backupFormat->model();
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@
|
||||||
#include "PgAttributeContainer.h"
|
#include "PgAttributeContainer.h"
|
||||||
#include "PgType.h"
|
#include "PgType.h"
|
||||||
#include "PgTypeContainer.h"
|
#include "PgTypeContainer.h"
|
||||||
|
#include "PgIndexContainer.h"
|
||||||
#include "ScopeGuard.h"
|
#include "ScopeGuard.h"
|
||||||
#include <QBrush>
|
#include <QBrush>
|
||||||
|
|
||||||
|
|
@ -23,6 +24,14 @@ void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, Oid
|
||||||
// sort remaining columns by order in table
|
// sort remaining columns by order in table
|
||||||
std::sort(m_columns.begin(), m_columns.end(),
|
std::sort(m_columns.begin(), m_columns.end(),
|
||||||
[] (auto &l, auto &r) -> bool { return l.num < r.num; });
|
[] (auto &l, auto &r) -> bool { return l.num < r.num; });
|
||||||
|
|
||||||
|
m_indexes = m_catalog->indexes()->getIndexesForTable(table_oid);
|
||||||
|
std::sort(m_indexes.begin(), m_indexes.end(),
|
||||||
|
[] (const auto &l, const auto &r) -> bool
|
||||||
|
{
|
||||||
|
return l.isprimary > r.isprimary
|
||||||
|
|| (l.isprimary == r.isprimary && l.indexrelid < r.indexrelid);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation, int role) const
|
||||||
|
|
@ -31,6 +40,16 @@ QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation,
|
||||||
if (orientation == Qt::Horizontal) {
|
if (orientation == Qt::Horizontal) {
|
||||||
if (role == Qt::DisplayRole) {
|
if (role == Qt::DisplayRole) {
|
||||||
QString c;
|
QString c;
|
||||||
|
if (section >= colCount) {
|
||||||
|
const auto &tbl_idx = m_indexes[section - colCount];
|
||||||
|
if (tbl_idx.isprimary)
|
||||||
|
c = "Pri";
|
||||||
|
else if (tbl_idx.isunique)
|
||||||
|
c = "Unq";
|
||||||
|
else
|
||||||
|
c = "Idx";
|
||||||
|
}
|
||||||
|
else {
|
||||||
switch (section) {
|
switch (section) {
|
||||||
case NameCol:
|
case NameCol:
|
||||||
c = tr("Name");
|
c = tr("Name");
|
||||||
|
|
@ -48,6 +67,7 @@ QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation,
|
||||||
c = tr("Collation");
|
c = tr("Collation");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
v = c;
|
v = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -62,7 +82,7 @@ int ColumnTableModel::rowCount(const QModelIndex &/*parent*/) const
|
||||||
|
|
||||||
int ColumnTableModel::columnCount(const QModelIndex &/*parent*/) const
|
int ColumnTableModel::columnCount(const QModelIndex &/*parent*/) const
|
||||||
{
|
{
|
||||||
return colCount;
|
return colCount + m_indexes.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
Oid ColumnTableModel::getType(int /*column*/) const
|
Oid ColumnTableModel::getType(int /*column*/) const
|
||||||
|
|
@ -86,9 +106,24 @@ Oid ColumnTableModel::getType(int /*column*/) const
|
||||||
QVariant ColumnTableModel::getData(const QModelIndex &index) const
|
QVariant ColumnTableModel::getData(const QModelIndex &index) const
|
||||||
{
|
{
|
||||||
QVariant v;
|
QVariant v;
|
||||||
const auto &t = m_columns[index.row()];
|
const int row = index.row();
|
||||||
|
const auto &t = m_columns[row];
|
||||||
|
|
||||||
|
const int col = index.column();
|
||||||
|
if (col >= colCount) {
|
||||||
|
const auto &tbl_idx = m_indexes[col - colCount];
|
||||||
|
int i = 1;
|
||||||
|
for (auto attr : tbl_idx.key) {
|
||||||
|
if (attr == t.num) {
|
||||||
|
v = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
QString s;
|
QString s;
|
||||||
switch (index.column()) {
|
switch (col) {
|
||||||
case NameCol:
|
case NameCol:
|
||||||
s = t.name;
|
s = t.name;
|
||||||
break;
|
break;
|
||||||
|
|
@ -106,6 +141,7 @@ QVariant ColumnTableModel::getData(const QModelIndex &index) const
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
v = s;
|
v = s;
|
||||||
|
}
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,9 @@
|
||||||
#define COLUMNTABLEMODEL_H
|
#define COLUMNTABLEMODEL_H
|
||||||
|
|
||||||
#include "BaseTableModel.h"
|
#include "BaseTableModel.h"
|
||||||
|
#include "PgIndex.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
class PgDatabaseCatalog;
|
class PgDatabaseCatalog;
|
||||||
class PgAttribute;
|
class PgAttribute;
|
||||||
|
|
@ -38,6 +40,7 @@ protected:
|
||||||
|
|
||||||
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
std::shared_ptr<const PgDatabaseCatalog> m_catalog;
|
||||||
t_Columns m_columns;
|
t_Columns m_columns;
|
||||||
|
std::vector<PgIndex> m_indexes;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -166,7 +166,7 @@ void ConnectionManagerWindow::on_testButton_clicked()
|
||||||
QMessageBox::information(this, "pglab",
|
QMessageBox::information(this, "pglab",
|
||||||
QString::fromUtf8(s.c_str()), QMessageBox::Yes);
|
QString::fromUtf8(s.c_str()), QMessageBox::Yes);
|
||||||
}
|
}
|
||||||
catch (Botan::Decoding_Error &e) {
|
catch (Botan::Decoding_Error &/*e*/) {
|
||||||
QMessageBox::information(this, "pglab",
|
QMessageBox::information(this, "pglab",
|
||||||
tr("Failure to decrypt"), QMessageBox::Yes);
|
tr("Failure to decrypt"), QMessageBox::Yes);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -15,8 +15,8 @@ void ParamTypeDelegate::setTypeSelectionModel(TypeSelectionItemModel* model)
|
||||||
}
|
}
|
||||||
|
|
||||||
QWidget *ParamTypeDelegate::createEditor(QWidget *parent,
|
QWidget *ParamTypeDelegate::createEditor(QWidget *parent,
|
||||||
const QStyleOptionViewItem &option,
|
const QStyleOptionViewItem &/*option*/,
|
||||||
const QModelIndex &index) const
|
const QModelIndex &/*index*/) const
|
||||||
|
|
||||||
{
|
{
|
||||||
QWidget *w = nullptr;
|
QWidget *w = nullptr;
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ public:
|
||||||
std::vector<int16_t> option;
|
std::vector<int16_t> option;
|
||||||
QString exprs;
|
QString exprs;
|
||||||
QString pred;
|
QString pred;
|
||||||
|
QString definition;
|
||||||
|
|
||||||
PgIndex();
|
PgIndex();
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -8,7 +8,8 @@ std::string PgIndexContainer::getLoadQuery() const
|
||||||
SELECT indexrelid, indrelid, indnatts, indisunique, indisprimary,
|
SELECT indexrelid, indrelid, indnatts, indisunique, indisprimary,
|
||||||
indisexclusion, indimmediate, indisclustered, indisvalid,
|
indisexclusion, indimmediate, indisclustered, indisvalid,
|
||||||
indcheckxmin, indisready, indislive, indisreplident, indkey,
|
indcheckxmin, indisready, indislive, indisreplident, indkey,
|
||||||
indcollation, indclass, indoption, indexprs, indpred
|
indcollation, indclass, indoption, indexprs, indpred,
|
||||||
|
pg_get_indexdef(indexrelid)
|
||||||
FROM pg_index)__";
|
FROM pg_index)__";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -23,6 +24,16 @@ PgIndex PgIndexContainer::loadElem(const Pgsql::Row &row)
|
||||||
col.getAsVector<Oid>(std::back_inserter(v.collation));
|
col.getAsVector<Oid>(std::back_inserter(v.collation));
|
||||||
col.getAsVector<Oid>(std::back_inserter(v.indclass));
|
col.getAsVector<Oid>(std::back_inserter(v.indclass));
|
||||||
col.getAsVector<int16_t>(std::back_inserter(v.option));
|
col.getAsVector<int16_t>(std::back_inserter(v.option));
|
||||||
col >> v.exprs >> v.pred;
|
col >> v.exprs >> v.pred >> v.definition;
|
||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<PgIndex> PgIndexContainer::getIndexesForTable(Oid table_oid) const
|
||||||
|
{
|
||||||
|
std::vector<PgIndex> result;
|
||||||
|
for (const auto &e : m_container)
|
||||||
|
if (e.relid == table_oid)
|
||||||
|
result.push_back(e);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ public:
|
||||||
using PgContainer<PgIndex>::PgContainer;
|
using PgContainer<PgIndex>::PgContainer;
|
||||||
|
|
||||||
virtual std::string getLoadQuery() const override;
|
virtual std::string getLoadQuery() const override;
|
||||||
|
std::vector<PgIndex> getIndexesForTable(Oid table_oid) const;
|
||||||
protected:
|
protected:
|
||||||
virtual PgIndex loadElem(const Pgsql::Row &row) override;
|
virtual PgIndex loadElem(const Pgsql::Row &row) override;
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue