Slightly more complex then you may expect because the tablespace specified by the tables tends to be oid 0 which means the default tablespace is used. However this does not mean pg_default, it means the tablespace as defined as standard in the database definition. So we need to know what the current dbname is retrieve it's details from the catalog and retrieve that tablespace to know what to show for an oid of 0.
90 lines
2.8 KiB
C++
90 lines
2.8 KiB
C++
#ifndef PGSQLDATABASECATALOGUE_H
|
|
#define PGSQLDATABASECATALOGUE_H
|
|
|
|
#include <libpq-fe.h>
|
|
#include <QString>
|
|
#include <functional>
|
|
#include <memory>
|
|
#include <vector>
|
|
|
|
namespace Pgsql {
|
|
|
|
class Connection;
|
|
|
|
}
|
|
|
|
class PgAttributeContainer;
|
|
class PgAuthIdContainer;
|
|
class PgClassContainer;
|
|
class PgConstraintContainer;
|
|
class PgDatabaseContainer;
|
|
class PgIndexContainer;
|
|
class PgNamespaceContainer;
|
|
class PgAmContainer;
|
|
class PgTablespaceContainer;
|
|
class PgTypeContainer;
|
|
|
|
class PgDatabaseCatalog: public std::enable_shared_from_this<PgDatabaseCatalog> {
|
|
public:
|
|
PgDatabaseCatalog();
|
|
PgDatabaseCatalog(const PgDatabaseCatalog&) = delete;
|
|
PgDatabaseCatalog& operator = (const PgDatabaseCatalog&) = delete;
|
|
~PgDatabaseCatalog();
|
|
|
|
void loadAll(Pgsql::Connection &conn,
|
|
std::function<bool(int, int)> progress_callback);
|
|
|
|
void loadInfo(Pgsql::Connection &conn);
|
|
|
|
const QString& serverVersionString() const;
|
|
int serverVersion() const;
|
|
const QString& getDBName() const { return m_dbName; }
|
|
|
|
std::shared_ptr<const PgAttributeContainer> attributes() const;
|
|
std::shared_ptr<const PgAuthIdContainer> authIds() const;
|
|
std::shared_ptr<const PgClassContainer> classes() const;
|
|
std::shared_ptr<const PgConstraintContainer> constraints() const;
|
|
std::shared_ptr<const PgDatabaseContainer> databases() const;
|
|
std::shared_ptr<const PgIndexContainer> indexes() const;
|
|
std::shared_ptr<const PgAmContainer> ams() const;
|
|
std::shared_ptr<const PgNamespaceContainer> namespaces() const;
|
|
std::shared_ptr<const PgTablespaceContainer> tablespaces() const;
|
|
std::shared_ptr<const PgTypeContainer> types() const;
|
|
|
|
private:
|
|
QString m_serverVersionString;
|
|
int m_serverVersion;
|
|
QString m_dbName;
|
|
|
|
std::shared_ptr<PgAttributeContainer> m_attributes;
|
|
std::shared_ptr<PgAuthIdContainer> m_authIds;
|
|
std::shared_ptr<PgClassContainer> m_classes;
|
|
std::shared_ptr<PgConstraintContainer> m_constraints;
|
|
std::shared_ptr<PgDatabaseContainer> m_databases;
|
|
std::shared_ptr<PgIndexContainer> m_indexes;
|
|
std::shared_ptr<PgAmContainer> m_ams;
|
|
std::shared_ptr<PgNamespaceContainer> m_namespaces;
|
|
std::shared_ptr<PgTablespaceContainer> m_tablespaces;
|
|
std::shared_ptr<PgTypeContainer> m_types;
|
|
|
|
template <typename T>
|
|
void load2(std::shared_ptr<T> &ptr, Pgsql::Connection &conn)
|
|
{
|
|
if (!ptr)
|
|
ptr = std::make_shared<T>(shared_from_this());
|
|
|
|
load(conn, *ptr);
|
|
}
|
|
|
|
};
|
|
|
|
QString getRoleNameFromOid(const PgDatabaseCatalog &cat, Oid oid);
|
|
QString getRoleDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
|
QString getNamespaceDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
|
QString getTablespaceDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
|
QString getTypeDisplayString(const PgDatabaseCatalog &cat, Oid oid, int32_t typmod = -1);
|
|
QString getIndexDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
|
QString getClassDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
|
|
|
|
|
#endif // PGSQLDATABASECATALOGUE_H
|