~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/statement/savepoint.cc

  • Committer: Stewart Smith
  • Date: 2009-12-02 06:01:21 UTC
  • mto: (1237.1.2 push)
  • mto: This revision was merged to the branch mainline in revision 1238.
  • Revision ID: stewart@flamingspork.com-20091202060121-68gyfqifqcjcmi2v
my_end() no longer requires an argument (we removed them all)

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"
 
21
#include <drizzled/server_includes.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"
27
 
 
28
 
#include <string>
29
 
#include <deque>
30
 
 
31
 
using namespace std;
32
25
 
33
26
namespace drizzled
34
27
{
41
34
  }
42
35
  else
43
36
  {
 
37
    SAVEPOINT **sv, *newsv;
 
38
    for (sv= &session->transaction.savepoints; *sv; sv= &(*sv)->prev)
 
39
    {
 
40
      if (my_strnncoll(system_charset_info,
 
41
                       (unsigned char *) session->lex->ident.str, 
 
42
                       session->lex->ident.length,
 
43
                       (unsigned char *) (*sv)->name, 
 
44
                       (*sv)->length) == 0)
 
45
        return false;
 
46
    }
 
47
    if (*sv) /* old savepoint of the same name exists */
 
48
    {
 
49
      newsv= *sv;
 
50
      ha_release_savepoint(session, *sv); // it cannot fail
 
51
      *sv= (*sv)->prev;
 
52
    }
 
53
    else if ((newsv= (SAVEPOINT *) alloc_root(&session->transaction.mem_root,
 
54
                                              savepoint_alloc_size)) == 0)
 
55
    {
 
56
      my_error(ER_OUT_OF_RESOURCES, MYF(0));
 
57
      return false;
 
58
    }
 
59
    newsv->name= strmake_root(&session->transaction.mem_root,
 
60
                              session->lex->ident.str, 
 
61
                              session->lex->ident.length);
 
62
    newsv->length= session->lex->ident.length;
44
63
    /*
45
 
     * Look through the savepoints.  If we find one with
46
 
     * the same name, delete it.
 
64
       if we'll get an error here, don't add new savepoint to the list.
 
65
       we'll lose a little bit of memory in transaction mem_root, but it'll
 
66
       be free'd when transaction ends anyway
47
67
     */
48
 
    TransactionServices &transaction_services= TransactionServices::singleton();
49
 
    deque<NamedSavepoint> &savepoints= session->transaction.savepoints;
50
 
    deque<NamedSavepoint>::iterator iter;
51
 
 
52
 
    for (iter= savepoints.begin();
53
 
         iter != savepoints.end();
54
 
         ++iter)
55
 
    {
56
 
      NamedSavepoint &sv= *iter;
57
 
      const string &sv_name= sv.getName();
58
 
      if (my_strnncoll(system_charset_info,
59
 
                       (unsigned char *) session->lex->ident.str,
60
 
                       session->lex->ident.length,
61
 
                       (unsigned char *) sv_name.c_str(),
62
 
                       sv_name.size()) == 0)
63
 
        break;
64
 
    }
65
 
    if (iter != savepoints.end())
66
 
    {
67
 
      NamedSavepoint &sv= *iter;
68
 
      (void) transaction_services.ha_release_savepoint(session, sv);
69
 
      savepoints.erase(iter);
70
 
    }
71
 
    
72
 
    NamedSavepoint newsv(session->lex->ident.str, session->lex->ident.length);
73
 
 
74
 
    if (transaction_services.ha_savepoint(session, newsv))
 
68
    if (ha_savepoint(session, newsv))
75
69
    {
76
70
      return true;
77
71
    }
78
72
    else
79
73
    {
80
 
      savepoints.push_front(newsv);
 
74
      newsv->prev= session->transaction.savepoints;
 
75
      session->transaction.savepoints= newsv;
81
76
      session->my_ok();
82
77
    }
83
78
  }
85
80
}
86
81
 
87
82
} /* namespace drizzled */
 
83