Created Pgsql::Transaction class for handling of transactions. It auto rollsback if no commit has been done.

Also moved some code out of the connection files to their own files.
This commit is contained in:
eelke 2018-12-09 20:24:11 +01:00
parent 255b2ec970
commit e32c82ac6f
12 changed files with 394 additions and 130 deletions

View file

@ -3,7 +3,6 @@
#include <functional>
#include <string>
#include <libpq-fe.h>
#include <cassert>
#include <QString>
#include <vector>
@ -12,6 +11,7 @@
#include <fmt/format.h>
#include "Pgsql_Canceller.h"
#include "Pgsql_Result.h"
namespace Pgsql {
@ -28,23 +28,6 @@ namespace Pgsql {
class Result;
class Params;
/** \brief Wrapper for a cancel object from libpq.
*/
class Canceller {
public:
Canceller() = default;
Canceller(PGcancel *c);
Canceller(const Canceller&) = delete;
Canceller& operator=(const Canceller&) = delete;
Canceller(Canceller&& rhs);
Canceller& operator=(Canceller&& rhs);
~Canceller();
bool cancel(std::string *error);
private:
PGcancel *m_cancel = nullptr;
};
/** \brief Class for connecting to the database.
*
* The class isolates the programmer from the worst C style parts
@ -87,6 +70,7 @@ namespace Pgsql {
int socket();
void close();
Canceller getCancel();
std::string getErrorMessage() const;