1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2009 Sun Microsystems
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
22
#include <drizzled/show.h>
23
#include <drizzled/session.h>
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"
36
bool statement::RollbackToSavepoint::execute()
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();
69
if (my_strnncoll(system_charset_info,
70
(unsigned char *) session->lex->ident.str,
71
session->lex->ident.length,
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.rollbackToSavepoint(session, first_savepoint);
78
if (session->transaction.all.hasModifiedNonTransData())
81
DRIZZLE_ERROR::WARN_LEVEL_WARN,
82
ER_WARNING_NOT_COMPLETE_ROLLBACK,
83
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
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.rollbackToSavepoint(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.hasModifiedNonTransData())
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;
144
my_error(ER_SP_DOES_NOT_EXIST,
147
session->lex->ident.str);
152
} /* namespace drizzled */