Rework of catalog objects. Several of them are now inheriting from common
base classes that implement common functionality.
This commit is contained in:
parent
840af1e0a9
commit
73c4cf4790
45 changed files with 340 additions and 265 deletions
|
|
@ -35,7 +35,7 @@ void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, con
|
|||
m_table = table;
|
||||
m_catalog = cat;
|
||||
if (m_table) {
|
||||
m_columns = cat->attributes()->getColumnsForRelation(table->oid);
|
||||
m_columns = cat->attributes()->getColumnsForRelation(table->oid());
|
||||
// hide system and dropped columns
|
||||
auto column_filter_pred = table->hasoids ? ColumnFilterWithOidsPred : ColumnFilterWithoutOidsPred;
|
||||
auto si = std::remove_if(m_columns.begin(), m_columns.end(), column_filter_pred);
|
||||
|
|
@ -51,12 +51,12 @@ void ColumnTableModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, con
|
|||
|
||||
|
||||
if (m_table) {
|
||||
m_indexes = m_catalog->indexes()->getIndexesForTable(table->oid);
|
||||
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);
|
||||
|| (l.isprimary == r.isprimary && l.oid() < r.oid());
|
||||
});
|
||||
}
|
||||
else
|
||||
|
|
@ -109,7 +109,7 @@ QVariant ColumnTableModel::headerData(int section, Qt::Orientation orientation,
|
|||
if (section >= colCount) {
|
||||
const auto &tbl_idx = m_indexes[section - colCount];
|
||||
//auto idx_cls = m_catalog->classes()->getByKey(tbl_idx.indexrelid);
|
||||
auto idx_class_name = getClassDisplayString(*m_catalog, tbl_idx.indexrelid);
|
||||
auto idx_class_name = tbl_idx.objectName(); // getClassDisplayString(*m_catalog, tbl_idx.indexrelid);
|
||||
QString s;
|
||||
if (tbl_idx.isprimary)
|
||||
s = tr("Primary key");
|
||||
|
|
|
|||
|
|
@ -20,7 +20,7 @@ void ConstraintModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, cons
|
|||
m_table = table;
|
||||
m_catalog = cat;
|
||||
if (table) {
|
||||
m_constraints = cat->constraints()->getConstraintsForRelation(table->oid);
|
||||
m_constraints = cat->constraints()->getConstraintsForRelation(table->oid());
|
||||
std::sort(m_constraints.begin(), m_constraints.end(),
|
||||
[] (auto &l, auto &r) {
|
||||
return l.type < r.type ||
|
||||
|
|
|
|||
|
|
@ -38,7 +38,7 @@ void CrudModel::setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table
|
|||
{
|
||||
m_database = db;
|
||||
m_table = table;
|
||||
m_primaryKey = db->catalog()->constraints()->getPrimaryForRelation(table.oid);
|
||||
m_primaryKey = db->catalog()->constraints()->getPrimaryForRelation(table.oid());
|
||||
//cat->attributes()->getColumnsForRelation()
|
||||
callLoadData = true;
|
||||
auto dbconfig = m_database->config();
|
||||
|
|
@ -163,7 +163,7 @@ QVariant CrudModel::data(const QModelIndex &index, int role) const
|
|||
|
||||
void CrudModel::loadData()
|
||||
{
|
||||
QString table_name = genFQTableName(*m_database->catalog(), m_table);
|
||||
QString table_name = m_table->fullyQualifiedQuotedObjectName(); // genFQTableName(*m_database->catalog(), *m_table);
|
||||
std::string q = "SELECT * FROM ";
|
||||
q += std::string(table_name.toUtf8().data());
|
||||
m_dbConn.send(q, [this] (Expected<std::shared_ptr<Pgsql::Result>> res, qint64) {
|
||||
|
|
@ -295,7 +295,7 @@ std::tuple<QString, Pgsql::Params> CrudModel::createUpdateQuery(const PKeyValues
|
|||
{
|
||||
Pgsql::Params params;
|
||||
auto data = pending_row.data();
|
||||
QString table_name = genFQTableName(*m_database->catalog(), m_table);
|
||||
QString table_name = m_table->fullyQualifiedQuotedObjectName(); //genFQTableName(*m_database->catalog(), *m_table);
|
||||
QString buffer;
|
||||
QTextStream q(&buffer);
|
||||
q << "UPDATE " << table_name << " AS d\n SET ";
|
||||
|
|
@ -329,12 +329,12 @@ std::tuple<QString, Pgsql::Params> CrudModel::createInsertQuery(const PendingRow
|
|||
{
|
||||
Pgsql::Params params;
|
||||
auto data = pending_row.data();
|
||||
QString table_name = genFQTableName(*m_database->catalog(), m_table);
|
||||
QString table_name = m_table->fullyQualifiedQuotedObjectName(); // genFQTableName(*m_database->catalog(), *m_table);
|
||||
QString buffer;
|
||||
QTextStream q(&buffer);
|
||||
q << "INSERT INTO " << table_name << "(";
|
||||
|
||||
auto columns = m_database->catalog()->attributes()->getColumnsForRelation(m_table.oid);
|
||||
auto columns = m_database->catalog()->attributes()->getColumnsForRelation(m_table->oid());
|
||||
bool first = true;
|
||||
for (auto e : data) {
|
||||
int num = e.first + 1;
|
||||
|
|
@ -362,7 +362,7 @@ std::tuple<QString, Pgsql::Params> CrudModel::createInsertQuery(const PendingRow
|
|||
std::tuple<QString, Pgsql::Params> CrudModel::createDeleteStatement(const PKeyValues &pkey_values)
|
||||
{
|
||||
Pgsql::Params params;
|
||||
QString table_name = genFQTableName(*m_database->catalog(), m_table);
|
||||
QString table_name = m_table->fullyQualifiedQuotedObjectName(); // genFQTableName(*m_database->catalog(), *m_table);
|
||||
QString buffer;
|
||||
QTextStream q(&buffer);
|
||||
q << "DELETE FROM " << table_name;
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ class CrudModel: public QAbstractTableModel {
|
|||
Q_OBJECT
|
||||
public:
|
||||
explicit CrudModel(ASyncWindow *async_win);
|
||||
~CrudModel();
|
||||
~CrudModel() override;
|
||||
|
||||
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
||||
|
||||
|
|
@ -149,7 +149,7 @@ private:
|
|||
*/
|
||||
class PendingRow {
|
||||
public:
|
||||
using ValueMap = std::map<int16_t, Value>;
|
||||
using ValueMap = std::map<int, Value>;
|
||||
|
||||
explicit PendingRow(int row)
|
||||
: m_row(row)
|
||||
|
|
@ -232,7 +232,7 @@ private:
|
|||
|
||||
ASyncWindow * m_asyncWindow;
|
||||
std::shared_ptr<OpenDatabase> m_database;
|
||||
PgClass m_table;
|
||||
std::optional<PgClass> m_table;
|
||||
std::optional<PgConstraint> m_primaryKey;
|
||||
ASyncDBConnection m_dbConn;
|
||||
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
#include <QWidget>
|
||||
#include "PlgPage.h"
|
||||
#include <memory>
|
||||
#include <optional>
|
||||
|
||||
namespace Ui {
|
||||
class CrudTab;
|
||||
|
|
@ -20,7 +21,7 @@ class CrudTab : public PlgPage
|
|||
|
||||
public:
|
||||
explicit CrudTab(MainWindow *parent = 0);
|
||||
~CrudTab();
|
||||
~CrudTab() override;
|
||||
|
||||
void setConfig(std::shared_ptr<OpenDatabase> db, const PgClass &table);
|
||||
|
||||
|
|
@ -33,7 +34,7 @@ private:
|
|||
MainWindow *m_window;
|
||||
|
||||
std::shared_ptr<OpenDatabase> m_db;
|
||||
PgClass m_table;
|
||||
std::optional<PgClass> m_table;
|
||||
|
||||
CrudModel *m_crudModel = nullptr;
|
||||
std::vector<QAction*> actions;
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ QVariant DatabasesTableModel::getData(const QModelIndex &index) const
|
|||
const PgDatabase &db = m_databases->getByIdx(index.row());
|
||||
switch (index.column()) {
|
||||
case NameCol:
|
||||
v = db.name;
|
||||
v = db.objectName();
|
||||
break;
|
||||
case DbaCol:
|
||||
v = getRoleDisplayString(*m_catalog, db.dba);
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ void IndexModel::setData(std::shared_ptr<const PgDatabaseCatalog> cat, const std
|
|||
m_catalog = cat;
|
||||
m_table = table;
|
||||
if (table)
|
||||
m_indexes = cat->indexes()->getIndexesForTable(table->oid);
|
||||
m_indexes = cat->indexes()->getIndexesForTable(table->oid());
|
||||
else
|
||||
m_indexes.clear();
|
||||
}
|
||||
|
|
@ -78,7 +78,7 @@ QVariant IndexModel::getData(const QModelIndex &index) const
|
|||
break;
|
||||
|
||||
case NameCol:
|
||||
v = getIndexDisplayString(*m_catalog, dat.indexrelid);
|
||||
v = dat.objectName(); // getIndexDisplayString(*m_catalog, dat.indexrelid);
|
||||
break;
|
||||
|
||||
case AmCol:
|
||||
|
|
|
|||
|
|
@ -57,7 +57,7 @@ void MainWindow::newCrudPage(const PgClass &table)
|
|||
ct->setConfig(m_database, table);
|
||||
// ui->tabWidget->addTab(ct, table.name);
|
||||
// ui->tabWidget->setCurrentWidget(ct);
|
||||
addPage(ct, table.name);
|
||||
addPage(ct, table.objectName());
|
||||
}
|
||||
|
||||
void MainWindow::newCodeGenPage(QString query, std::shared_ptr<const Pgsql::Result> dbres)
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ namespace NamespaceItemModel_impl {
|
|||
{
|
||||
QVariant v;
|
||||
if (role == Qt::DisplayRole) {
|
||||
v = ns.name;
|
||||
v = ns.objectName();
|
||||
}
|
||||
else if (role == Qt::CheckStateRole) {
|
||||
v = getCheckState();
|
||||
|
|
@ -59,7 +59,7 @@ namespace NamespaceItemModel_impl {
|
|||
|
||||
bool operator < (const LeafNode &rhs) const
|
||||
{
|
||||
return ns.name < rhs.ns.name;
|
||||
return ns.objectName() < rhs.ns.objectName();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -78,8 +78,8 @@ QVariant ProcTableModel::getData(const QModelIndex &index) const
|
|||
{
|
||||
auto&& t = m_procs->getByIdx(index.row());
|
||||
switch (index.column()) {
|
||||
case NameCol: return t.name;
|
||||
case NamespaceCol: return t.schemaOid();
|
||||
case NameCol: return t.objectName();
|
||||
case NamespaceCol: return t.nsName();
|
||||
case OwnerCol: return t.owner;
|
||||
case LangCol: return t.lang;
|
||||
case AclCol: return t.acl;
|
||||
|
|
|
|||
|
|
@ -225,7 +225,7 @@ void TablesPage::indexesTable_modelReset()
|
|||
void TablesPage::on_tableListTable_doubleClicked(const QModelIndex &index)
|
||||
{
|
||||
PgClass table = m_tablesModel->getTable(index.row());
|
||||
if (table.oid != InvalidOid) {
|
||||
if (table.oid() != InvalidOid) {
|
||||
m_window->newCrudPage(table);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -23,12 +23,12 @@ void TablesTableModel::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
|||
// How many?
|
||||
int n = 0;
|
||||
for (const auto &e : *classes)
|
||||
if (e.kind == RelKind::Table && !e.system_namespace) ++n;
|
||||
if (e.kind == RelKind::Table && !e.ns().isSystemCatalog()) ++n;
|
||||
|
||||
m_tables.clear();
|
||||
m_tables.reserve(n); // reserve space
|
||||
for (const auto &e : *classes) {
|
||||
if (e.kind == RelKind::Table && !e.system_namespace) {
|
||||
if (e.kind == RelKind::Table && !e.ns().isSystemCatalog()) {
|
||||
m_tables.push_back(e);
|
||||
}
|
||||
}
|
||||
|
|
@ -48,14 +48,14 @@ namespace {
|
|||
|
||||
inline bool compareByName(PgClass l, PgClass r)
|
||||
{
|
||||
return l.name < r.name
|
||||
|| (l.name == r.name && l.relnamespace_name < r.relnamespace_name);
|
||||
return l.objectName() < r.objectName()
|
||||
|| (l.objectName() == r.objectName() && l.nsName() < r.nsName());
|
||||
}
|
||||
|
||||
inline bool compareBySchema(PgClass l, PgClass r)
|
||||
{
|
||||
return l.relnamespace_name < r.relnamespace_name
|
||||
|| (l.relnamespace_name == r.relnamespace_name && l.name < r.name);
|
||||
return l.nsName() < r.nsName()
|
||||
|| (l.nsName() == r.nsName() && l.objectName() < r.objectName());
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -138,9 +138,9 @@ QVariant TablesTableModel::getData(const QModelIndex &index) const
|
|||
{
|
||||
const auto &t = m_tables[index.row()];
|
||||
switch (index.column()) {
|
||||
case NameCol: return t.name; //formatTableName(t);
|
||||
case NamespaceCol: return getNamespaceDisplayString(*m_catalog, t.relnamespace);
|
||||
case OwnerCol: return getRoleDisplayString(*m_catalog, t.owner);
|
||||
case NameCol: return t.objectName();
|
||||
case NamespaceCol: return t.nsName(); //getNamespaceDisplayString(*m_catalog, t.relnamespace);
|
||||
case OwnerCol: return t.ownerName();
|
||||
case TablespaceCol: return getTablespaceDisplayString(*m_catalog, t.tablespace);
|
||||
case OptionsCol: break;
|
||||
case AclCol: return t.acl;
|
||||
|
|
@ -156,15 +156,15 @@ PgClass TablesTableModel::getTable(int row) const
|
|||
|
||||
Oid TablesTableModel::getTableOid(int row) const
|
||||
{
|
||||
return m_tables[row].oid;
|
||||
return m_tables[row].oid();
|
||||
}
|
||||
|
||||
QString TablesTableModel::formatTableName(const PgClass &cls) const
|
||||
{
|
||||
const char * format = "%2 (%1)";
|
||||
QString ns_name = getNamespaceDisplayString(*m_catalog, cls.relnamespace);
|
||||
return QString(format).arg(ns_name).arg(cls.name);
|
||||
}
|
||||
//QString TablesTableModel::formatTableName(const PgClass &cls) const
|
||||
//{
|
||||
// const char * format = "%2 (%1)";
|
||||
// QString ns_name = getNamespaceDisplayString(*m_catalog, cls.relnamespace);
|
||||
// return QString(format).arg(ns_name).arg(cls.objectName());
|
||||
//}
|
||||
|
||||
QVariant TablesTableModel::data(const QModelIndex &index, int role) const
|
||||
{
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@ private:
|
|||
|
||||
Oid getType(int column) const;
|
||||
QVariant getData(const QModelIndex &index) const;
|
||||
QString formatTableName(const PgClass &cls) const;
|
||||
// QString formatTableName(const PgClass &cls) const;
|
||||
void doSort(int so);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -47,7 +47,7 @@ void TriggerPage::setCatalog(std::shared_ptr<const PgDatabaseCatalog> cat)
|
|||
|
||||
void TriggerPage::setFilter(const std::optional<PgClass> &cls)
|
||||
{
|
||||
m_sortFilterProxy->setOidFilterTable(cls ? cls->oid : InvalidOid, FirstHiddenValue);
|
||||
m_sortFilterProxy->setOidFilterTable(cls ? cls->oid() : InvalidOid, FirstHiddenValue);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -85,7 +85,7 @@ QVariant TriggerTableModel::getData(const QModelIndex &index) const
|
|||
{
|
||||
auto&& t = m_triggers->getByIdx(index.row());
|
||||
switch (index.column()) {
|
||||
case NameCol: return t.name;
|
||||
case NameCol: return t.objectName();
|
||||
case EventsCol: return t.eventAbbr();
|
||||
case WhenCol: return t.typeFireWhen();
|
||||
case DeferrableCol: return t.deferrable;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue