54 lines
1.3 KiB
C++
54 lines
1.3 KiB
C++
#include "OpenDatabase.h"
|
|
#include "PgDatabaseCatalog.h"
|
|
#include "Pgsql_Connection.h"
|
|
#include "TypeSelectionItemModel.h"
|
|
|
|
Expected<OpenDatabase::OpenDatabaseSPtr> OpenDatabase::createOpenDatabase(const ConnectionConfig &cfg)
|
|
{
|
|
OpenDatabaseSPtr odb(new OpenDatabase(cfg));
|
|
if (odb->Init()) {
|
|
|
|
return odb;
|
|
|
|
}
|
|
//return Expected<ConnectionConfig>::fromException(std::out_of_range("Invalid row"));
|
|
return Expected<OpenDatabaseSPtr>::fromException(
|
|
std::runtime_error("Failed to get database information"));
|
|
}
|
|
|
|
OpenDatabase::OpenDatabase(const ConnectionConfig& cfg)
|
|
: m_config(cfg)
|
|
, m_catalogue(std::make_shared<PgDatabaseCatalog>())
|
|
{
|
|
}
|
|
|
|
OpenDatabase::~OpenDatabase()
|
|
{
|
|
}
|
|
|
|
bool OpenDatabase::Init()
|
|
{
|
|
Pgsql::Connection conn;
|
|
auto kw = m_config.getKeywords();
|
|
auto vals = m_config.getValues();
|
|
if (conn.connect(kw, vals, 0)) {
|
|
m_catalogue->loadAll(conn, nullptr);
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
std::shared_ptr<PgDatabaseCatalog> OpenDatabase::catalogue()
|
|
{
|
|
return m_catalogue;
|
|
}
|
|
|
|
|
|
TypeSelectionItemModel* OpenDatabase::typeSelectionModel()
|
|
{
|
|
if (m_typeSelectionModel == nullptr) {
|
|
m_typeSelectionModel = new TypeSelectionItemModel(nullptr);
|
|
m_typeSelectionModel->setTypeList(m_catalogue->types());
|
|
}
|
|
return m_typeSelectionModel;
|
|
}
|