24
24
#include "config.h"
26
#include <drizzled/copy_field.h>
27
25
#include "drizzled/session.h"
28
26
#include "drizzled/session/cache.h"
29
28
#include "drizzled/error.h"
30
29
#include "drizzled/gettext.h"
31
30
#include "drizzled/query_id.h"
53
52
#include "drizzled/identifier.h"
55
#include <drizzled/refresh_version.h>
57
#include "drizzled/table/singular.h"
54
#include "drizzled/table/instance.h"
59
56
#include "plugin/myisam/myisam.h"
60
57
#include "drizzled/internal/iocache.h"
115
int session_tablespace_op(const Session *session)
117
return test(session->tablespace_op);
121
Set the process info field of the Session structure.
123
This function is used by plug-ins. Internally, the
124
Session::set_proc_info() function should be used.
126
@see Session::set_proc_info
128
void set_session_proc_info(Session *session, const char *info)
130
session->set_proc_info(info);
133
const char *get_session_proc_info(Session *session)
135
return session->get_proc_info();
121
138
void **Session::getEngineData(const plugin::MonitoredInTransaction *monitored)
123
140
return static_cast<void **>(&ha_data[monitored->getId()].ha_ptr);
134
151
return session->options & test_options;
137
Session::Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog_arg) :
154
int session_sql_command(const Session *session)
156
return (int) session->lex->sql_command;
159
enum_tx_isolation session_tx_isolation(const Session *session)
161
return (enum_tx_isolation)session->variables.tx_isolation;
164
Session::Session(plugin::Client *client_arg) :
138
165
Open_tables_state(refresh_version),
139
166
mem_root(&main_mem_root),
142
169
query(new std::string),
143
170
_schema(new std::string("")),
144
172
client(client_arg),
146
174
scheduler_arg(NULL),
147
175
lock_id(&main_lock_id),
148
176
thread_stack(NULL),
149
177
security_ctx(identifier::User::make_shared()),
150
_where(Session::DEFAULT_WHERE),
178
where(Session::DEFAULT_WHERE),
151
179
dbug_sentry(Session_SENTRY_MAGIC),
153
181
command(COM_CONNECT),
183
211
is_fatal_error(false),
184
212
transaction_rollback_request(false),
185
213
is_fatal_sub_stmt_error(0),
214
derived_tables_processing(false),
186
215
tablespace_op(false),
187
derived_tables_processing(false),
190
218
transaction_message(NULL),
191
219
statement_message(NULL),
192
220
session_event_observers(NULL),
193
_catalog(catalog_arg),
196
223
client->setSession(this);
269
296
m_internal_handler= handler;
272
bool Session::handle_error(drizzled::error_t sql_errno, const char *message,
273
DRIZZLE_ERROR::enum_warning_level level)
299
bool Session::handle_error(uint32_t sql_errno, const char *message,
300
DRIZZLE_ERROR::enum_warning_level level)
275
302
if (m_internal_handler)
328
355
TransactionServices &transaction_services= TransactionServices::singleton();
329
transaction_services.rollbackTransaction(*this, true);
356
transaction_services.rollbackTransaction(this, true);
330
357
xid_cache_delete(&transaction.xid_state);
359
386
assert(security_ctx);
360
387
if (global_system_variables.log_warnings)
362
errmsg_printf(error::WARN, ER(ER_FORCING_CLOSE),
389
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),
363
390
internal::my_progname,
365
392
security_ctx->username().c_str());
393
419
plugin::Logging::postEndDo(this);
394
420
plugin::EventObserver::deregisterSessionEvents(*this);
422
for (PropertyMap::iterator iter= life_properties.begin(); iter != life_properties.end(); iter++)
424
delete (*iter).second;
426
life_properties.clear();
397
429
void Session::setClient(plugin::Client *client_arg)
642
674
/* Change database if necessary */
643
675
if (not in_db.empty())
645
identifier::Schema identifier(in_db);
677
SchemaIdentifier identifier(in_db);
646
678
if (change_db(this, identifier))
648
680
/* change_db() has pushed the error message. */
713
745
plugin::QueryRewriter::rewriteQuery(*_schema, *new_query);
715
747
query.reset(new_query);
716
_state.reset(new session::State(in_packet, in_packet_length));
748
_state.reset(new State(in_packet, in_packet_length));
738
770
* (Which of course should never happen...)
740
772
server_status&= ~SERVER_STATUS_IN_TRANS;
741
if (transaction_services.commitTransaction(*this, true))
773
if (transaction_services.commitTransaction(this, true))
743
775
options&= ~(OPTION_BEGIN);
755
787
case ROLLBACK_AND_CHAIN:
757
789
server_status&= ~SERVER_STATUS_IN_TRANS;
758
if (transaction_services.rollbackTransaction(*this, true))
790
if (transaction_services.rollbackTransaction(this, true))
760
792
options&= ~(OPTION_BEGIN);
761
793
if (result == true && (completion == ROLLBACK_AND_CHAIN))
792
824
if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
794
826
server_status&= ~SERVER_STATUS_IN_TRANS;
795
if (transaction_services.commitTransaction(*this, true))
827
if (transaction_services.commitTransaction(this, true))
798
830
options&= ~(OPTION_BEGIN);
804
836
bool result= true;
806
assert(! inTransaction());
808
options|= OPTION_BEGIN;
809
server_status|= SERVER_STATUS_IN_TRANS;
811
if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
838
if (! endActiveTransaction())
844
options|= OPTION_BEGIN;
845
server_status|= SERVER_STATUS_IN_TRANS;
847
if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
833
870
first_successful_insert_id_in_cur_stmt= 0;
834
871
substitute_null_with_insert_id= true;
837
873
arg_of_last_insert_id_function= false;
839
874
/* Free Items that were created during this execution */
843
_where= Session::DEFAULT_WHERE;
877
where= Session::DEFAULT_WHERE;
845
879
/* Reset the temporary shares we built */
846
880
for_each(temporary_shares.begin(),
871
905
bool allocate_lex_string)
873
907
if (allocate_lex_string)
874
if (!(lex_str= (LEX_STRING *)getMemRoot()->allocate(sizeof(LEX_STRING))))
908
if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING))))
876
910
if (!(lex_str->str= mem_root->strmake_root(str, length)))
917
951
return (result->send_fields(field_list));
920
void select_result::send_error(drizzled::error_t errcode, const char *err)
954
void select_result::send_error(uint32_t errcode, const char *err)
922
956
my_message(errcode, err, MYF(0));
926
960
Handling writing to file
927
961
************************************************************************/
929
void select_to_file::send_error(drizzled::error_t errcode,const char *err)
963
void select_to_file::send_error(uint32_t errcode,const char *err)
931
965
my_message(errcode, err, MYF(0));
1574
1608
/* Fix for Intel compiler */
1575
1609
if (copy_field)
1577
boost::checked_array_delete(copy_field);
1611
delete [] copy_field;
1578
1612
save_copy_field= save_copy_field_end= copy_field= copy_field_end= 0;
1582
1616
void Session::send_kill_message() const
1584
drizzled::error_t err= static_cast<drizzled::error_t>(killed_errno());
1618
int err= killed_errno();
1586
1620
my_message(err, ER(err), MYF(0));
1612
1646
@param session Thread handle
1613
1647
@param all true <=> rollback main transaction.
1615
void Session::markTransactionForRollback(bool all)
1649
void mark_transaction_to_rollback(Session *session, bool all)
1617
is_fatal_sub_stmt_error= true;
1618
transaction_rollback_request= all;
1653
session->is_fatal_sub_stmt_error= true;
1654
session->transaction_rollback_request= all;
1621
1658
void Session::disconnect(enum error_t errcode)
1634
1671
if (not getKilled() && variables.log_warnings > 1)
1636
errmsg_printf(error::WARN, ER(ER_NEW_ABORTING_CONNECTION)
1673
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_NEW_ABORTING_CONNECTION)
1638
1675
, (_schema->empty() ? "unconnected" : _schema->c_str())
1639
1676
, security_ctx->username().empty() == false ? security_ctx->username().c_str() : "unauthenticated"
1743
1780
table->free_io_cache();
1744
1781
table->delete_table();
1746
identifier::Table identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), table->getShare()->getPath());
1783
TableIdentifier identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), table->getShare()->getPath());
1747
1784
rm_temporary_table(table_type, identifier);
1749
boost::checked_delete(table->getMutableShare());
1786
delete table->getMutableShare();
1751
boost::checked_delete(table);
1754
1791
/** Clear most status variables. */
1772
1809
user_var_entry *Session::getVariable(const std::string &name, bool create_if_not_exists)
1811
UserVarsRange ppp= user_vars.equal_range(name);
1777
UserVars::iterator iter= user_vars.find(name);
1778
if (iter != user_vars.end())
1813
for (UserVars::iterator iter= ppp.first;
1814
iter != ppp.second; ++iter)
1779
1816
return (*iter).second;
1781
1819
if (not create_if_not_exists)
1800
1838
void Session::setVariable(const std::string &name, const std::string &value)
1802
1840
user_var_entry *updateable_var= getVariable(name.c_str(), true);
1805
updateable_var->update_hash(false,
1806
(void*)value.c_str(),
1807
static_cast<uint32_t>(value.length()), STRING_RESULT,
1809
DERIVATION_IMPLICIT, false);
1842
updateable_var->update_hash(false,
1843
(void*)value.c_str(),
1844
static_cast<uint32_t>(value.length()), STRING_RESULT,
1846
DERIVATION_IMPLICIT, false);
1813
1849
void Open_tables_state::mark_temp_tables_as_free_for_reuse()
1863
1899
TransactionServices &transaction_services= TransactionServices::singleton();
1864
1900
main_da.can_overwrite_status= true;
1865
transaction_services.autocommitOrRollback(*this, is_error());
1901
transaction_services.autocommitOrRollback(this, is_error());
1866
1902
main_da.can_overwrite_status= false;
1867
1903
transaction.stmt.reset();
1919
1955
if (not lock_tables(tables, counter, &need_reopen))
1922
1957
if (not need_reopen)
1925
1959
close_tables_for_reopen(&tables);
1928
if ((handle_derived(lex, &derived_prepare) || (handle_derived(lex, &derived_filling))))
1961
if ((handle_derived(lex, &derived_prepare) ||
1963
handle_derived(lex, &derived_filling))))
1937
1972
might be an issue (lame engines).
1940
bool Open_tables_state::rm_temporary_table(const identifier::Table &identifier, bool best_effort)
1975
bool Open_tables_state::rm_temporary_table(const TableIdentifier &identifier, bool best_effort)
1942
if (not plugin::StorageEngine::dropTable(*static_cast<Session *>(this), identifier))
1977
if (plugin::StorageEngine::dropTable(*static_cast<Session *>(this), identifier))
1944
1979
if (not best_effort)
1946
1981
std::string path;
1947
1982
identifier.getSQLPath(path);
1948
errmsg_printf(error::WARN, _("Could not remove temporary table: '%s', error: %d"),
1983
errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
1949
1984
path.c_str(), errno);
1958
bool Open_tables_state::rm_temporary_table(plugin::StorageEngine *base, const identifier::Table &identifier)
1993
bool Open_tables_state::rm_temporary_table(plugin::StorageEngine *base, const TableIdentifier &identifier)
1960
drizzled::error_t error;
1963
if (not plugin::StorageEngine::dropTable(*static_cast<Session *>(this), *base, identifier, error))
1997
if (plugin::StorageEngine::dropTable(*static_cast<Session *>(this), *base, identifier))
1965
1999
std::string path;
1966
2000
identifier.getSQLPath(path);
1967
errmsg_printf(error::WARN, _("Could not remove temporary table: '%s', error: %d"),
1968
path.c_str(), error);
2001
errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2002
path.c_str(), errno);
1990
2024
bool have_proto= false;
1992
message::Table *proto= table->getShare()->getTableMessage();
1993
if (table->getShare()->getTableMessage())
2026
message::Table *proto= table->getShare()->getTableProto();
2027
if (table->getShare()->getTableProto())
1994
2028
have_proto= true;
1996
2030
const char *answer= have_proto ? "true" : "false";
2010
table::Singular *Session::getInstanceTable()
2012
temporary_shares.push_back(new table::Singular()); // This will not go into the tableshare cache, so no key is used.
2014
table::Singular *tmp_share= temporary_shares.back();
2044
bool Session::TableMessages::storeTableMessage(const TableIdentifier &identifier, message::Table &table_message)
2046
table_message_cache.insert(make_pair(identifier.getPath(), table_message));
2051
bool Session::TableMessages::removeTableMessage(const TableIdentifier &identifier)
2053
TableMessageCache::iterator iter;
2055
iter= table_message_cache.find(identifier.getPath());
2057
if (iter == table_message_cache.end())
2060
table_message_cache.erase(iter);
2065
bool Session::TableMessages::getTableMessage(const TableIdentifier &identifier, message::Table &table_message)
2067
TableMessageCache::iterator iter;
2069
iter= table_message_cache.find(identifier.getPath());
2071
if (iter == table_message_cache.end())
2074
table_message.CopyFrom(((*iter).second));
2079
bool Session::TableMessages::doesTableMessageExist(const TableIdentifier &identifier)
2081
TableMessageCache::iterator iter;
2083
iter= table_message_cache.find(identifier.getPath());
2085
if (iter == table_message_cache.end())
2093
bool Session::TableMessages::renameTableMessage(const TableIdentifier &from, const TableIdentifier &to)
2095
TableMessageCache::iterator iter;
2097
table_message_cache[to.getPath()]= table_message_cache[from.getPath()];
2099
iter= table_message_cache.find(to.getPath());
2101
if (iter == table_message_cache.end())
2106
(*iter).second.set_schema(to.getSchemaName());
2107
(*iter).second.set_name(to.getTableName());
2112
table::Instance *Session::getInstanceTable()
2114
temporary_shares.push_back(new table::Instance()); // This will not go into the tableshare cache, so no key is used.
2116
table::Instance *tmp_share= temporary_shares.back();
2016
2118
assert(tmp_share);
2038
2140
0 if out of memory, Table object in case of success
2040
table::Singular *Session::getInstanceTable(List<CreateField> &field_list)
2142
table::Instance *Session::getInstanceTable(List<CreateField> &field_list)
2042
temporary_shares.push_back(new table::Singular(this, field_list)); // This will not go into the tableshare cache, so no key is used.
2144
temporary_shares.push_back(new table::Instance(this, field_list)); // This will not go into the tableshare cache, so no key is used.
2044
table::Singular *tmp_share= temporary_shares.back();
2146
table::Instance *tmp_share= temporary_shares.back();
2046
2148
assert(tmp_share);