Misc minor changes.

This commit is contained in:
eelke 2017-12-28 09:20:42 +01:00
parent 36e5526f5f
commit a06c752029
3 changed files with 47 additions and 12 deletions

View file

@ -278,7 +278,6 @@ void MainWindow::on_actionCopy_triggered()
method.invoke(w, Qt::AutoConnection); method.invoke(w, Qt::AutoConnection);
} }
} }
//this->ui->
} }

View file

@ -149,7 +149,7 @@ void PgDatabaseCatalog::loadInfo(Pgsql::Connection &conn)
void load(Pgsql::Connection &conn, IPgContainter &pg_cont) void load(Pgsql::Connection &conn, IPgContainter &pg_cont)
{ {
QThread::msleep(400); //QThread::msleep(400);
std::string q = pg_cont.getLoadQuery(); std::string q = pg_cont.getLoadQuery();
Pgsql::Result result = conn.query(q.c_str()); Pgsql::Result result = conn.query(q.c_str());
if (result && result.resultStatus() == PGRES_TUPLES_OK) if (result && result.resultStatus() == PGRES_TUPLES_OK)

View file

@ -1,23 +1,52 @@
#ifndef PGEXCEPTION_H #ifndef PGEXCEPTION_H
#define PGEXCEPTION_H #define PGEXCEPTION_H
#include <cassert>
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
namespace Pgsql { namespace Pgsql {
class PgException { class ResultCode {
public:
explicit ResultCode(std::string result_code)
: m_resultCode(std::move(result_code))
{
assert(m_resultCode.length() == 5);
}
std::string getClass() const
{
return m_resultCode.substr(1,2);
}
/** Helper to easily check the class of the error
*
*/
bool isClass(const std::string_view cls)
{
return m_resultCode.compare(1, 2, cls);
}
const std::string& getSpecific() const
{
return m_resultCode;
}
private:
std::string m_resultCode;
};
class PgException: public std::runtime_error {
public: public:
PgException(const char *msg) PgException(const char *msg)
: message(msg) : std::runtime_error(msg)
{} {}
PgException(std::string msg) PgException(std::string msg)
: message(std::move(msg)) : std::runtime_error(msg)
{} {}
private: private:
std::string message;
}; };
@ -25,15 +54,22 @@ namespace Pgsql {
public: public:
PgResultError(std::string msg, std::string result_code) PgResultError(std::string msg, std::string result_code)
: PgException(std::move(msg)) : PgException(std::move(msg))
, m_resultCode(result_code)
{} {}
ResultCode getResultCode() const { return m_resultCode; }
private:
ResultCode m_resultCode;
}; };
class PgConnectionError: public PgResultError, std::runtime_error { class PgConnectionError: public PgResultError {
public:
PgConnectionError(const std::string &msg, std::string result_code) PgConnectionError(const std::string &msg, std::string result_code)
: PgResultError(msg, std::move(result_code)) : PgResultError(msg, std::move(result_code))
, std::runtime_error(msg)
{} {}
private:
}; };