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

43
pgsql/Pgsql_Canceller.cpp Normal file
View file

@ -0,0 +1,43 @@
#include "Pgsql_Canceller.h"
namespace Pgsql {
Canceller::Canceller(PGcancel *c)
: m_cancel(c)
{}
Canceller::Canceller(Canceller&& rhs)
: m_cancel(rhs.m_cancel)
{
rhs.m_cancel = nullptr;
}
Canceller& Canceller::operator=(Canceller&& rhs)
{
if (m_cancel) {
PQfreeCancel(m_cancel);
}
m_cancel = rhs.m_cancel;
rhs.m_cancel = nullptr;
return *this;
}
Canceller::~Canceller()
{
if (m_cancel) {
PQfreeCancel(m_cancel);
}
}
bool Canceller::cancel(std::string *error)
{
const int errbuf_size = 256;
char errbuf[errbuf_size];
bool res = PQcancel(m_cancel, errbuf, errbuf_size);
if (!res && error) {
*error = errbuf;
}
return res;
}
}