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/cached.h>
26
#include <drizzled/plugin/client/concurrent.h>
27
#include <drizzled/catalog/local.h>
28
#include <drizzled/execute.h>
32
Execute::Execute(Session &arg, bool wait_arg) :
38
void Execute::run(str_ref execution_string, sql::ResultSet &result_set)
40
if (not _session.isConcurrentExecuteAllowed())
42
my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
47
plugin::client::Cached *client= new plugin::client::Cached(result_set);
48
client->pushSQL(execution_string);
49
Session::shared_ptr new_session= Session::make_shared(client, catalog::local());
51
// We set the current schema. @todo do the same with catalog
52
util::string::ptr schema(_session.schema());
53
if (not schema->empty())
54
new_session->set_schema(*schema);
56
new_session->setConcurrentExecute(false);
58
// Overwrite the context in the next session, with what we have in our
59
// session. Eventually we will allow someone to change the effective
61
new_session->user()= _session.user();
62
new_session->setOriginatingServerUUID(_session.getOriginatingServerUUID());
63
new_session->setOriginatingCommitID(_session.getOriginatingCommitID());
65
if (Session::schedule(new_session))
67
Session::unlink(new_session);
71
thread= new_session->getThread();
75
if (wait && thread && thread->joinable())
77
// We want to make sure that we can be killed
78
if (_session.getThread())
80
boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
86
catch(boost::thread_interrupted const&)
88
// Just surpress and return the error
89
my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
100
void Execute::run(str_ref execution_string)
102
if (not _session.isConcurrentExecuteAllowed())
104
my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
109
plugin::client::Concurrent *client= new plugin::client::Concurrent;
110
client->pushSQL(execution_string);
111
Session::shared_ptr new_session= Session::make_shared(client, catalog::local());
113
// We set the current schema. @todo do the same with catalog
114
util::string::ptr schema(_session.schema());
115
if (not schema->empty())
116
new_session->set_schema(*schema);
118
new_session->setConcurrentExecute(false);
120
// Overwrite the context in the next session, with what we have in our
121
// session. Eventually we will allow someone to change the effective
123
new_session->user()= _session.user();
125
if (Session::schedule(new_session))
127
Session::unlink(new_session);
131
thread= new_session->getThread();
135
if (wait && thread && thread->joinable())
137
// We want to make sure that we can be killed
138
if (_session.getThread())
140
boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
146
catch(boost::thread_interrupted const&)
148
// Just surpress and return the error
149
my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
160
} /* namespace drizzled */