~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/savepoint.cc

  • Committer: Mark Atwood
  • Date: 2011-08-11 03:05:03 UTC
  • mfrom: (2385.1.12 refactor4)
  • Revision ID: me@mark.atwood.name-20110811030503-rp9xjihc5x3y0x4q
mergeĀ lp:~olafvdspek/drizzle/refactor4

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
22
 
#include "drizzled/show.h"
23
 
#include "drizzled/session.h"
24
 
#include "drizzled/statement/savepoint.h"
25
 
#include "drizzled/transaction_services.h"
26
 
#include "drizzled/named_savepoint.h"
 
21
#include <config.h>
 
22
#include <drizzled/show.h>
 
23
#include <drizzled/session.h>
 
24
#include <drizzled/statement/savepoint.h>
 
25
#include <drizzled/transaction_services.h>
 
26
#include <drizzled/named_savepoint.h>
 
27
#include <drizzled/session/transactions.h>
27
28
 
28
29
#include <string>
29
30
#include <deque>
30
31
 
31
32
using namespace std;
32
33
 
33
 
namespace drizzled
34
 
{
 
34
namespace drizzled {
35
35
 
36
36
bool statement::Savepoint::execute()
37
37
{
38
 
  if (! (getSession()->options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
 
38
  if (! (session().options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN)))
39
39
  {
40
40
    /* AUTOCOMMIT is on and not in a BEGIN */
41
 
    getSession()->my_ok();
 
41
    session().my_ok();
42
42
  }
43
43
  else
44
44
  {
48
48
     * transaction. Table affecting statements do this work in lockTables()
49
49
     * by calling startStatement().
50
50
     */
51
 
    if ( (getSession()->options & OPTION_NOT_AUTOCOMMIT) &&
52
 
         (getSession()->transaction.all.getResourceContexts().empty() == true) )
 
51
    if ( (session().options & OPTION_NOT_AUTOCOMMIT) &&
 
52
         (transaction().all.getResourceContexts().empty() == true) )
53
53
    {
54
 
      if (getSession()->startTransaction() == false)
 
54
      if (session().startTransaction() == false)
55
55
      {
56
56
        return false;
57
57
      }
61
61
     * Look through the savepoints.  If we find one with
62
62
     * the same name, delete it.
63
63
     */
64
 
    TransactionServices &transaction_services= TransactionServices::singleton();
65
 
    deque<NamedSavepoint> &savepoints= getSession()->transaction.savepoints;
 
64
    deque<NamedSavepoint> &savepoints= transaction().savepoints;
66
65
    deque<NamedSavepoint>::iterator iter;
67
66
 
68
67
    for (iter= savepoints.begin();
72
71
      NamedSavepoint &sv= *iter;
73
72
      const string &sv_name= sv.getName();
74
73
      if (my_strnncoll(system_charset_info,
75
 
                       (unsigned char *) getSession()->lex->ident.str,
76
 
                       getSession()->lex->ident.length,
 
74
                       (unsigned char *) lex().ident.str,
 
75
                       lex().ident.length,
77
76
                       (unsigned char *) sv_name.c_str(),
78
77
                       sv_name.size()) == 0)
79
78
        break;
81
80
    if (iter != savepoints.end())
82
81
    {
83
82
      NamedSavepoint &sv= *iter;
84
 
      (void) transaction_services.releaseSavepoint(*getSession(), sv);
 
83
      (void) TransactionServices::releaseSavepoint(session(), sv);
85
84
      savepoints.erase(iter);
86
85
    }
87
86
    
88
 
    NamedSavepoint newsv(getSession()->lex->ident.str, getSession()->lex->ident.length);
 
87
    NamedSavepoint newsv(lex().ident.str, lex().ident.length);
89
88
 
90
 
    if (transaction_services.setSavepoint(*getSession(), newsv))
 
89
    if (TransactionServices::setSavepoint(session(), newsv))
91
90
    {
92
91
      return true;
93
92
    }
94
93
    else
95
94
    {
96
95
      savepoints.push_front(newsv);
97
 
      getSession()->my_ok();
 
96
      session().my_ok();
98
97
    }
99
98
  }
100
99
  return false;