2017-08-26 11:44:40 +02:00
|
|
|
#include "OpenDatabase.h"
|
|
|
|
|
#include "PgDatabaseCatalogue.h"
|
2017-08-26 11:45:50 +02:00
|
|
|
#include "Pgsql_Connection.h"
|
2017-08-23 13:27:23 +02:00
|
|
|
#include "TypeSelectionItemModel.h"
|
2017-02-01 18:01:02 +01:00
|
|
|
|
|
|
|
|
Expected<OpenDatabase*> OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
|
|
|
|
|
{
|
|
|
|
|
OpenDatabase *odb = new OpenDatabase(cfg, nullptr);
|
|
|
|
|
if (odb->Init()) {
|
|
|
|
|
|
2017-02-02 07:22:54 +01:00
|
|
|
|
2017-02-01 18:01:02 +01:00
|
|
|
}
|
2017-02-02 07:22:54 +01:00
|
|
|
return odb;
|
2017-02-01 18:01:02 +01:00
|
|
|
//return Expected<ConnectionConfig>::fromException(std::out_of_range("Invalid row"));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenDatabase::OpenDatabase(const ConnectionConfig& cfg, QObject *parent)
|
|
|
|
|
: QObject(parent)
|
|
|
|
|
, m_config(cfg)
|
2017-08-26 11:44:40 +02:00
|
|
|
, m_catalogue(new PgDatabaseCatalogue)
|
2017-02-01 18:01:02 +01:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
OpenDatabase::~OpenDatabase()
|
|
|
|
|
{
|
|
|
|
|
delete m_catalogue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool OpenDatabase::Init()
|
|
|
|
|
{
|
2017-02-04 11:55:49 +01:00
|
|
|
Pgsql::Connection conn;
|
|
|
|
|
auto kw = m_config.getKeywords();
|
|
|
|
|
auto vals = m_config.getValues();
|
|
|
|
|
if (conn.connect(kw, vals, 0)) {
|
|
|
|
|
m_catalogue->loadAll(conn);
|
|
|
|
|
}
|
2017-02-01 18:01:02 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
2017-02-04 11:55:49 +01:00
|
|
|
|
2017-08-26 11:44:40 +02:00
|
|
|
PgDatabaseCatalogue* OpenDatabase::catalogue()
|
2017-02-04 11:55:49 +01:00
|
|
|
{
|
|
|
|
|
return m_catalogue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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);
|
2017-02-07 21:39:45 +01:00
|
|
|
m_typeSelectionModel->setTypeList(m_catalogue->types());
|
2017-02-04 11:55:49 +01:00
|
|
|
}
|
|
|
|
|
return m_typeSelectionModel;
|
|
|
|
|
}
|