Changeset c19618d in confclerk_git


Ignore:
Timestamp:
09/27/17 21:36:47 (5 years ago)
Author:
Philipp Spitzer <philipp@…>
Branches:
master
Children:
a2f0d1e
Parents:
0c71a07
Message:

Implement transaction RAII.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/sql/sqlengine.h

    r0c71a07 rc19618d  
    8383};
    8484
     85
     86class TransactionRaii {
     87    SqlEngine& sqlEngine;
     88    bool committed = false;
     89public:
     90    TransactionRaii(SqlEngine& sqlEngine): sqlEngine(sqlEngine) {
     91        sqlEngine.beginTransaction();
     92    }
     93
     94    void commit() {
     95        sqlEngine.commitTransaction();
     96        committed = true;
     97    }
     98
     99    ~TransactionRaii() {
     100        if (!committed) sqlEngine.rollbackTransaction();
     101    }
     102};
     103
    85104#endif /* SQLENGINE_H */
    86105
Note: See TracChangeset for help on using the changeset viewer.