2017-12-09 20:21:22 +01:00
|
|
|
|
#include "OpenDatabase.h"
|
2018-12-16 10:17:59 +01:00
|
|
|
|
#include "catalog/PgDatabaseCatalog.h"
|
2017-08-26 11:45:50 +02:00
|
|
|
|
#include "Pgsql_Connection.h"
|
2019-01-29 19:41:27 +01:00
|
|
|
|
#include "Pgsql_PgException.h"
|
2018-12-16 10:17:59 +01:00
|
|
|
|
#include "model/TypeSelectionItemModel.h"
|
2019-09-16 19:24:39 +02:00
|
|
|
|
#include <QDebug>
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2019-01-29 19:41:27 +01:00
|
|
|
|
OpenDatabase::OpenDatabaseSPtr OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
2019-01-29 19:41:27 +01:00
|
|
|
|
try {
|
|
|
|
|
|
OpenDatabaseSPtr odb(new OpenDatabase(cfg));
|
|
|
|
|
|
odb->Init();
|
|
|
|
|
|
return odb;
|
|
|
|
|
|
}
|
2023-02-06 20:03:57 +01:00
|
|
|
|
catch (const std::exception &ex) {
|
2019-01-29 19:41:27 +01:00
|
|
|
|
throw OpenDatabaseException(ex.what());
|
|
|
|
|
|
}
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2017-12-25 10:31:58 +01:00
|
|
|
|
OpenDatabase::OpenDatabase(const ConnectionConfig& cfg)
|
|
|
|
|
|
: m_config(cfg)
|
2018-11-25 09:05:01 +01:00
|
|
|
|
, m_catalog(std::make_shared<PgDatabaseCatalog>())
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2018-12-16 15:38:32 +01:00
|
|
|
|
OpenDatabase::~OpenDatabase() = default;
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
2018-12-23 08:43:43 +01:00
|
|
|
|
void OpenDatabase::Init()
|
2017-02-01 18:01:02 +01:00
|
|
|
|
{
|
2019-10-06 13:52:45 +02:00
|
|
|
|
refresh();
|
2017-02-01 18:01:02 +01:00
|
|
|
|
}
|
2017-02-04 11:55:49 +01:00
|
|
|
|
|
2018-11-25 09:05:01 +01:00
|
|
|
|
std::shared_ptr<PgDatabaseCatalog> OpenDatabase::catalog()
|
2017-02-04 11:55:49 +01:00
|
|
|
|
{
|
2018-11-25 09:05:01 +01:00
|
|
|
|
return m_catalog;
|
2017-02-04 11:55:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2017-02-07 21:39:45 +01:00
|
|
|
|
TypeSelectionItemModel* OpenDatabase::typeSelectionModel()
|
2017-02-04 11:55:49 +01:00
|
|
|
|
{
|
|
|
|
|
|
if (m_typeSelectionModel == nullptr) {
|
|
|
|
|
|
m_typeSelectionModel = new TypeSelectionItemModel(nullptr);
|
2018-11-25 09:05:01 +01:00
|
|
|
|
m_typeSelectionModel->setTypeList(m_catalog->types());
|
2017-02-04 11:55:49 +01:00
|
|
|
|
}
|
|
|
|
|
|
return m_typeSelectionModel;
|
|
|
|
|
|
}
|
2019-10-06 13:52:45 +02:00
|
|
|
|
|
|
|
|
|
|
void OpenDatabase::refresh()
|
|
|
|
|
|
{
|
|
|
|
|
|
Pgsql::Connection conn;
|
2019-11-03 07:58:48 +01:00
|
|
|
|
auto connstr = m_config.connectionString();
|
|
|
|
|
|
conn.connect(connstr);
|
|
|
|
|
|
m_catalog->loadAll(conn, nullptr);
|
2019-10-06 13:52:45 +02:00
|
|
|
|
}
|