Loading of index definitions
This commit is contained in:
parent
db75d9ed50
commit
aef9b914b1
7 changed files with 95 additions and 27 deletions
|
|
@ -4,6 +4,7 @@
|
|||
#include "PgAuthIdContainer.h"
|
||||
#include "PgClassContainer.h"
|
||||
#include "PgDatabaseContainer.h"
|
||||
#include "PgIndexContainer.h"
|
||||
#include "PgNamespaceContainer.h"
|
||||
#include "PgTypeContainer.h"
|
||||
#include "Pgsql_Connection.h"
|
||||
|
|
@ -80,11 +81,11 @@ PgDatabaseCatalog::~PgDatabaseCatalog()
|
|||
void PgDatabaseCatalog::loadAll(Pgsql::Connection &conn)
|
||||
{
|
||||
loadInfo(conn);
|
||||
|
||||
loadAttributes(conn);
|
||||
loadAuthIds(conn);
|
||||
loadClasses(conn);
|
||||
loadDatabases(conn);
|
||||
loadIndexes(conn);
|
||||
loadNamespaces(conn);
|
||||
loadTypes(conn);
|
||||
}
|
||||
|
|
@ -145,6 +146,14 @@ void PgDatabaseCatalog::loadDatabases(Pgsql::Connection &conn)
|
|||
load(conn, *m_databases);
|
||||
}
|
||||
|
||||
void PgDatabaseCatalog::loadIndexes(Pgsql::Connection &conn)
|
||||
{
|
||||
if (!m_indexes)
|
||||
m_indexes = std::make_shared<PgIndexContainer>(shared_from_this());
|
||||
|
||||
load(conn, *m_indexes);
|
||||
}
|
||||
|
||||
void PgDatabaseCatalog::loadNamespaces(Pgsql::Connection &conn)
|
||||
{
|
||||
if (!m_namespaces)
|
||||
|
|
@ -192,6 +201,11 @@ std::shared_ptr<const PgDatabaseContainer> PgDatabaseCatalog::databases() const
|
|||
return m_databases;
|
||||
}
|
||||
|
||||
std::shared_ptr<const PgIndexContainer> PgDatabaseCatalog::indexes() const
|
||||
{
|
||||
return m_indexes;
|
||||
}
|
||||
|
||||
std::shared_ptr<const PgNamespaceContainer> PgDatabaseCatalog::namespaces() const
|
||||
{
|
||||
return m_namespaces;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ class PgAttributeContainer;
|
|||
class PgAuthIdContainer;
|
||||
class PgClassContainer;
|
||||
class PgDatabaseContainer;
|
||||
class PgIndexContainer;
|
||||
class PgNamespaceContainer;
|
||||
class PgTypeContainer;
|
||||
|
||||
|
|
@ -29,12 +30,13 @@ public:
|
|||
|
||||
|
||||
void loadAll(Pgsql::Connection &conn);
|
||||
void loadInfo(Pgsql::Connection &conn);
|
||||
|
||||
void loadAttributes(Pgsql::Connection &conn);
|
||||
void loadAuthIds(Pgsql::Connection &conn);
|
||||
void loadClasses(Pgsql::Connection &conn);
|
||||
void loadDatabases(Pgsql::Connection &conn);
|
||||
void loadInfo(Pgsql::Connection &conn);
|
||||
void loadIndexes(Pgsql::Connection &conn);
|
||||
void loadNamespaces(Pgsql::Connection &conn);
|
||||
void loadTypes(Pgsql::Connection &conn);
|
||||
|
||||
|
|
@ -45,6 +47,7 @@ public:
|
|||
std::shared_ptr<const PgAuthIdContainer> authIds() const;
|
||||
std::shared_ptr<const PgClassContainer> classes() const;
|
||||
std::shared_ptr<const PgDatabaseContainer> databases() const;
|
||||
std::shared_ptr<const PgIndexContainer> indexes() const;
|
||||
std::shared_ptr<const PgNamespaceContainer> namespaces() const;
|
||||
std::shared_ptr<const PgTypeContainer> types() const;
|
||||
private:
|
||||
|
|
@ -55,6 +58,7 @@ private:
|
|||
std::shared_ptr<PgAuthIdContainer> m_authIds;
|
||||
std::shared_ptr<PgClassContainer> m_classes;
|
||||
std::shared_ptr<PgDatabaseContainer> m_databases;
|
||||
std::shared_ptr<PgIndexContainer> m_indexes;
|
||||
std::shared_ptr<PgNamespaceContainer> m_namespaces;
|
||||
std::shared_ptr<PgTypeContainer> m_types;
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
#include "PgIndex.h"
|
||||
#include "PgIndex.h"
|
||||
|
||||
PgIndex::PgIndex()
|
||||
{
|
||||
|
||||
}
|
||||
PgIndex::PgIndex() = default;
|
||||
|
|
|
|||
|
|
@ -8,27 +8,32 @@
|
|||
class PgIndex {
|
||||
public:
|
||||
|
||||
Oid indexrelid;
|
||||
Oid indrelid;
|
||||
int16_t indnatts;
|
||||
bool indisunique;
|
||||
bool indisprimary;
|
||||
bool indisexclusion;
|
||||
bool indimmediate;
|
||||
bool indisclustered;
|
||||
bool indisvalid;
|
||||
bool indcheckxmin;
|
||||
bool indisready;
|
||||
bool indislive;
|
||||
bool indisreplident;
|
||||
std::vector<int16_t> indkey;
|
||||
std::vector<Oid> indcollation;
|
||||
Oid indexrelid = InvalidOid;
|
||||
Oid relid = InvalidOid;
|
||||
int16_t natts = 0;
|
||||
bool isunique = false;
|
||||
bool isprimary = false;
|
||||
bool isexclusion = false;
|
||||
bool immediate = false;
|
||||
bool isclustered = false;
|
||||
bool isvalid = false;
|
||||
bool checkxmin = false;
|
||||
bool isready = false;
|
||||
bool islive = false;
|
||||
bool isreplident = false;
|
||||
std::vector<int16_t> key;
|
||||
std::vector<Oid> collation;
|
||||
std::vector<Oid> indclass;
|
||||
std::vector<int16_t> indoption;
|
||||
QString indexprs;
|
||||
QString indpred;
|
||||
std::vector<int16_t> option;
|
||||
QString exprs;
|
||||
QString pred;
|
||||
|
||||
PgIndex();
|
||||
|
||||
bool operator==(Oid _oid) const { return indexrelid == _oid; }
|
||||
//bool operator==(const QString &n) const { return name == n; }
|
||||
bool operator<(Oid _oid) const { return indexrelid < _oid; }
|
||||
bool operator<(const PgIndex &rhs) const { return indexrelid < rhs.indexrelid; }
|
||||
};
|
||||
|
||||
#endif // PGINDEX_H
|
||||
|
|
|
|||
28
pglab/PgIndexContainer.cpp
Normal file
28
pglab/PgIndexContainer.cpp
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "PgIndexContainer.h"
|
||||
#include "Pgsql_Col.h"
|
||||
#include <iterator>
|
||||
|
||||
std::string PgIndexContainer::getLoadQuery() const
|
||||
{
|
||||
return R"__(
|
||||
SELECT indexrelid, indrelid, indnatts, indisunique, indisprimary,
|
||||
indisexclusion, indimmediate, indisclustered, indisvalid,
|
||||
indcheckxmin, indisready, indislive, indisreplident, indkey,
|
||||
indcollation, indclass, indoption, indexprs, indpred
|
||||
FROM pg_index)__";
|
||||
}
|
||||
|
||||
PgIndex PgIndexContainer::loadElem(const Pgsql::Row &row)
|
||||
{
|
||||
Pgsql::Col col(row);
|
||||
PgIndex v;
|
||||
col >> v.indexrelid >> v.relid >> v.natts >> v.isunique
|
||||
>> v.isprimary >> v.isexclusion >> v.immediate >> v.isclustered
|
||||
>> v.isvalid >> v.checkxmin >> v.isready >> v.islive >> v.isreplident;
|
||||
col.getAsVector<int16_t>(std::back_inserter(v.key));
|
||||
col.getAsVector<Oid>(std::back_inserter(v.collation));
|
||||
col.getAsVector<Oid>(std::back_inserter(v.indclass));
|
||||
col.getAsVector<int16_t>(std::back_inserter(v.option));
|
||||
col >> v.exprs >> v.pred;
|
||||
return v;
|
||||
}
|
||||
18
pglab/PgIndexContainer.h
Normal file
18
pglab/PgIndexContainer.h
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef PGINDEXCONTAINER_H
|
||||
#define PGINDEXCONTAINER_H
|
||||
|
||||
#include "PgContainer.h"
|
||||
#include "PgIndex.h"
|
||||
#include "Pgsql_declare.h"
|
||||
#include <vector>
|
||||
|
||||
class PgIndexContainer : public PgContainer<PgIndex> {
|
||||
public:
|
||||
using PgContainer<PgIndex>::PgContainer;
|
||||
|
||||
virtual std::string getLoadQuery() const override;
|
||||
protected:
|
||||
virtual PgIndex loadElem(const Pgsql::Row &row) override;
|
||||
};
|
||||
|
||||
#endif // PGINDEXCONTAINER_H
|
||||
|
|
@ -79,7 +79,8 @@ SOURCES += main.cpp\
|
|||
PgAttribute.cpp \
|
||||
PgContainer.cpp \
|
||||
PgAttributeContainer.cpp \
|
||||
PgIndex.cpp
|
||||
PgIndex.cpp \
|
||||
PgIndexContainer.cpp
|
||||
|
||||
HEADERS += \
|
||||
QueryResultModel.h \
|
||||
|
|
@ -130,7 +131,8 @@ HEADERS += \
|
|||
ColumnTableModel.h \
|
||||
PgAttribute.h \
|
||||
PgAttributeContainer.h \
|
||||
PgIndex.h
|
||||
PgIndex.h \
|
||||
PgIndexContainer.h
|
||||
|
||||
FORMS += mainwindow.ui \
|
||||
DatabaseWindow.ui \
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue