2017-01-25 06:52:02 +01:00
|
|
|
|
#ifndef PGSQLDATABASECATALOGUE_H
|
|
|
|
|
|
#define PGSQLDATABASECATALOGUE_H
|
|
|
|
|
|
|
2017-08-23 13:27:23 +02:00
|
|
|
|
#include <libpq-fe.h>
|
2018-10-07 19:40:06 +02:00
|
|
|
|
#include <QObject>
|
2017-02-18 12:05:48 +01:00
|
|
|
|
#include <QString>
|
2017-12-28 07:29:07 +01:00
|
|
|
|
#include <functional>
|
2018-10-07 19:40:06 +02:00
|
|
|
|
#include <bitset>
|
2017-12-09 20:21:22 +01:00
|
|
|
|
#include <memory>
|
2017-01-25 06:52:02 +01:00
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
2017-02-01 20:00:25 +01:00
|
|
|
|
namespace Pgsql {
|
|
|
|
|
|
|
|
|
|
|
|
class Connection;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-12 20:13:53 +01:00
|
|
|
|
class PgAttributeContainer;
|
2017-02-18 12:05:48 +01:00
|
|
|
|
class PgAuthIdContainer;
|
2017-12-10 10:35:46 +01:00
|
|
|
|
class PgClassContainer;
|
2017-12-25 10:31:58 +01:00
|
|
|
|
class PgConstraintContainer;
|
2017-12-10 10:35:46 +01:00
|
|
|
|
class PgDatabaseContainer;
|
2017-12-17 11:28:20 +01:00
|
|
|
|
class PgIndexContainer;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
class PgNamespaceContainer;
|
2018-08-25 18:11:12 +02:00
|
|
|
|
class PgAmContainer;
|
2018-09-02 10:30:30 +00:00
|
|
|
|
class PgTablespaceContainer;
|
2018-10-07 19:40:06 +02:00
|
|
|
|
class PgTriggerContainer;
|
2017-12-10 10:35:46 +01:00
|
|
|
|
class PgTypeContainer;
|
2018-11-17 19:38:07 +01:00
|
|
|
|
class PgProcContainer;
|
2018-11-29 20:21:36 +01:00
|
|
|
|
class PgCollationContainer;
|
2018-12-03 21:03:49 +01:00
|
|
|
|
class PgInheritsContainer;
|
2018-12-17 21:51:14 +01:00
|
|
|
|
class PgLanguageContainer;
|
2018-12-28 08:51:02 +01:00
|
|
|
|
class PgSequenceContainer;
|
2017-01-25 06:52:02 +01:00
|
|
|
|
|
2019-10-06 13:52:45 +02:00
|
|
|
|
/// Manages all the catalog data for the database so the program
|
|
|
|
|
|
/// can efficiently retrieve information from memory.
|
|
|
|
|
|
///
|
|
|
|
|
|
/// All the containers are created once during the first load. After
|
|
|
|
|
|
/// that they are reused on reload so signals will stay connected.
|
2018-10-07 19:40:06 +02:00
|
|
|
|
class PgDatabaseCatalog: public QObject, public std::enable_shared_from_this<PgDatabaseCatalog> {
|
|
|
|
|
|
Q_OBJECT
|
2017-01-25 06:52:02 +01:00
|
|
|
|
public:
|
2017-12-10 10:35:46 +01:00
|
|
|
|
PgDatabaseCatalog();
|
|
|
|
|
|
PgDatabaseCatalog(const PgDatabaseCatalog&) = delete;
|
|
|
|
|
|
PgDatabaseCatalog& operator = (const PgDatabaseCatalog&) = delete;
|
|
|
|
|
|
~PgDatabaseCatalog();
|
2017-02-01 20:00:25 +01:00
|
|
|
|
|
2017-12-28 07:29:07 +01:00
|
|
|
|
void loadAll(Pgsql::Connection &conn,
|
|
|
|
|
|
std::function<bool(int, int)> progress_callback);
|
2017-02-01 20:00:25 +01:00
|
|
|
|
|
2017-12-17 11:28:20 +01:00
|
|
|
|
void loadInfo(Pgsql::Connection &conn);
|
2017-12-12 20:13:53 +01:00
|
|
|
|
|
2017-02-18 12:05:48 +01:00
|
|
|
|
const QString& serverVersionString() const;
|
|
|
|
|
|
int serverVersion() const;
|
2018-09-02 10:30:30 +00:00
|
|
|
|
const QString& getDBName() const { return m_dbName; }
|
2017-01-25 06:52:02 +01:00
|
|
|
|
|
2017-12-12 20:13:53 +01:00
|
|
|
|
std::shared_ptr<const PgAttributeContainer> attributes() const;
|
2017-12-09 20:21:22 +01:00
|
|
|
|
std::shared_ptr<const PgAuthIdContainer> authIds() const;
|
2017-12-10 10:35:46 +01:00
|
|
|
|
std::shared_ptr<const PgClassContainer> classes() const;
|
2017-12-25 10:31:58 +01:00
|
|
|
|
std::shared_ptr<const PgConstraintContainer> constraints() const;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
std::shared_ptr<const PgDatabaseContainer> databases() const;
|
2017-12-17 11:28:20 +01:00
|
|
|
|
std::shared_ptr<const PgIndexContainer> indexes() const;
|
2018-08-25 18:11:12 +02:00
|
|
|
|
std::shared_ptr<const PgAmContainer> ams() const;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
std::shared_ptr<const PgNamespaceContainer> namespaces() const;
|
2018-09-02 10:30:30 +00:00
|
|
|
|
std::shared_ptr<const PgTablespaceContainer> tablespaces() const;
|
2018-10-07 19:40:06 +02:00
|
|
|
|
std::shared_ptr<const PgTriggerContainer> triggers() const;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
std::shared_ptr<const PgTypeContainer> types() const;
|
2018-11-17 19:38:07 +01:00
|
|
|
|
std::shared_ptr<const PgProcContainer> procs() const;
|
2018-11-29 20:21:36 +01:00
|
|
|
|
std::shared_ptr<const PgCollationContainer> collations() const;
|
2018-12-03 21:03:49 +01:00
|
|
|
|
std::shared_ptr<const PgInheritsContainer> inherits() const;
|
2018-12-17 21:51:14 +01:00
|
|
|
|
std::shared_ptr<const PgLanguageContainer> languages() const;
|
2018-12-28 08:51:02 +01:00
|
|
|
|
std::shared_ptr<const PgSequenceContainer> sequences() const;
|
2018-09-02 10:30:30 +00:00
|
|
|
|
|
2018-10-07 19:40:06 +02:00
|
|
|
|
enum RefreshFlag {
|
|
|
|
|
|
Attributes = 1,
|
|
|
|
|
|
AuthIds = (1 << 1),
|
|
|
|
|
|
Classes = (1 << 2),
|
|
|
|
|
|
Constraints = (1 << 3),
|
|
|
|
|
|
Databases = (1 << 4),
|
|
|
|
|
|
Indexes = (1 << 5),
|
|
|
|
|
|
Ams = (1 << 6),
|
|
|
|
|
|
Namespaces = (1 << 7),
|
|
|
|
|
|
Tablespaces = (1 << 8),
|
|
|
|
|
|
Triggers = (1 << 9),
|
|
|
|
|
|
Types = (1 << 10),
|
2018-11-17 19:38:07 +01:00
|
|
|
|
Proc = (1 << 11),
|
2018-10-07 19:40:06 +02:00
|
|
|
|
All = 0xffffffff
|
|
|
|
|
|
};
|
|
|
|
|
|
using RefreshFlags = int;
|
|
|
|
|
|
|
|
|
|
|
|
signals:
|
|
|
|
|
|
void refreshed(const PgDatabaseCatalog *catalog, RefreshFlags flags);
|
2017-01-25 06:52:02 +01:00
|
|
|
|
private:
|
2017-02-18 12:05:48 +01:00
|
|
|
|
QString m_serverVersionString;
|
|
|
|
|
|
int m_serverVersion;
|
2018-09-02 10:30:30 +00:00
|
|
|
|
QString m_dbName;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
|
|
|
|
|
|
std::shared_ptr<PgAttributeContainer> m_attributes;
|
2017-12-09 20:21:22 +01:00
|
|
|
|
std::shared_ptr<PgAuthIdContainer> m_authIds;
|
2017-12-10 10:35:46 +01:00
|
|
|
|
std::shared_ptr<PgClassContainer> m_classes;
|
2017-12-25 10:31:58 +01:00
|
|
|
|
std::shared_ptr<PgConstraintContainer> m_constraints;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
std::shared_ptr<PgDatabaseContainer> m_databases;
|
2017-12-17 11:28:20 +01:00
|
|
|
|
std::shared_ptr<PgIndexContainer> m_indexes;
|
2018-08-25 18:11:12 +02:00
|
|
|
|
std::shared_ptr<PgAmContainer> m_ams;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
std::shared_ptr<PgNamespaceContainer> m_namespaces;
|
2018-09-02 10:30:30 +00:00
|
|
|
|
std::shared_ptr<PgTablespaceContainer> m_tablespaces;
|
2018-10-07 19:40:06 +02:00
|
|
|
|
std::shared_ptr<PgTriggerContainer> m_triggers;
|
2017-12-12 20:13:53 +01:00
|
|
|
|
std::shared_ptr<PgTypeContainer> m_types;
|
2018-11-17 19:38:07 +01:00
|
|
|
|
std::shared_ptr<PgProcContainer> m_procs;
|
2018-11-29 20:21:36 +01:00
|
|
|
|
std::shared_ptr<PgCollationContainer> m_collations;
|
2018-12-03 21:03:49 +01:00
|
|
|
|
std::shared_ptr<PgInheritsContainer> m_inherits;
|
2018-12-17 21:51:14 +01:00
|
|
|
|
std::shared_ptr<PgLanguageContainer> m_languages;
|
2018-12-28 08:51:02 +01:00
|
|
|
|
std::shared_ptr<PgSequenceContainer> m_sequences;
|
2017-12-25 10:31:58 +01:00
|
|
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
|
|
void load2(std::shared_ptr<T> &ptr, Pgsql::Connection &conn)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!ptr)
|
2018-11-18 19:30:45 +01:00
|
|
|
|
ptr = std::make_shared<T>(*this);
|
2017-12-25 10:31:58 +01:00
|
|
|
|
|
2018-12-28 08:51:02 +01:00
|
|
|
|
ptr->loadAll(conn);
|
2017-12-25 10:31:58 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-01-25 06:52:02 +01:00
|
|
|
|
};
|
|
|
|
|
|
|
2017-12-10 10:35:46 +01:00
|
|
|
|
QString getRoleNameFromOid(const PgDatabaseCatalog &cat, Oid oid);
|
|
|
|
|
|
QString getRoleDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
|
|
|
|
|
QString getTablespaceDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
2017-12-19 19:33:22 +01:00
|
|
|
|
QString getTypeDisplayString(const PgDatabaseCatalog &cat, Oid oid, int32_t typmod = -1);
|
2017-12-30 12:57:55 +01:00
|
|
|
|
QString getIndexDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
|
|
|
|
|
QString getClassDisplayString(const PgDatabaseCatalog &cat, Oid oid);
|
2017-12-09 10:45:13 +01:00
|
|
|
|
|
2017-02-18 12:05:48 +01:00
|
|
|
|
|
2017-01-25 06:52:02 +01:00
|
|
|
|
#endif // PGSQLDATABASECATALOGUE_H
|