Drizzled Public API Documentation

release_savepoint.cc
00001 /* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
00002  *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
00003  *
00004  *  Copyright (C) 2009 Sun Microsystems, Inc.
00005  *
00006  *  This program is free software; you can redistribute it and/or modify
00007  *  it under the terms of the GNU General Public License as published by
00008  *  the Free Software Foundation; either version 2 of the License, or
00009  *  (at your option) any later version.
00010  *
00011  *  This program is distributed in the hope that it will be useful,
00012  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *  GNU General Public License for more details.
00015  *
00016  *  You should have received a copy of the GNU General Public License
00017  *  along with this program; if not, write to the Free Software
00018  *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
00019  */
00020 
00021 #include <config.h>
00022 #include <drizzled/show.h>
00023 #include <drizzled/session.h>
00024 #include <drizzled/statement/release_savepoint.h>
00025 #include <drizzled/transaction_services.h>
00026 #include <drizzled/named_savepoint.h>
00027 
00028 #include <string>
00029 
00030 using namespace std;
00031 
00032 namespace drizzled
00033 {
00034 
00035 bool statement::ReleaseSavepoint::execute()
00036 {
00037   /*
00038    * Look through the deque of savepoints.  If we
00039    * find one with the same name, we release it and
00040    * unbind it from our deque.
00041    */
00042   TransactionServices &transaction_services= TransactionServices::singleton();
00043   deque<NamedSavepoint> &savepoints= transaction().savepoints;
00044   deque<NamedSavepoint>::iterator iter;
00045 
00046   for (iter= savepoints.begin();
00047        iter != savepoints.end();
00048        ++iter)
00049   {
00050     NamedSavepoint &sv= *iter;
00051     const string &sv_name= sv.getName();
00052     if (my_strnncoll(system_charset_info,
00053                      (unsigned char *) lex().ident.str,
00054                      lex().ident.length,
00055                      (unsigned char *) sv_name.c_str(),
00056                      sv_name.size()) == 0)
00057       break;
00058   }
00059   if (iter != savepoints.end())
00060   {
00061     NamedSavepoint &sv= *iter;
00062     (void) transaction_services.releaseSavepoint(session(), sv);
00063     savepoints.erase(iter);
00064     session().my_ok();
00065   }
00066   else
00067   {
00068     my_error(ER_SP_DOES_NOT_EXIST, 
00069              MYF(0), 
00070              "SAVEPOINT", 
00071              lex().ident.str);
00072   }
00073   return false;
00074 }
00075 
00076 } /* namespace drizzled */