22
22
#include <drizzled/show.h>
23
23
#include <drizzled/session.h>
24
24
#include <drizzled/statement/rollback_to_savepoint.h>
25
#include "drizzled/transaction_services.h"
26
#include "drizzled/named_savepoint.h"
27
#include "drizzled/util/functors.h"
29
36
bool statement::RollbackToSavepoint::execute()
32
for (sv= session->transaction.savepoints; sv; sv= sv->prev)
39
* Handle these situations:
41
* If the first savepoint on the deck matches the
42
* name to find, simply call rollback_to_savepoint
43
* for the resource managers.
45
* If the first savepoint on the deck does NOT match
46
* the name to find, then we need to search through
47
* the deque to find the savepoint we need. If we
48
* don't find it, we return an error. If we do
49
* find it, we must restructure the deque by removing
50
* all savepoints "above" the one we find.
52
deque<NamedSavepoint> &savepoints= session->transaction.savepoints;
53
TransactionServices &transaction_services= TransactionServices::singleton();
55
/* Short-circuit for no savepoints */
56
if (savepoints.empty())
58
my_error(ER_SP_DOES_NOT_EXIST,
61
session->lex->ident.str);
66
/* Short-circuit for first savepoint */
67
NamedSavepoint &first_savepoint= savepoints.front();
68
const string &first_savepoint_name= first_savepoint.getName();
34
69
if (my_strnncoll(system_charset_info,
35
70
(unsigned char *) session->lex->ident.str,
36
71
session->lex->ident.length,
37
(unsigned char *)sv->name,
45
if (ha_rollback_to_savepoint(session, sv))
47
return true; /* cannot happen */
72
(unsigned char *) first_savepoint_name.c_str(),
73
first_savepoint_name.size()) == 0)
75
/* Found the named savepoint we want to rollback to */
76
(void) transaction_services.ha_rollback_to_savepoint(session, first_savepoint);
51
78
if (session->transaction.all.modified_non_trans_table)
53
80
push_warning(session,
56
83
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
60
session->transaction.savepoints= sv;
91
* OK, from here on out it means that we have savepoints
92
* but that the first savepoint isn't the one we're looking
93
* for. We need to search through the savepoints and find
94
* the one we're looking for, removing all savepoints "above"
98
deque<NamedSavepoint> copy_savepoints(savepoints); /* used to restore if not found */
99
deque<NamedSavepoint> new_savepoints;
100
while (savepoints.empty() == false)
102
NamedSavepoint &sv= savepoints.front();
103
const string &sv_name= sv.getName();
105
my_strnncoll(system_charset_info,
106
(unsigned char *) session->lex->ident.str,
107
session->lex->ident.length,
108
(unsigned char *) sv_name.c_str(),
109
sv_name.size()) == 0)
111
/* Found the named savepoint we want to rollback to */
114
(void) transaction_services.ha_rollback_to_savepoint(session, sv);
119
* We push all savepoints "below" the found savepoint
120
* to our new savepoint list, in reverse order to keep
121
* the stack order correct.
123
new_savepoints.push_back(sv);
125
savepoints.pop_front();
129
if (session->transaction.all.modified_non_trans_table)
131
push_warning(session,
132
DRIZZLE_ERROR::WARN_LEVEL_WARN,
133
ER_WARNING_NOT_COMPLETE_ROLLBACK,
134
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
136
/* Store new savepoints list */
137
session->transaction.savepoints= new_savepoints;
142
/* restore the original savepoint list */
143
session->transaction.savepoints= copy_savepoints;
64
144
my_error(ER_SP_DOES_NOT_EXIST,