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:
parent
255b2ec970
commit
e32c82ac6f
12 changed files with 394 additions and 130 deletions
53
pgsql/Pgsql_Transaction.h
Normal file
53
pgsql/Pgsql_Transaction.h
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
#ifndef PGSQL_TRANSACTION_H
|
||||
#define PGSQL_TRANSACTION_H
|
||||
|
||||
#include <QString>
|
||||
#include <string>
|
||||
#include "Pgsql_Canceller.h"
|
||||
|
||||
namespace Pgsql {
|
||||
|
||||
class Result;
|
||||
class Params;
|
||||
class Connection;
|
||||
|
||||
|
||||
class Transaction {
|
||||
public:
|
||||
static Transaction startTransaction(Connection &conn);
|
||||
~Transaction();
|
||||
void rollback();
|
||||
void commit();
|
||||
Canceller getCancel();
|
||||
std::string getErrorMessage() const;
|
||||
Result query(const char * command);
|
||||
Result query(const QString &command);
|
||||
Result queryParam(const char * command, const Params ¶ms);
|
||||
Result queryParam(const QString &command, const Params ¶ms);
|
||||
bool sendQuery(const char * query);
|
||||
bool sendQuery(const std::string &command);
|
||||
bool sendQuery(const QString &command);
|
||||
bool sendQueryParams(const char * command, const Params ¶ms);
|
||||
std::shared_ptr<Result> getResult();
|
||||
bool consumeInput();
|
||||
bool isBusy();
|
||||
std::string escapeLiteral(const std::string_view &literal);
|
||||
QString escapeLiteral(const QString &literal);
|
||||
std::string escapeIdentifier(const std::string_view &ident);
|
||||
QString escapeIdentifier(const QString &ident);
|
||||
QString getDBName() const;
|
||||
|
||||
private:
|
||||
Connection *m_conn = nullptr;
|
||||
bool m_committed = false;
|
||||
bool m_rolledback = false;
|
||||
|
||||
Transaction(Connection *conn)
|
||||
: m_conn(conn)
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif // PGSQL_TRANSACTION_H
|
||||
Loading…
Add table
Add a link
Reference in a new issue