24
24
#include "config.h"
26
#include <drizzled/copy_field.h>
25
27
#include "drizzled/session.h"
26
28
#include "drizzled/session/cache.h"
28
29
#include "drizzled/error.h"
29
30
#include "drizzled/gettext.h"
30
31
#include "drizzled/query_id.h"
117
int session_tablespace_op(const Session *session)
119
return test(session->tablespace_op);
123
Set the process info field of the Session structure.
125
This function is used by plug-ins. Internally, the
126
Session::set_proc_info() function should be used.
128
@see Session::set_proc_info
130
void set_session_proc_info(Session *session, const char *info)
132
session->set_proc_info(info);
135
const char *get_session_proc_info(Session *session)
137
return session->get_proc_info();
140
121
void **Session::getEngineData(const plugin::MonitoredInTransaction *monitored)
142
123
return static_cast<void **>(&ha_data[monitored->getId()].ha_ptr);
153
134
return session->options & test_options;
156
int session_sql_command(const Session *session)
158
return (int) session->lex->sql_command;
161
enum_tx_isolation session_tx_isolation(const Session *session)
163
return (enum_tx_isolation)session->variables.tx_isolation;
166
137
Session::Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog_arg) :
167
138
Open_tables_state(refresh_version),
168
139
mem_root(&main_mem_root),
176
147
lock_id(&main_lock_id),
177
148
thread_stack(NULL),
178
149
security_ctx(identifier::User::make_shared()),
179
where(Session::DEFAULT_WHERE),
150
_where(Session::DEFAULT_WHERE),
180
151
dbug_sentry(Session_SENTRY_MAGIC),
182
153
command(COM_CONNECT),
212
183
is_fatal_error(false),
213
184
transaction_rollback_request(false),
214
185
is_fatal_sub_stmt_error(0),
186
tablespace_op(false),
215
187
derived_tables_processing(false),
216
tablespace_op(false),
219
190
transaction_message(NULL),
357
328
TransactionServices &transaction_services= TransactionServices::singleton();
358
transaction_services.rollbackTransaction(this, true);
329
transaction_services.rollbackTransaction(*this, true);
359
330
xid_cache_delete(&transaction.xid_state);
388
359
assert(security_ctx);
389
360
if (global_system_variables.log_warnings)
391
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),
362
errmsg_printf(error::WARN, ER(ER_FORCING_CLOSE),
392
363
internal::my_progname,
394
365
security_ctx->username().c_str());
422
393
plugin::Logging::postEndDo(this);
423
394
plugin::EventObserver::deregisterSessionEvents(*this);
425
for (PropertyMap::iterator iter= life_properties.begin(); iter != life_properties.end(); iter++)
427
boost::checked_delete((*iter).second);
429
life_properties.clear();
432
397
void Session::setClient(plugin::Client *client_arg)
748
713
plugin::QueryRewriter::rewriteQuery(*_schema, *new_query);
750
715
query.reset(new_query);
751
_state.reset(new State(in_packet, in_packet_length));
716
_state.reset(new session::State(in_packet, in_packet_length));
773
738
* (Which of course should never happen...)
775
740
server_status&= ~SERVER_STATUS_IN_TRANS;
776
if (transaction_services.commitTransaction(this, true))
741
if (transaction_services.commitTransaction(*this, true))
778
743
options&= ~(OPTION_BEGIN);
790
755
case ROLLBACK_AND_CHAIN:
792
757
server_status&= ~SERVER_STATUS_IN_TRANS;
793
if (transaction_services.rollbackTransaction(this, true))
758
if (transaction_services.rollbackTransaction(*this, true))
795
760
options&= ~(OPTION_BEGIN);
796
761
if (result == true && (completion == ROLLBACK_AND_CHAIN))
827
792
if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
829
794
server_status&= ~SERVER_STATUS_IN_TRANS;
830
if (transaction_services.commitTransaction(this, true))
795
if (transaction_services.commitTransaction(*this, true))
833
798
options&= ~(OPTION_BEGIN);
839
804
bool result= true;
841
if (! endActiveTransaction())
806
assert(! inTransaction());
808
options|= OPTION_BEGIN;
809
server_status|= SERVER_STATUS_IN_TRANS;
811
if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
847
options|= OPTION_BEGIN;
848
server_status|= SERVER_STATUS_IN_TRANS;
850
if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
873
833
first_successful_insert_id_in_cur_stmt= 0;
874
834
substitute_null_with_insert_id= true;
876
837
arg_of_last_insert_id_function= false;
877
839
/* Free Items that were created during this execution */
880
where= Session::DEFAULT_WHERE;
843
_where= Session::DEFAULT_WHERE;
882
845
/* Reset the temporary shares we built */
883
846
for_each(temporary_shares.begin(),
908
871
bool allocate_lex_string)
910
873
if (allocate_lex_string)
911
if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING))))
874
if (!(lex_str= (LEX_STRING *)getMemRoot()->allocate(sizeof(LEX_STRING))))
913
876
if (!(lex_str->str= mem_root->strmake_root(str, length)))
1649
1612
@param session Thread handle
1650
1613
@param all true <=> rollback main transaction.
1652
void mark_transaction_to_rollback(Session *session, bool all)
1615
void Session::markTransactionForRollback(bool all)
1656
session->is_fatal_sub_stmt_error= true;
1657
session->transaction_rollback_request= all;
1617
is_fatal_sub_stmt_error= true;
1618
transaction_rollback_request= all;
1661
1621
void Session::disconnect(enum error_t errcode)
1674
1634
if (not getKilled() && variables.log_warnings > 1)
1676
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_NEW_ABORTING_CONNECTION)
1636
errmsg_printf(error::WARN, ER(ER_NEW_ABORTING_CONNECTION)
1678
1638
, (_schema->empty() ? "unconnected" : _schema->c_str())
1679
1639
, security_ctx->username().empty() == false ? security_ctx->username().c_str() : "unauthenticated"
1812
1772
user_var_entry *Session::getVariable(const std::string &name, bool create_if_not_exists)
1814
UserVarsRange ppp= user_vars.equal_range(name);
1816
for (UserVars::iterator iter= ppp.first;
1817
iter != ppp.second; ++iter)
1777
UserVars::iterator iter= user_vars.find(name);
1778
if (iter != user_vars.end())
1819
1779
return (*iter).second;
1822
1781
if (not create_if_not_exists)
1841
1800
void Session::setVariable(const std::string &name, const std::string &value)
1843
1802
user_var_entry *updateable_var= getVariable(name.c_str(), true);
1845
updateable_var->update_hash(false,
1846
(void*)value.c_str(),
1847
static_cast<uint32_t>(value.length()), STRING_RESULT,
1849
DERIVATION_IMPLICIT, false);
1805
updateable_var->update_hash(false,
1806
(void*)value.c_str(),
1807
static_cast<uint32_t>(value.length()), STRING_RESULT,
1809
DERIVATION_IMPLICIT, false);
1852
1813
void Open_tables_state::mark_temp_tables_as_free_for_reuse()
1902
1863
TransactionServices &transaction_services= TransactionServices::singleton();
1903
1864
main_da.can_overwrite_status= true;
1904
transaction_services.autocommitOrRollback(this, is_error());
1865
transaction_services.autocommitOrRollback(*this, is_error());
1905
1866
main_da.can_overwrite_status= false;
1906
1867
transaction.stmt.reset();
1985
1946
std::string path;
1986
1947
identifier.getSQLPath(path);
1987
errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
1948
errmsg_printf(error::WARN, _("Could not remove temporary table: '%s', error: %d"),
1988
1949
path.c_str(), errno);
2004
1965
std::string path;
2005
1966
identifier.getSQLPath(path);
2006
errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
1967
errmsg_printf(error::WARN, _("Could not remove temporary table: '%s', error: %d"),
2007
1968
path.c_str(), error);
2029
1990
bool have_proto= false;
2031
message::Table *proto= table->getShare()->getTableProto();
2032
if (table->getShare()->getTableProto())
1992
message::Table *proto= table->getShare()->getTableMessage();
1993
if (table->getShare()->getTableMessage())
2033
1994
have_proto= true;
2035
1996
const char *answer= have_proto ? "true" : "false";
2049
bool Session::TableMessages::storeTableMessage(const identifier::Table &identifier, message::Table &table_message)
2051
table_message_cache.insert(make_pair(identifier.getPath(), table_message));
2056
bool Session::TableMessages::removeTableMessage(const identifier::Table &identifier)
2058
TableMessageCache::iterator iter;
2060
iter= table_message_cache.find(identifier.getPath());
2062
if (iter == table_message_cache.end())
2065
table_message_cache.erase(iter);
2070
bool Session::TableMessages::getTableMessage(const identifier::Table &identifier, message::Table &table_message)
2072
TableMessageCache::iterator iter;
2074
iter= table_message_cache.find(identifier.getPath());
2076
if (iter == table_message_cache.end())
2079
table_message.CopyFrom(((*iter).second));
2084
bool Session::TableMessages::doesTableMessageExist(const identifier::Table &identifier)
2086
TableMessageCache::iterator iter;
2088
iter= table_message_cache.find(identifier.getPath());
2090
if (iter == table_message_cache.end())
2098
bool Session::TableMessages::renameTableMessage(const identifier::Table &from, const identifier::Table &to)
2100
TableMessageCache::iterator iter;
2102
table_message_cache[to.getPath()]= table_message_cache[from.getPath()];
2104
iter= table_message_cache.find(to.getPath());
2106
if (iter == table_message_cache.end())
2111
(*iter).second.set_schema(to.getSchemaName());
2112
(*iter).second.set_name(to.getTableName());
2117
2010
table::Singular *Session::getInstanceTable()
2119
2012
temporary_shares.push_back(new table::Singular()); // This will not go into the tableshare cache, so no key is used.