Fixed Transaction class.

print
Josef Rokos 9 years ago
parent f208120799
commit 6bc7fd8762

@ -47,5 +47,4 @@ void Context::openDb(const QString &path)
Context::Context()
{
m_db = NULL;
m_inTransaction = false;
}

@ -19,13 +19,9 @@ public:
odb::database *db() { return m_db; }
private:
friend class Transaction;
Context();
QList<IPlugin*> m_plugins;
odb::database *m_db;
bool m_inTransaction;
};
#endif // CONTEXT_H

@ -1,12 +1,32 @@
#include "transaction.h"
#include "context.h"
bool Transaction::m_inTransaction = false;
Transaction::Transaction()
{
if (!Transaction::m_inTransaction)
{
m_tr = new odb::transaction(Context::instance().db()->begin());
Transaction::m_inTransaction = true;
}
}
Transaction::~Transaction()
{
if (m_tr != NULL)
{
delete m_tr;
Transaction::m_inTransaction = false;
}
}
void Transaction::commit()
{
if (m_tr != NULL)
{
m_tr->commit();
}
}

@ -1,12 +1,20 @@
#ifndef TRANSACTION_H
#define TRANSACTION_H
#include <odb/database.hxx>
#include <odb/transaction.hxx>
class Transaction
{
public:
Transaction();
~Transaction();
void commit();
private:
odb::transaction *m_tr;
static bool m_inTransaction;
};
#endif // TRANSACTION_H

Loading…
Cancel
Save