SqlTransaction.cpp Example File
datamanagerusage/src/default/SqlTransaction.cpp
#include "SqlTransaction.hpp"
#include <bb/cascades/datamanager/Global>
#include <QtSql/QSqlDatabase>
#include <QDebug>
SqlTransaction::SqlTransaction(QSqlDatabase &connection)
: m_dbConnection(connection)
{
if (!m_dbConnection.transaction()) {
qDebug() << "SqlTransaction could not begin transaction for database " << m_dbConnection.databaseName();
}
}
SqlTransaction::~SqlTransaction() {
SqlTransaction::endTransaction();
}
void SqlTransaction::endTransaction() {
if (!m_dbConnection.commit()) {
qDebug() << "SqlTransaction could not commit transaction for database " << m_dbConnection.databaseName();
m_dbConnection.rollback();
}
}
QSqlError SqlTransaction::lastError() const {
return m_dbConnection.lastError();
}