class AutoTransaction{public: AutoTransaction(QSqlDatabase db) : m_success(true), m_db(db) { m_db.transaction(); } ~AutoTransaction() { if (m_success) m_db.commit(); else m_db.rollback(); } void setSuccess(bool success) { m_success = success; }private: bool m_success; QSqlDatabase m_db;};#define EXEC(db, method) \ AutoTransaction atr(db); \ try { \ method; \ } catch(...) { \ atr.setSuccess(false); \ throw; \ }
class AutoTransaction{public: AutoTransaction(QSqlDatabase db) : m_success(false), m_db(db) { m_db.transaction(); } ~AutoTransaction() { if (m_success) m_db.commit(); else m_db.rollback(); } void dismiss() { m_success = true; }private: bool m_success; QSqlDatabase m_db;};#define EXEC(db, method) \ AutoTransaction atr(db); \ method; \ atr.dismiss();
#define EXEC(db, method) \{ \ AutoTransaction atr(db); \ method; \ atr.dismiss();}
AutoTransaction atr(db); \ method; \ atr.dismiss();