The Battle for Wesnoth  1.15.3+dev
save_point.cpp
Go to the documentation of this file.
1 //
2 // M A R I A D B + +
3 //
4 // Copyright Sylvain Rochette Langlois 2013,
5 // Frantisek Boranek 2015,
6 // The ViaDuck Project 2016 - 2018.
7 // Distributed under the Boost Software License, Version 1.0.
8 // (See accompanying file LICENSE or copy at
9 // http://www.boost.org/LICENSE_1_0.txt)
10 
11 #include <algorithm>
12 #include <mariadb++/connection.hpp>
13 
14 using namespace mariadb;
15 
16 namespace {
17 handle g_save_point_id = 0;
18 
19 const char* g_save_point_create = "SAVEPOINT ";
20 const char* g_save_point_rollback = "ROLLBACK TO SAVEPOINT ";
21 const char* g_save_point_release = "RELEASE SAVEPOINT ";
22 }
23 
24 //
25 // Constructor
26 //
27 save_point::save_point(transaction* trans) : m_transaction(trans) {
28  m_name = "SP" + std::to_string(++g_save_point_id);
29  m_transaction->m_connection->execute(g_save_point_create + m_name);
30 }
31 
32 //
33 // Destructor
34 //
36  if (!m_transaction) return;
37 
39  m_transaction->m_connection->execute(g_save_point_rollback + m_name);
40 }
41 
42 //
43 // Commit the change
44 //
46  if (!m_transaction) return;
47 
49  m_transaction->m_connection->execute(g_save_point_release + m_name);
50  m_transaction = NULL;
51 }
connection * m_connection
Definition: transaction.hpp:73
Class representing a SQL transaction having automatic rollback functionality.
Definition: transaction.hpp:25
transaction * m_transaction
Definition: save_point.hpp:45
void remove_save_point(save_point *sv_point)
Removes a savepoint from the list of savepoints.
Definition: transaction.cpp:65
u64 handle
Definition: types.hpp:38
std::string m_name
Definition: save_point.hpp:47
void commit()
Commits the changes and releases savepoint.
Definition: save_point.cpp:45
u64 execute(const std::string &query)
Execute a query without interest in a result.
Definition: connection.cpp:150
virtual ~save_point()
Destructor initiates automatic rollback if changes were not committed.
Definition: save_point.cpp:35
save_point(transaction *trans)
Create save_point with given transaction.
Definition: save_point.cpp:27