1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23
#include "drizzled/session.h"
24
#include "drizzled/user_var_entry.h"
25
#include "drizzled/plugin/client/concurrent.h"
26
#include "drizzled/catalog/local.h"
27
#include "drizzled/execute.h"
32
Execute::Execute(Session &arg, bool wait_arg) :
42
void Execute::run(const char *arg, size_t length)
44
std::string execution_string(arg, length);
45
run(execution_string);
48
void Execute::run(std::string &execution_string)
50
boost_thread_shared_ptr thread;
52
if (_session.isConcurrentExecuteAllowed())
54
plugin::client::Concurrent *client= new plugin::client::Concurrent;
55
client->pushSQL(execution_string);
56
Session::shared_ptr new_session= Session::make_shared(client, catalog::local());
58
// We set the current schema. @todo do the same with catalog
59
util::string::const_shared_ptr schema(_session.schema());
60
if (not schema->empty())
61
new_session->set_db(*schema);
63
new_session->setConcurrentExecute(false);
65
// Overwrite the context in the next session, with what we have in our
66
// session. Eventually we will allow someone to change the effective
68
new_session->user()= _session.user();
70
if (Session::schedule(new_session))
72
Session::unlink(new_session);
76
thread= new_session->getThread();
81
my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
85
if (wait && thread && thread->joinable())
87
// We want to make sure that we can be killed
88
if (_session.getThread())
90
boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
95
catch(boost::thread_interrupted const&)
97
// Just surpress and return the error
98
my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
109
} /* namespace drizzled */