~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/rollback_to_savepoint.cc

  • Committer: Olaf van der Spek
  • Date: 2011-04-16 13:00:30 UTC
  • mto: (2280.2.3 build)
  • mto: This revision was merged to the branch mainline in revision 2281.
  • Revision ID: olafvdspek@gmail.com-20110416130030-53mitypb2aenxpkb
Prune

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
3
3
 *
4
 
 *  Copyright (C) 2009 Sun Microsystems
 
4
 *  Copyright (C) 2009 Sun Microsystems, Inc.
5
5
 *
6
6
 *  This program is free software; you can redistribute it and/or modify
7
7
 *  it under the terms of the GNU General Public License as published by
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
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"
 
25
#include <drizzled/transaction_services.h>
 
26
#include <drizzled/named_savepoint.h>
 
27
#include <drizzled/util/functors.h>
 
28
#include <drizzled/session/transactions.h>
28
29
 
29
30
#include <string>
30
31
 
31
32
using namespace std;
32
33
 
33
 
namespace drizzled
34
 
{
 
34
namespace drizzled {
35
35
 
36
36
bool statement::RollbackToSavepoint::execute()
37
37
{
38
38
  /*
 
39
   * If AUTOCOMMIT is off and resource contexts are empty then we need
 
40
   * to start a transaction. It will be empty when ROLLBACK TO SAVEPOINT
 
41
   * starts the transaction. Table affecting statements do this work in
 
42
   * lockTables() by calling startStatement().
 
43
   */
 
44
  if ( (session().options & OPTION_NOT_AUTOCOMMIT) &&
 
45
       (transaction().all.getResourceContexts().empty() == true) )
 
46
  {
 
47
    if (session().startTransaction() == false)
 
48
    {
 
49
      return false;
 
50
    }
 
51
  }
 
52
 
 
53
  /*
39
54
   * Handle these situations:
40
55
   *
41
56
   * If the first savepoint on the deck matches the
49
64
   * find it, we must restructure the deque by removing
50
65
   * all savepoints "above" the one we find.
51
66
   */
52
 
  deque<NamedSavepoint> &savepoints= session->transaction.savepoints;
 
67
  deque<NamedSavepoint> &savepoints= transaction().savepoints;
53
68
  TransactionServices &transaction_services= TransactionServices::singleton();
54
69
 
55
70
  /* Short-circuit for no savepoints */
58
73
    my_error(ER_SP_DOES_NOT_EXIST, 
59
74
             MYF(0), 
60
75
             "SAVEPOINT", 
61
 
             session->lex->ident.str);
 
76
             lex().ident.str);
62
77
    return false;
63
78
  }
64
79
 
67
82
    NamedSavepoint &first_savepoint= savepoints.front();
68
83
    const string &first_savepoint_name= first_savepoint.getName();
69
84
    if (my_strnncoll(system_charset_info,
70
 
                     (unsigned char *) session->lex->ident.str, 
71
 
                     session->lex->ident.length,
 
85
                     (unsigned char *) lex().ident.str, 
 
86
                     lex().ident.length,
72
87
                     (unsigned char *) first_savepoint_name.c_str(), 
73
88
                     first_savepoint_name.size()) == 0)
74
89
    {
75
90
      /* Found the named savepoint we want to rollback to */
76
 
      (void) transaction_services.rollbackToSavepoint(session, first_savepoint);
 
91
      (void) transaction_services.rollbackToSavepoint(session(), first_savepoint);
77
92
 
78
 
      if (session->transaction.all.hasModifiedNonTransData())
 
93
      if (transaction().all.hasModifiedNonTransData())
79
94
      {
80
 
        push_warning(session, 
 
95
        push_warning(&session(), 
81
96
                     DRIZZLE_ERROR::WARN_LEVEL_WARN,
82
97
                     ER_WARNING_NOT_COMPLETE_ROLLBACK,
83
98
                     ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
84
99
      }
85
 
      session->my_ok();
 
100
      session().my_ok();
86
101
      return false;
87
102
    }
88
103
  }
103
118
    const string &sv_name= sv.getName();
104
119
    if (! found && 
105
120
        my_strnncoll(system_charset_info,
106
 
                     (unsigned char *) session->lex->ident.str, 
107
 
                     session->lex->ident.length,
 
121
                     (unsigned char *) lex().ident.str, 
 
122
                     lex().ident.length,
108
123
                     (unsigned char *) sv_name.c_str(), 
109
124
                     sv_name.size()) == 0)
110
125
    {
111
126
      /* Found the named savepoint we want to rollback to */
112
127
      found= true;
113
128
 
114
 
      (void) transaction_services.rollbackToSavepoint(session, sv);
 
129
      (void) transaction_services.rollbackToSavepoint(session(), sv);
115
130
    }
116
131
    if (found)
117
132
    {
126
141
  }
127
142
  if (found)
128
143
  {
129
 
    if (session->transaction.all.hasModifiedNonTransData())
 
144
    if (transaction().all.hasModifiedNonTransData())
130
145
    {
131
 
      push_warning(session, 
 
146
      push_warning(&session(), 
132
147
                   DRIZZLE_ERROR::WARN_LEVEL_WARN,
133
148
                   ER_WARNING_NOT_COMPLETE_ROLLBACK,
134
149
                   ER(ER_WARNING_NOT_COMPLETE_ROLLBACK));
135
150
    }
136
151
    /* Store new savepoints list */
137
 
    session->transaction.savepoints= new_savepoints;
138
 
    session->my_ok();
 
152
    transaction().savepoints= new_savepoints;
 
153
    session().my_ok();
139
154
  }
140
155
  else
141
156
  {
142
157
    /* restore the original savepoint list */
143
 
    session->transaction.savepoints= copy_savepoints;
 
158
    transaction().savepoints= copy_savepoints;
144
159
    my_error(ER_SP_DOES_NOT_EXIST, 
145
160
             MYF(0), 
146
161
             "SAVEPOINT", 
147
 
             session->lex->ident.str);
 
162
             lex().ident.str);
148
163
  }
149
164
  return false;
150
165
}