This repository has been archived on 2021-11-25. You can view files and clone it, but cannot push or open issues or pull requests.
DBHomework/MySQLTransaction.h

27 lines
854 B
C
Raw Normal View History

2017-11-20 13:46:28 +08:00
#include "MySQLWrapper.h"
class Transaction
{
public:
/// Start Transaction on construct.
Transaction(MySQLConn& MySQLConnection);
/// Rollback transaction on destruct. If commit() or rollback() is called, this function will not execute any sql.
~Transaction();
/// NOTE: A Transaction can only call commit() or rollback() once, until it calls start commit again.
/// Commit transaction. Equals to SQL: COMMIT
/// ReturnValue: -1 SQL Error. -2 Operated >=0 Affected Rows
int commit();
/// Rollback transaction. Equals to SQL: ROLLBACK
/// ReturnValue: -1 SQL Error. -2 Operated >=0 Affected Rows
int rollback();
/// Check if a Transaction object is ready. If it is ready, then a transaction has started.
bool isReady() const;
private:
MySQLConn& conn;
bool _isReady;
bool _operated;
};