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

@ -154,8 +154,8 @@ void MainWindow::on_actionAbout_triggered()
QMessageBox::about(this, "pgLab 0.1", tr( QMessageBox::about(this, "pgLab 0.1", tr(
"Copyrights 2016-2017, Eelke Klein, All Rights Reserved.\n" "Copyrights 2016-2017, Eelke Klein, All Rights Reserved.\n"
"\n" "\n"
"The program is provided AS IS with NO WARRANTY OF ANY KIND," "The program is provided AS IS with NO WARRANTY OF ANY KIND, "
" INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS " "INCLUDING THE WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS "
"FOR A PARTICULAR PURPOSE.\n" "FOR A PARTICULAR PURPOSE.\n"
"\n" "\n"
"This program is dynamically linked with Qt 5.9 Copyright (C) 2017 " "This program is dynamically linked with Qt 5.9 Copyright (C) 2017 "
@ -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,14 +54,21 @@ 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:
}; };