1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2008 Sun Microsystems
4
* Copyright (C) 2008 Sun Microsystems, Inc.
6
6
* This program is free software; you can redistribute it and/or modify
7
7
* it under the terms of the GNU General Public License as published by
49
49
#include "drizzled/transaction_services.h"
50
50
#include "drizzled/drizzled.h"
52
#include "drizzled/identifier.h"
52
54
#include "drizzled/table/instance.h"
54
56
#include "plugin/myisam/myisam.h"
100
102
The following functions form part of the C plugin API
102
int mysql_tmpfile(const char *prefix)
104
int tmpfile(const char *prefix)
104
106
char filename[FN_REFLEN];
105
107
int fd = internal::create_temp_file(filename, drizzle_tmpdir.c_str(), prefix, MYF(MY_WME));
159
161
return (enum_tx_isolation)session->variables.tx_isolation;
162
Session::Session(plugin::Client *client_arg) :
164
Session::Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog_arg) :
163
165
Open_tables_state(refresh_version),
164
166
mem_root(&main_mem_root),
167
169
query(new std::string),
168
170
_schema(new std::string("")),
170
171
client(client_arg),
172
173
scheduler_arg(NULL),
173
174
lock_id(&main_lock_id),
176
security_ctx(identifier::User::make_shared()),
177
where(Session::DEFAULT_WHERE),
178
dbug_sentry(Session_SENTRY_MAGIC),
180
command(COM_CONNECT),
182
_epoch(boost::gregorian::date(1970,1,1)),
183
_connect_time(boost::posix_time::microsec_clock::universal_time()),
175
185
ha_data(plugin::num_trx_monitored_objects),
176
188
concurrent_execute_allowed(true),
177
189
arg_of_last_insert_id_function(false),
178
190
first_successful_insert_id_in_prev_stmt(0),
179
191
first_successful_insert_id_in_cur_stmt(0),
180
192
limit_found_rows(0),
193
options(session_startup_options),
196
examined_row_count(0),
200
statement_id_counter(0),
181
204
_global_read_lock(NONE),
205
count_cuted_fields(CHECK_FIELD_ERROR_FOR_NULL),
182
206
_killed(NOT_KILLED),
183
207
some_tables_deleted(false),
184
208
no_errors(false),
203
228
will be re-initialized in init_for_queries().
205
230
memory::init_sql_alloc(&main_mem_root, memory::ROOT_MIN_BLOCK_SIZE, 0);
207
count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
211
231
cuted_fields= sent_row_count= row_count= 0L;
213
statement_id_counter= 0UL;
214
232
// Must be reset to handle error with Session's created for init of mysqld
215
233
lex->current_select= 0;
216
start_time=(time_t) 0;
218
utime_after_lock= 0L;
219
234
memset(&variables, 0, sizeof(variables));
225
235
scoreboard_index= -1;
226
dbug_sentry=Session_SENTRY_MAGIC;
227
236
cleanup_done= abort_on_warning= no_warnings_for_error= false;
229
238
/* query_cache init */
244
251
variables.pseudo_thread_id= thread_id;
245
252
server_status= SERVER_STATUS_AUTOCOMMIT;
246
options= session_startup_options;
248
254
if (variables.max_join_size == HA_POS_ERROR)
249
255
options |= OPTION_BIG_SELECTS;
255
261
session_tx_isolation= (enum_tx_isolation) variables.tx_isolation;
256
262
warn_list.empty();
257
263
memset(warn_count, 0, sizeof(warn_count));
259
264
memset(&status_var, 0, sizeof(status_var));
261
266
/* Initialize sub structures */
377
382
this->checkSentry();
379
if (client->isConnected())
384
if (client and client->isConnected())
386
assert(security_ctx);
381
387
if (global_system_variables.log_warnings)
382
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),internal::my_progname,
384
(getSecurityContext().getUser().c_str() ?
385
getSecurityContext().getUser().c_str() : ""));
386
disconnect(0, false);
389
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),
390
internal::my_progname,
392
security_ctx->username().c_str());
389
398
/* Close connection */
393
405
if (cleanup_done == false)
561
573
arg->scheduler= plugin::Scheduler::getScheduler();
562
574
assert(arg->scheduler);
564
connection_count.increment();
566
if (connection_count > current_global_counters.max_used_connections)
578
long current_connections= connection_count;
580
if (current_connections > 0 and static_cast<uint64_t>(current_connections) > current_global_counters.max_used_connections)
568
current_global_counters.max_used_connections= connection_count;
582
current_global_counters.max_used_connections= static_cast<uint64_t>(connection_count);
571
585
current_global_counters.connections++;
604
618
Is this session viewable by the current user?
606
bool Session::isViewable() const
620
bool Session::isViewable(identifier::User::const_reference user_arg) const
608
return plugin::Authorization::isAuthorized(current_session->getSecurityContext(),
622
return plugin::Authorization::isAuthorized(user_arg, this, false);
651
662
const std::string &in_db)
653
664
bool is_authenticated=
654
plugin::Authentication::isAuthenticated(getSecurityContext(),
665
plugin::Authentication::isAuthenticated(user(), passwd_str);
657
667
if (is_authenticated != true)
665
675
if (not in_db.empty())
667
677
SchemaIdentifier identifier(in_db);
668
if (mysql_change_db(this, identifier))
678
if (change_db(this, identifier))
670
/* mysql_change_db() has pushed the error message. */
680
/* change_db() has pushed the error message. */
1504
1514
bool select_max_min_finder_subselect::cmp_decimal()
1506
1516
Item *maxmin= ((Item_singlerow_subselect *)item)->element_index(0);
1507
my_decimal cval, *cvalue= cache->val_decimal(&cval);
1508
my_decimal mval, *mvalue= maxmin->val_decimal(&mval);
1517
type::Decimal cval, *cvalue= cache->val_decimal(&cval);
1518
type::Decimal mval, *mvalue= maxmin->val_decimal(&mval);
1510
1520
return (cache->null_value && !maxmin->null_value) ||
1511
1521
(!cache->null_value && !maxmin->null_value &&
1512
my_decimal_cmp(cvalue, mvalue) > 0) ;
1522
class_decimal_cmp(cvalue, mvalue) > 0) ;
1513
1523
return (maxmin->null_value && !cache->null_value) ||
1514
1524
(!cache->null_value && !maxmin->null_value &&
1515
my_decimal_cmp(cvalue,mvalue) < 0);
1525
class_decimal_cmp(cvalue,mvalue) < 0);
1518
1528
bool select_max_min_finder_subselect::cmp_str()
1648
void Session::disconnect(uint32_t errcode, bool should_lock)
1658
void Session::disconnect(enum error_t errcode)
1650
1660
/* Allow any plugins to cleanup their session variables */
1651
1661
plugin_sessionvar_cleanup(this);
1661
1671
if (not getKilled() && variables.log_warnings > 1)
1663
SecurityContext *sctx= &security_ctx;
1665
1673
errmsg_printf(ERRMSG_LVL_WARN, ER(ER_NEW_ABORTING_CONNECTION)
1667
1675
, (_schema->empty() ? "unconnected" : _schema->c_str())
1668
, sctx->getUser().empty() == false ? sctx->getUser().c_str() : "unauthenticated"
1669
, sctx->getIp().c_str()
1676
, security_ctx->username().empty() == false ? security_ctx->username().c_str() : "unauthenticated"
1677
, security_ctx->address().c_str()
1670
1678
, (main_da.is_error() ? main_da.message() : ER(ER_UNKNOWN_ERROR)));
1674
/* Close out our connection to the client */
1676
session::Cache::singleton().mutex().lock();
1678
1682
setKilled(Session::KILL_CONNECTION);
1680
1684
if (client->isConnected())
1686
if (errcode != EE_OK)
1684
1688
/*my_error(errcode, ER(errcode));*/
1685
1689
client->sendError(errcode, ER(errcode));
1687
1691
client->close();
1692
session::Cache::singleton().mutex().unlock();
1696
1695
void Session::reset_for_next_command()
1923
1921
Note that we need to hold table::Cache::singleton().mutex() while changing the
1924
1922
open_tables list. Another thread may work on it.
1925
(See: table::Cache::singleton().removeTable(), mysql_wait_completed_table())
1923
(See: table::Cache::singleton().removeTable(), wait_completed_table())
1926
1924
Closing a MERGE child before the parent would be fatal if the
1927
1925
other thread tries to abort the MERGE lock in between.
1957
1955
if (not lock_tables(tables, counter, &need_reopen))
1959
1958
if (not need_reopen)
1961
1961
close_tables_for_reopen(&tables);
1963
if ((mysql_handle_derived(lex, &mysql_derived_prepare) ||
1965
mysql_handle_derived(lex, &mysql_derived_filling))))
1964
if ((handle_derived(lex, &derived_prepare) || (handle_derived(lex, &derived_filling))))
1977
1976
bool Open_tables_state::rm_temporary_table(const TableIdentifier &identifier, bool best_effort)
1979
if (plugin::StorageEngine::dropTable(*static_cast<Session *>(this), identifier))
1978
if (not plugin::StorageEngine::dropTable(*static_cast<Session *>(this), identifier))
1981
1980
if (not best_effort)
1995
1994
bool Open_tables_state::rm_temporary_table(plugin::StorageEngine *base, const TableIdentifier &identifier)
1996
drizzled::error_t error;
1999
if (plugin::StorageEngine::dropTable(*static_cast<Session *>(this), *base, identifier))
1999
if (not plugin::StorageEngine::dropTable(*static_cast<Session *>(this), *base, identifier, error))
2001
2001
std::string path;
2002
2002
identifier.getSQLPath(path);
2003
2003
errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2004
path.c_str(), errno);
2004
path.c_str(), error);