~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/savepoint.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

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/savepoint.h>
25
 
#include "drizzled/transaction_services.h"
26
 
#include "drizzled/named_savepoint.h"
 
25
#include <drizzled/transaction_services.h>
 
26
#include <drizzled/named_savepoint.h>
27
27
 
28
28
#include <string>
29
29
#include <deque>
35
35
 
36
36
bool statement::Savepoint::execute()
37
37
{
38
 
  if (! (session->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
 
38
  if (! (getSession()->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
39
39
  {
40
 
    session->my_ok();
 
40
    /* AUTOCOMMIT is on and not in a BEGIN */
 
41
    getSession()->my_ok();
41
42
  }
42
43
  else
43
44
  {
44
45
    /*
 
46
     * If AUTOCOMMIT is off and resource contexts are empty then we need
 
47
     * to start a transaction. It will be empty when SAVEPOINT starts the
 
48
     * transaction. Table affecting statements do this work in lockTables()
 
49
     * by calling startStatement().
 
50
     */
 
51
    if ( (getSession()->options & OPTION_NOT_AUTOCOMMIT) &&
 
52
         (getSession()->transaction.all.getResourceContexts().empty() == true) )
 
53
    {
 
54
      if (getSession()->startTransaction() == false)
 
55
      {
 
56
        return false;
 
57
      }
 
58
    }
 
59
 
 
60
    /*
45
61
     * Look through the savepoints.  If we find one with
46
62
     * the same name, delete it.
47
63
     */
48
64
    TransactionServices &transaction_services= TransactionServices::singleton();
49
 
    deque<NamedSavepoint> &savepoints= session->transaction.savepoints;
 
65
    deque<NamedSavepoint> &savepoints= getSession()->transaction.savepoints;
50
66
    deque<NamedSavepoint>::iterator iter;
51
67
 
52
68
    for (iter= savepoints.begin();
56
72
      NamedSavepoint &sv= *iter;
57
73
      const string &sv_name= sv.getName();
58
74
      if (my_strnncoll(system_charset_info,
59
 
                       (unsigned char *) session->lex->ident.str,
60
 
                       session->lex->ident.length,
 
75
                       (unsigned char *) getSession()->getLex()->ident.str,
 
76
                       getSession()->getLex()->ident.length,
61
77
                       (unsigned char *) sv_name.c_str(),
62
78
                       sv_name.size()) == 0)
63
79
        break;
65
81
    if (iter != savepoints.end())
66
82
    {
67
83
      NamedSavepoint &sv= *iter;
68
 
      (void) transaction_services.releaseSavepoint(session, sv);
 
84
      (void) transaction_services.releaseSavepoint(*getSession(), sv);
69
85
      savepoints.erase(iter);
70
86
    }
71
87
    
72
 
    NamedSavepoint newsv(session->lex->ident.str, session->lex->ident.length);
 
88
    NamedSavepoint newsv(getSession()->getLex()->ident.str, getSession()->getLex()->ident.length);
73
89
 
74
 
    if (transaction_services.setSavepoint(session, newsv))
 
90
    if (transaction_services.setSavepoint(*getSession(), newsv))
75
91
    {
76
92
      return true;
77
93
    }
78
94
    else
79
95
    {
80
96
      savepoints.push_front(newsv);
81
 
      session->my_ok();
 
97
      getSession()->my_ok();
82
98
    }
83
99
  }
84
100
  return false;