~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Lee Bieber
  • Date: 2011-03-23 01:55:35 UTC
  • mfrom: (2245.1.2 build)
  • Revision ID: kalebral@gmail.com-20110323015535-2aatqy8tyiuqtc2z
Merge Olaf - more code refactoring

Show diffs side-by-side

added added

removed removed

Lines of Context:
68
68
#include <drizzled/session/property_map.h>
69
69
#include <drizzled/session/state.h>
70
70
#include <drizzled/session/table_messages.h>
 
71
#include <drizzled/session/transactions.h>
71
72
#include <drizzled/show.h>
72
73
#include <drizzled/sql_base.h>
73
74
#include <drizzled/sql_lex.h>
 
75
#include <drizzled/system_variables.h>
74
76
#include <drizzled/statement.h>
 
77
#include <drizzled/statistics_variables.h>
75
78
#include <drizzled/table/singular.h>
76
79
#include <drizzled/table_proto.h>
77
80
#include <drizzled/tmp_table_param.h>
147
150
{
148
151
public:
149
152
  typedef session::PropertyMap properties_t;
 
153
  typedef std::map<std::string, plugin::EventObserverList*> schema_event_observers_t;
150
154
 
151
155
  Diagnostics_area diagnostics;
152
156
  /**
157
161
  */
158
162
  LEX lex;
159
163
  properties_t properties;
 
164
  schema_event_observers_t schema_event_observers;
 
165
  system_status_var status_var;
160
166
  session::TableMessages table_message_cache;
 
167
  std::vector<table::Singular*> temporary_shares;
 
168
        session::Transactions transaction;
 
169
  drizzle_system_variables variables;
161
170
};
162
171
 
163
172
Session::Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog_arg) :
164
173
  Open_tables_state(refresh_version),
 
174
  impl_(new impl_c),
165
175
  mem_root(&main_mem_root),
166
176
  query(new std::string),
167
 
  _schema(new std::string),
168
177
  scheduler(NULL),
169
178
  scheduler_arg(NULL),
 
179
  variables(impl_->variables),
 
180
  status_var(impl_->status_var),
170
181
  lock_id(&main_lock_id),
171
182
  thread_stack(NULL),
172
183
  _where(Session::DEFAULT_WHERE),
179
190
  ha_data(plugin::num_trx_monitored_objects),
180
191
  query_id(0),
181
192
  warn_query_id(0),
 
193
        transaction(impl_->transaction),
182
194
  first_successful_insert_id_in_prev_stmt(0),
183
195
  first_successful_insert_id_in_cur_stmt(0),
184
196
  limit_found_rows(0),
188
200
  examined_row_count(0),
189
201
  used_tables(0),
190
202
  total_warn_count(0),
191
 
  col_access(0),
192
 
  statement_id_counter(0),
193
203
  row_count(0),
194
204
  thread_id(0),
195
205
  tmp_table(0),
198
208
  _killed(NOT_KILLED),
199
209
  some_tables_deleted(false),
200
210
  no_errors(false),
201
 
  password(false),
202
211
  is_fatal_error(false),
203
212
  transaction_rollback_request(false),
204
213
  is_fatal_sub_stmt_error(0),
205
214
  derived_tables_processing(false),
206
215
  m_lip(NULL),
207
 
  cached_table(0),
208
216
  arg_of_last_insert_id_function(false),
209
 
  impl_(new impl_c),
210
217
  _catalog(catalog_arg),
211
218
  transaction_message(NULL),
212
219
  statement_message(NULL),
257
264
  open_options=ha_open_options;
258
265
  update_lock_default= TL_WRITE;
259
266
  session_tx_isolation= (enum_tx_isolation) variables.tx_isolation;
260
 
  warn_list.clear();
261
267
  memset(warn_count, 0, sizeof(warn_count));
262
268
  memset(&status_var, 0, sizeof(status_var));
263
269
 
474
480
 
475
481
  plugin::Logging::postEndDo(this);
476
482
  plugin::EventObserver::deregisterSessionEvents(session_event_observers); 
477
 
 
478
 
  // Free all schema event observer lists.
479
 
  for (std::map<std::string, plugin::EventObserverList *>::iterator it=schema_event_observers.begin() ; it != schema_event_observers.end(); it++ )
480
 
    plugin::EventObserver::deregisterSchemaEvents(it->second);
481
483
 
 
484
        BOOST_FOREACH(impl_c::schema_event_observers_t::reference it, impl_->schema_event_observers)
 
485
    plugin::EventObserver::deregisterSchemaEvents(it.second);
482
486
}
483
487
 
484
488
void Session::setClient(plugin::Client *client_arg)
711
715
  return true;
712
716
}
713
717
 
714
 
bool Session::checkUser(const std::string &passwd_str,
715
 
                        const std::string &in_db)
 
718
bool Session::checkUser(const std::string &passwd_str, const std::string &in_db)
716
719
{
717
 
  bool is_authenticated=
718
 
    plugin::Authentication::isAuthenticated(*user(), passwd_str);
719
 
 
720
 
  if (is_authenticated != true)
 
720
  if (not plugin::Authentication::isAuthenticated(*user(), passwd_str))
721
721
  {
722
722
    status_var.access_denied++;
723
723
    /* isAuthenticated has pushed the error message */
725
725
  }
726
726
 
727
727
  /* Change database if necessary */
728
 
  if (not in_db.empty())
729
 
  {
730
 
    identifier::Schema identifier(in_db);
731
 
    if (schema::change(*this, identifier))
732
 
    {
733
 
      /* change_db() has pushed the error message. */
734
 
      return false;
735
 
    }
736
 
  }
 
728
  if (not in_db.empty() && schema::change(*this, identifier::Schema(in_db)))
 
729
    return false; // change() has pushed the error message
737
730
  my_ok();
738
 
  password= not passwd_str.empty();
739
731
 
740
732
  /* Ready to handle queries */
741
733
  return true;
743
735
 
744
736
bool Session::executeStatement()
745
737
{
 
738
  /*
 
739
    indicator of uninitialized lex => normal flow of errors handling
 
740
    (see my_message_sql)
 
741
  */
 
742
  lex().current_select= 0;
 
743
  clear_error();
 
744
  main_da().reset_diagnostics_area();
746
745
  char *l_packet= 0;
747
746
  uint32_t packet_length;
748
 
 
749
 
  enum enum_server_command l_command;
750
 
 
751
 
  /*
752
 
    indicator of uninitialized lex => normal flow of errors handling
753
 
    (see my_message_sql)
754
 
  */
755
 
  lex().current_select= 0;
756
 
  clear_error();
757
 
  main_da().reset_diagnostics_area();
758
 
 
759
 
  if (client->readCommand(&l_packet, &packet_length) == false)
760
 
  {
 
747
  if (not client->readCommand(&l_packet, &packet_length))
761
748
    return false;
762
 
  }
763
749
 
764
750
  if (getKilled() == KILL_CONNECTION)
765
751
    return false;
767
753
  if (packet_length == 0)
768
754
    return true;
769
755
 
770
 
  l_command= static_cast<enum_server_command>(l_packet[0]);
 
756
  enum_server_command l_command= static_cast<enum_server_command>(l_packet[0]);
771
757
 
772
758
  if (command >= COM_END)
773
759
    command= COM_END;                           // Wrong command
924
910
  _where= Session::DEFAULT_WHERE;
925
911
 
926
912
  /* Reset the temporary shares we built */
927
 
  for_each(temporary_shares.begin(),
928
 
           temporary_shares.end(),
929
 
           DeletePtr());
930
 
  temporary_shares.clear();
 
913
  for_each(impl_->temporary_shares.begin(), impl_->temporary_shares.end(), DeletePtr());
 
914
  impl_->temporary_shares.clear();
931
915
}
932
916
 
933
917
/**
2079
2063
  }
2080
2064
}
2081
2065
 
2082
 
table::Singular *Session::getInstanceTable()
 
2066
table::Singular& Session::getInstanceTable()
2083
2067
{
2084
 
  temporary_shares.push_back(new table::Singular()); // This will not go into the tableshare cache, so no key is used.
2085
 
 
2086
 
  table::Singular *tmp_share= temporary_shares.back();
2087
 
 
2088
 
  assert(tmp_share);
2089
 
 
2090
 
  return tmp_share;
 
2068
  impl_->temporary_shares.push_back(new table::Singular); // This will not go into the tableshare cache, so no key is used.
 
2069
  return *impl_->temporary_shares.back();
2091
2070
}
2092
2071
 
2093
2072
 
2109
2088
  @return
2110
2089
    0 if out of memory, Table object in case of success
2111
2090
*/
2112
 
table::Singular *Session::getInstanceTable(List<CreateField> &field_list)
 
2091
table::Singular& Session::getInstanceTable(std::list<CreateField>& field_list)
2113
2092
{
2114
 
  temporary_shares.push_back(new table::Singular(this, field_list)); // This will not go into the tableshare cache, so no key is used.
2115
 
  return temporary_shares.back();
 
2093
  impl_->temporary_shares.push_back(new table::Singular(this, field_list)); // This will not go into the tableshare cache, so no key is used.
 
2094
  return *impl_->temporary_shares.back();
2116
2095
}
2117
2096
 
2118
2097
void Session::clear_error(bool full)
2199
2178
  impl_->properties.setProperty(arg, value);
2200
2179
}
2201
2180
 
 
2181
plugin::EventObserverList* Session::getSchemaObservers(const std::string &db_name)
 
2182
{
 
2183
  if (impl_c::schema_event_observers_t::mapped_type* i= find_ptr(impl_->schema_event_observers, db_name))
 
2184
    return *i;
 
2185
  return NULL;
 
2186
}
 
2187
 
 
2188
plugin::EventObserverList* Session::setSchemaObservers(const std::string &db_name, plugin::EventObserverList* observers)
 
2189
{
 
2190
  impl_->schema_event_observers.erase(db_name);
 
2191
  if (observers)
 
2192
    impl_->schema_event_observers[db_name] = observers;
 
2193
        return observers;
 
2194
}
 
2195
my_xid Session::getTransactionId()
 
2196
{
 
2197
  return transaction.xid_state.xid.quick_get_my_xid();
 
2198
}
 
2199
 
2202
2200
const std::string& display::type(drizzled::Session::global_read_lock_t type)
2203
2201
{
2204
2202
  static const std::string NONE= "NONE";