|
- #pragma once
-
- #include "transaction.h"
-
- namespace cppmariadb
- {
-
- /* transaction */
-
- transaction::transaction(connection& connection) :
- _connection (connection),
- _closed (false)
- { begin(); }
-
- transaction::~transaction()
- {
- if (!_closed)
- rollback();
- }
-
- void transaction::commit()
- {
- static const statement sCommit("COMMIT");
- if (_closed)
- throw exception("transaction is already closed", error_code::Unknown);
- _connection.execute(sCommit);
- _closed = true;
- }
-
- void transaction::rollback()
- {
- static const statement sRollback("ROLLBACK");
- if (_closed)
- throw exception("transaction is already closed", error_code::Unknown);
- _connection.execute(sRollback);
- _closed = true;
- }
-
- void transaction::begin()
- {
- static const statement sCommit("START TRANSACTION");
- _connection.execute(sCommit);
- }
-
- }
|