~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/execute.cc

mergeĀ lp:~hingo/drizzle/drizzle-auth_ldap-fix-and-docs

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
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
 
{
 
21
#include <config.h>
 
22
 
 
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>
 
29
 
 
30
namespace drizzled {
30
31
 
31
32
Execute::Execute(Session &arg, bool wait_arg) :
32
33
  wait(wait_arg),
34
35
{
35
36
}
36
37
 
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())
 
38
void Execute::run(str_ref execution_string, sql::ResultSet &result_set)
 
39
{
 
40
  if (not _session.isConcurrentExecuteAllowed())
 
41
  {
 
42
    my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
 
43
    return;
 
44
  }
 
45
  thread_ptr thread;
 
46
  {
 
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());
 
50
    
 
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);
 
55
    
 
56
    new_session->setConcurrentExecute(false);
 
57
    
 
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
 
60
    // user.
 
61
    new_session->user()= _session.user();
 
62
    new_session->setOriginatingServerUUID(_session.getOriginatingServerUUID());
 
63
    new_session->setOriginatingCommitID(_session.getOriginatingCommitID());
 
64
    
 
65
    if (Session::schedule(new_session))
 
66
    {
 
67
      Session::unlink(new_session);
 
68
    }
 
69
    else if (wait)
 
70
    {
 
71
      thread= new_session->getThread();
 
72
    }
 
73
  }
 
74
  
 
75
  if (wait && thread && thread->joinable())
 
76
  {
 
77
    // We want to make sure that we can be killed
 
78
    if (_session.getThread())
 
79
    {
 
80
      boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
 
81
      
 
82
      try 
 
83
      {
 
84
        thread->join();
 
85
      }
 
86
      catch(boost::thread_interrupted const&)
 
87
      {
 
88
        // Just surpress and return the error
 
89
        my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
 
90
        return;
 
91
      }
 
92
    }
 
93
    else
 
94
    {
 
95
      thread->join();
 
96
    }
 
97
  }
 
98
}
 
99
 
 
100
void Execute::run(str_ref execution_string)
 
101
{
 
102
  if (not _session.isConcurrentExecuteAllowed())
 
103
  {
 
104
    my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
 
105
    return;
 
106
  }
 
107
  thread_ptr thread;
52
108
  {
53
109
    plugin::client::Concurrent *client= new plugin::client::Concurrent;
54
110
    client->pushSQL(execution_string);
55
 
    Session::shared_ptr new_session(new Session(client));
 
111
    Session::shared_ptr new_session= Session::make_shared(client, catalog::local());
56
112
 
57
113
    // We set the current schema.  @todo do the same with catalog
58
 
    util::string::const_shared_ptr schema(_session.schema());
 
114
    util::string::ptr schema(_session.schema());
59
115
    if (not schema->empty())
60
 
      new_session->set_db(*schema);
 
116
      new_session->set_schema(*schema);
61
117
 
62
118
    new_session->setConcurrentExecute(false);
63
119
 
75
131
      thread= new_session->getThread();
76
132
    }
77
133
  }
78
 
  else
79
 
  {
80
 
    my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
81
 
    return;
82
 
  }
83
134
 
84
135
  if (wait && thread && thread->joinable())
85
136
  {
86
137
    // We want to make sure that we can be killed
87
 
    boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
88
 
    try {
 
138
    if (_session.getThread())
 
139
    {
 
140
      boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
 
141
 
 
142
      try 
 
143
      {
 
144
        thread->join();
 
145
      }
 
146
      catch(boost::thread_interrupted const&)
 
147
      {
 
148
        // Just surpress and return the error
 
149
        my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
 
150
        return;
 
151
      }
 
152
    }
 
153
    else
 
154
    {
89
155
      thread->join();
90
156
    }
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
157
  }
99
158
}
100
159