1100.3.52
by Padraig O'Sullivan
Extracted the ROLLBACK_TO_SAVEPOINT command into its own class and |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2009 Sun Microsystems
|
|
5 |
*
|
|
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.
|
|
10 |
*
|
|
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.
|
|
15 |
*
|
|
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
|
|
19 |
*/
|
|
20 |
||
1241.9.36
by Monty Taylor
ZOMG. I deleted drizzled/server_includes.h. |
21 |
#include "config.h" |
1100.3.52
by Padraig O'Sullivan
Extracted the ROLLBACK_TO_SAVEPOINT command into its own class and |
22 |
#include <drizzled/show.h> |
23 |
#include <drizzled/session.h> |
|
24 |
#include <drizzled/statement/rollback_to_savepoint.h> |
|
1273.1.2
by Jay Pipes
This patch does not change any algorithms or code paths, |
25 |
#include "drizzled/transaction_services.h" |
1273.1.4
by Jay Pipes
This patch significantly reworks the way that |
26 |
#include "drizzled/named_savepoint.h" |
27 |
#include "drizzled/util/functors.h" |
|
28 |
||
29 |
#include <string> |
|
30 |
||
31 |
using namespace std; |
|
1100.3.52
by Padraig O'Sullivan
Extracted the ROLLBACK_TO_SAVEPOINT command into its own class and |
32 |
|
1130.3.12
by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/ |
33 |
namespace drizzled |
34 |
{
|
|
1100.3.52
by Padraig O'Sullivan
Extracted the ROLLBACK_TO_SAVEPOINT command into its own class and |
35 |
|
36 |
bool statement::RollbackToSavepoint::execute() |
|
37 |
{
|
|
1273.1.4
by Jay Pipes
This patch significantly reworks the way that |
38 |
/*
|
39 |
* Handle these situations:
|
|
40 |
*
|
|
41 |
* If the first savepoint on the deck matches the
|
|
42 |
* name to find, simply call rollback_to_savepoint
|
|
43 |
* for the resource managers.
|
|
44 |
*
|
|
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.
|
|
51 |
*/
|
|
52 |
deque<NamedSavepoint> &savepoints= session->transaction.savepoints; |
|
53 |
TransactionServices &transaction_services= TransactionServices::singleton(); |
|
54 |
||
55 |
/* Short-circuit for no savepoints */
|
|
56 |
if (savepoints.empty()) |
|
57 |
{
|
|
58 |
my_error(ER_SP_DOES_NOT_EXIST, |
|
59 |
MYF(0), |
|
60 |
"SAVEPOINT", |
|
61 |
session->lex->ident.str); |
|
62 |
return false; |
|
63 |
}
|
|
64 |
||
65 |
{
|
|
66 |
/* Short-circuit for first savepoint */
|
|
67 |
NamedSavepoint &first_savepoint= savepoints.front(); |
|
68 |
const string &first_savepoint_name= first_savepoint.getName(); |
|
1100.3.52
by Padraig O'Sullivan
Extracted the ROLLBACK_TO_SAVEPOINT command into its own class and |
69 |
if (my_strnncoll(system_charset_info, |
70 |
(unsigned char *) session->lex->ident.str, |
|
71 |
session->lex->ident.length, |
|
1273.1.4
by Jay Pipes
This patch significantly reworks the way that |
72 |
(unsigned char *) first_savepoint_name.c_str(), |
73 |
first_savepoint_name.size()) == 0) |
|
74 |
{
|
|
75 |
/* Found the named savepoint we want to rollback to */
|
|
1405.3.5
by Jay Pipes
TransactionServices method names now meet code style guidelines. |
76 |
(void) transaction_services.rollbackToSavepoint(session, first_savepoint); |
1273.1.4
by Jay Pipes
This patch significantly reworks the way that |
77 |
|
1273.1.13
by Jay Pipes
Style cleanup around TransactionContext::modified_non_trans_table and dead code removal |
78 |
if (session->transaction.all.hasModifiedNonTransData()) |
1100.3.52
by Padraig O'Sullivan
Extracted the ROLLBACK_TO_SAVEPOINT command into its own class and |
79 |
{
|
80 |
push_warning(session, |
|
81 |
DRIZZLE_ERROR::WARN_LEVEL_WARN, |
|
82 |
ER_WARNING_NOT_COMPLETE_ROLLBACK, |
|
83 |
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK)); |
|
84 |
}
|
|
85 |
session->my_ok(); |
|
1273.1.4
by Jay Pipes
This patch significantly reworks the way that |
86 |
return false; |
87 |
}
|
|
88 |
}
|
|
89 |
||
90 |
/*
|
|
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"
|
|
95 |
* the one we need.
|
|
96 |
*/
|
|
97 |
bool found= false; |
|
98 |
deque<NamedSavepoint> copy_savepoints(savepoints); /* used to restore if not found */ |
|
99 |
deque<NamedSavepoint> new_savepoints; |
|
100 |
while (savepoints.empty() == false) |
|
101 |
{
|
|
102 |
NamedSavepoint &sv= savepoints.front(); |
|
103 |
const string &sv_name= sv.getName(); |
|
104 |
if (! found && |
|
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) |
|
110 |
{
|
|
111 |
/* Found the named savepoint we want to rollback to */
|
|
112 |
found= true; |
|
113 |
||
1405.3.5
by Jay Pipes
TransactionServices method names now meet code style guidelines. |
114 |
(void) transaction_services.rollbackToSavepoint(session, sv); |
1273.1.4
by Jay Pipes
This patch significantly reworks the way that |
115 |
}
|
116 |
if (found) |
|
117 |
{
|
|
118 |
/*
|
|
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.
|
|
122 |
*/
|
|
123 |
new_savepoints.push_back(sv); |
|
124 |
}
|
|
125 |
savepoints.pop_front(); |
|
126 |
}
|
|
127 |
if (found) |
|
128 |
{
|
|
1273.1.13
by Jay Pipes
Style cleanup around TransactionContext::modified_non_trans_table and dead code removal |
129 |
if (session->transaction.all.hasModifiedNonTransData()) |
1273.1.4
by Jay Pipes
This patch significantly reworks the way that |
130 |
{
|
131 |
push_warning(session, |
|
132 |
DRIZZLE_ERROR::WARN_LEVEL_WARN, |
|
133 |
ER_WARNING_NOT_COMPLETE_ROLLBACK, |
|
134 |
ER(ER_WARNING_NOT_COMPLETE_ROLLBACK)); |
|
135 |
}
|
|
136 |
/* Store new savepoints list */
|
|
137 |
session->transaction.savepoints= new_savepoints; |
|
138 |
session->my_ok(); |
|
1100.3.52
by Padraig O'Sullivan
Extracted the ROLLBACK_TO_SAVEPOINT command into its own class and |
139 |
}
|
140 |
else
|
|
141 |
{
|
|
1273.1.4
by Jay Pipes
This patch significantly reworks the way that |
142 |
/* restore the original savepoint list */
|
143 |
session->transaction.savepoints= copy_savepoints; |
|
1100.3.52
by Padraig O'Sullivan
Extracted the ROLLBACK_TO_SAVEPOINT command into its own class and |
144 |
my_error(ER_SP_DOES_NOT_EXIST, |
145 |
MYF(0), |
|
146 |
"SAVEPOINT", |
|
147 |
session->lex->ident.str); |
|
148 |
}
|
|
149 |
return false; |
|
150 |
}
|
|
1130.3.12
by Monty Taylor
using namespace drizzled; to namespace drizzled { in statement/ |
151 |
|
152 |
} /* namespace drizzled */ |