23 #include <drizzled/statement/execute.h>
24 #include <drizzled/session.h>
25 #include <drizzled/execute.h>
26 #include <drizzled/user_var_entry.h>
27 #include <drizzled/plugin/listen.h>
28 #include <drizzled/plugin/client.h>
29 #include <drizzled/plugin/null_client.h>
30 #include <drizzled/plugin/client/concurrent.h>
31 #include <drizzled/sql_lex.h>
39 Execute::Execute(Session *in_session,
40 execute_string_t to_execute_arg,
42 bool is_concurrent_arg,
43 bool should_wait_arg) :
45 is_quiet(is_quiet_arg),
46 is_concurrent(is_concurrent_arg),
47 should_wait(should_wait_arg),
48 to_execute(to_execute_arg)
53 bool statement::Execute::parseVariable()
55 if (to_execute.isVariable())
57 user_var_entry *var= session().getVariable(to_execute,
false);
59 if (var && var->length && var->value && var->type == STRING_RESULT)
61 lex_string_t tmp_for_var;
62 tmp_for_var.assign(var->value, var->length);
63 to_execute.set(tmp_for_var);
73 bool statement::Execute::runStatement(plugin::NullClient&
client,
const std::string &arg)
76 if (not session().executeStatement())
79 if (session().is_error())
88 bool ret= execute_shell();
91 lex().statement=
this;
97 bool statement::Execute::execute_shell()
99 if (to_execute.size() == 0)
101 my_error(ER_WRONG_ARGUMENTS, MYF(0),
"Invalid Variable");
105 if (to_execute.isVariable())
107 if (not parseVariable())
109 my_error(ER_WRONG_ARGUMENTS, MYF(0),
"Invalid Variable");
116 if (not session().isConcurrentExecuteAllowed())
118 my_error(ER_WRONG_ARGUMENTS, MYF(0),
"A Concurrent Execution Session can not launch another session.");
123 executer.run(to_execute);
129 plugin::Client *temp= session().getClient();
130 boost::scoped_ptr<plugin::NullClient> null_client(
new plugin::NullClient);
132 session().setClient(null_client.get());
134 bool error_occured=
false;
135 bool is_savepoint=
false;
137 std::string start_sql;
141 start_sql=
"SAVEPOINT execute_internal_savepoint";
146 start_sql=
"START TRANSACTION";
149 error_occured= runStatement(*null_client, start_sql);
154 if (not error_occured)
156 typedef boost::tokenizer<boost::escaped_list_separator<char> > Tokenizer;
157 std::string full_string(to_execute.data(), to_execute.size());
158 Tokenizer tok(full_string, boost::escaped_list_separator<char>(
"\\",
";",
"\""));
160 for (Tokenizer::iterator iter= tok.begin(); iter != tok.end(); ++iter)
162 if (session().getKilled() == Session::KILL_CONNECTION)
164 if (runStatement(*null_client, *iter))
173 std::string final_sql;
176 final_sql= error_occured ?
177 "ROLLBACK TO SAVEPOINT execute_internal_savepoint" :
178 "RELEASE SAVEPOINT execute_internal_savepoint";
182 final_sql= error_occured ?
"ROLLBACK" :
"COMMIT";
187 (void)runStatement(*null_client, final_sql);
191 session().setClient(temp);
192 if (session().is_error())
194 session().clear_error(
true);
198 session().clearDiagnostics();
203 null_client->close();
207 parse(session(), to_execute);
void my_ok(ha_rows affected_rows=0, ha_rows found_rows_arg=0, uint64_t passed_id=0, const char *message=NULL)
void parse(Session &, str_ref)
TODO: Rename this file - func.h is stupid.
bool inTransaction() const