~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/execute.cc

  • Committer: pcrews
  • Date: 2011-05-24 17:36:24 UTC
  • mfrom: (1099.4.232 drizzle)
  • Revision ID: pcrews@lucid32-20110524173624-mwr1bvq6fa1r01ao
Updated translations + 2011.05.18 tarball tag

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/catalog/local.h"
27
 
#include "drizzled/execute.h"
28
 
 
29
 
namespace drizzled
30
 
{
 
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 {
31
31
 
32
32
Execute::Execute(Session &arg, bool wait_arg) :
33
33
  wait(wait_arg),
35
35
{
36
36
}
37
37
 
38
 
Execute::~Execute()
39
 
{
40
 
}
41
 
 
42
38
void Execute::run(const char *arg, size_t length)
43
39
{
44
 
  std::string execution_string(arg, length);
45
 
  run(execution_string);
46
 
}
47
 
 
48
 
void Execute::run(std::string &execution_string)
49
 
{
50
 
  boost_thread_shared_ptr thread;
51
 
 
52
 
  if (_session.isConcurrentExecuteAllowed())
 
40
  run(std::string(arg, length));
 
41
}
 
42
 
 
43
void Execute::run(const std::string &execution_string, sql::ResultSet &result_set)
 
44
{
 
45
  if (not _session.isConcurrentExecuteAllowed())
 
46
  {
 
47
    my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
 
48
    return;
 
49
  }
 
50
  thread_ptr thread;
 
51
  {
 
52
    plugin::client::Cached *client= new plugin::client::Cached(result_set);
 
53
    client->pushSQL(execution_string);
 
54
    Session::shared_ptr new_session= Session::make_shared(client, catalog::local());
 
55
    
 
56
    // We set the current schema.  @todo do the same with catalog
 
57
    util::string::ptr schema(_session.schema());
 
58
    if (not schema->empty())
 
59
      new_session->set_db(*schema);
 
60
    
 
61
    new_session->setConcurrentExecute(false);
 
62
    
 
63
    // Overwrite the context in the next session, with what we have in our
 
64
    // session. Eventually we will allow someone to change the effective
 
65
    // user.
 
66
    new_session->user()= _session.user();
 
67
    new_session->setOriginatingServerUUID(_session.getOriginatingServerUUID());
 
68
    new_session->setOriginatingCommitID(_session.getOriginatingCommitID());
 
69
    
 
70
    if (Session::schedule(new_session))
 
71
    {
 
72
      Session::unlink(new_session);
 
73
    }
 
74
    else if (wait)
 
75
    {
 
76
      thread= new_session->getThread();
 
77
    }
 
78
  }
 
79
  
 
80
  if (wait && thread && thread->joinable())
 
81
  {
 
82
    // We want to make sure that we can be killed
 
83
    if (_session.getThread())
 
84
    {
 
85
      boost::this_thread::restore_interruption dl(_session.getThreadInterupt());
 
86
      
 
87
      try {
 
88
        thread->join();
 
89
      }
 
90
      catch(boost::thread_interrupted const&)
 
91
      {
 
92
        // Just surpress and return the error
 
93
        my_error(drizzled::ER_QUERY_INTERRUPTED, MYF(0));
 
94
        return;
 
95
      }
 
96
    }
 
97
    else
 
98
    {
 
99
      thread->join();
 
100
    }
 
101
  }
 
102
}
 
103
 
 
104
void Execute::run(const std::string &execution_string)
 
105
{
 
106
  if (not _session.isConcurrentExecuteAllowed())
 
107
  {
 
108
    my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
 
109
    return;
 
110
  }
 
111
  thread_ptr thread;
53
112
  {
54
113
    plugin::client::Concurrent *client= new plugin::client::Concurrent;
55
114
    client->pushSQL(execution_string);
56
115
    Session::shared_ptr new_session= Session::make_shared(client, catalog::local());
57
116
 
58
117
    // We set the current schema.  @todo do the same with catalog
59
 
    util::string::const_shared_ptr schema(_session.schema());
 
118
    util::string::ptr schema(_session.schema());
60
119
    if (not schema->empty())
61
120
      new_session->set_db(*schema);
62
121
 
76
135
      thread= new_session->getThread();
77
136
    }
78
137
  }
79
 
  else
80
 
  {
81
 
    my_error(ER_WRONG_ARGUMENTS, MYF(0), "A Concurrent Execution Session can not launch another session.");
82
 
    return;
83
 
  }
84
138
 
85
139
  if (wait && thread && thread->joinable())
86
140
  {