1976.7.2
by Brian Aker
Adding execute command to go along with main command. |
1 |
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
4 |
* Copyright (C) 2010 Brian Aker
|
|
5 |
*
|
|
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.
|
|
10 |
*
|
|
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.
|
|
15 |
*
|
|
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
|
|
19 |
*/
|
|
20 |
||
21 |
#include "config.h" |
|
22 |
||
23 |
#include "drizzled/session.h" |
|
24 |
#include "drizzled/user_var_entry.h" |
|
25 |
#include "drizzled/plugin/client/concurrent.h" |
|
26 |
#include "drizzled/execute.h" |
|
27 |
||
28 |
namespace drizzled |
|
29 |
{
|
|
30 |
||
31 |
Execute::Execute(Session &arg, bool wait_arg) : |
|
32 |
wait(wait_arg), |
|
33 |
_session(arg) |
|
34 |
{
|
|
35 |
}
|
|
36 |
||
37 |
Execute::~Execute() |
|
38 |
{
|
|
39 |
}
|
|
40 |
||
41 |
void Execute::run(const char *arg, size_t length) |
|
42 |
{
|
|
43 |
std::string execution_string(arg, length); |
|
44 |
run(execution_string); |
|
45 |
}
|
|
46 |
||
47 |
void Execute::run(std::string &execution_string) |
|
48 |
{
|
|
49 |
boost_thread_shared_ptr thread; |
|
50 |
||
51 |
if (_session.isConcurrentExecuteAllowed()) |
|
52 |
{
|
|
53 |
plugin::client::Concurrent *client= new plugin::client::Concurrent; |
|
54 |
client->pushSQL(execution_string); |
|
55 |
Session::shared_ptr new_session(new Session(client)); |
|
56 |
||
57 |
// We set the current schema. @todo do the same with catalog
|
|
58 |
util::string::const_shared_ptr schema(_session.schema()); |
|
59 |
if (not schema->empty()) |
|
60 |
new_session->set_db(*schema); |
|
61 |
||
62 |
new_session->setConcurrentExecute(false); |
|
63 |
||
64 |
// Overwrite the context in the next session, with what we have in our
|
|
65 |
// session. Eventually we will allow someone to change the effective
|
|
66 |
// user.
|
|
67 |
new_session->getSecurityContext()= _session.getSecurityContext(); |
|
68 |
||
69 |
if (Session::schedule(new_session)) |
|
70 |
{
|
|
71 |
Session::unlink(new_session); |
|
72 |
}
|
|
73 |
else if (wait) |
|
74 |
{
|
|
75 |
thread= new_session->getThread(); |
|
76 |
}
|
|
77 |
}
|
|
78 |
else
|
|
79 |
{
|
|
80 |
my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session."); |
|
81 |
return; |
|
82 |
}
|
|
83 |
||
84 |
if (wait && thread && thread->joinable()) |
|
85 |
{
|
|
86 |
// We want to make sure that we can be killed
|
|
87 |
boost::this_thread::restore_interruption dl(_session.getThreadInterupt()); |
|
88 |
try { |
|
89 |
thread->join(); |
|
90 |
}
|
|
91 |
catch(boost::thread_interrupted const&) |
|
92 |
{
|
|
93 |
// Just surpress and return the error
|
|
94 |
my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0)); |
|
95 |
||
96 |
return; |
|
97 |
}
|
|
98 |
}
|
|
99 |
}
|
|
100 |
||
101 |
} /* namespace drizzled */ |