drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
drizzled/execute.cc
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/execute/common.h>
24
25#include <drizzled/session.h>
26#include <drizzled/user_var_entry.h>
27#include <drizzled/plugin/client/cached.h>
28#include <drizzled/plugin/client/concurrent.h>
29#include <drizzled/catalog/local.h>
30#include <drizzled/execute.h>
31
32namespace drizzled {
33
34Execute::Execute(Session &arg, bool wait_arg) :
35 wait(wait_arg),
36 _session(arg)
37{
38}
39
40void Execute::run(str_ref execution_string, sql::ResultSet &result_set)
41{
42 if (not _session.isConcurrentExecuteAllowed())
43 {
44 my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
45 return;
46 }
47 thread_ptr thread;
48 {
49 plugin::client::Cached *client= new plugin::client::Cached(result_set);
50 client->pushSQL(execution_string);
51 Session::shared_ptr new_session= Session::make_shared(client, catalog::local());
52
53 // We set the current schema. @todo do the same with catalog
54 util::string::ptr schema(_session.schema());
55 if (not schema->empty())
56 new_session->set_schema(*schema);
57
58 new_session->setConcurrentExecute(false);
59
60 // Overwrite the context in the next session, with what we have in our
61 // session. Eventually we will allow someone to change the effective
62 // user.
63 new_session->user()= _session.user();
64 new_session->setOriginatingServerUUID(_session.getOriginatingServerUUID());
65 new_session->setOriginatingCommitID(_session.getOriginatingCommitID());
66
67 if (Session::schedule(new_session))
68 {
69 Session::unlink(new_session);
70 }
71 else if (wait)
72 {
73 thread= new_session->getThread();
74 }
75 }
76
77 if (wait && thread && thread->joinable())
78 {
79 // We want to make sure that we can be killed
80 if (_session.getThread())
81 {
82 boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
83
84 try
85 {
86 thread->join();
87 }
88 catch(boost::thread_interrupted const&)
89 {
90 // Just surpress and return the error
91 my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
92 return;
93 }
94 }
95 else
96 {
97 thread->join();
98 }
99 }
100}
101
102void Execute::run(str_ref execution_string)
103{
104 if (not _session.isConcurrentExecuteAllowed())
105 {
106 my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
107 return;
108 }
109 thread_ptr thread;
110 {
111 plugin::client::Concurrent *client= new plugin::client::Concurrent;
112 client->pushSQL(execution_string);
113 Session::shared_ptr new_session= Session::make_shared(client, catalog::local());
114
115 // We set the current schema. @todo do the same with catalog
116 util::string::ptr schema(_session.schema());
117 if (not schema->empty())
118 new_session->set_schema(*schema);
119
120 new_session->setConcurrentExecute(false);
121
122 // Overwrite the context in the next session, with what we have in our
123 // session. Eventually we will allow someone to change the effective
124 // user.
125 new_session->user()= _session.user();
126
127 if (Session::schedule(new_session))
128 {
129 Session::unlink(new_session);
130 }
131 else if (wait)
132 {
133 thread= new_session->getThread();
134 }
135 }
136
137 if (wait && thread && thread->joinable())
138 {
139 // We want to make sure that we can be killed
140 if (_session.getThread())
141 {
142 boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
143
144 try
145 {
146 thread->join();
147 }
148 catch(boost::thread_interrupted const&)
149 {
150 // Just surpress and return the error
151 my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
152 return;
153 }
154 }
155 else
156 {
157 thread->join();
158 }
159 }
160}
161
162} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.