~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Stewart Smith
  • Date: 2011-02-10 01:03:48 UTC
  • mto: (2154.1.2 build)
  • mto: This revision was merged to the branch mainline in revision 2155.
  • Revision ID: stewart@flamingspork.com-20110210010348-5l0zh0akjahvx3vi
fix Session::tx_isolation to be getTxIsolation to follow coding style, but look weird

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
 * @file Implementation of the Session class and API
22
22
 */
23
23
 
24
 
#include <config.h>
25
 
 
26
 
#include <drizzled/copy_field.h>
27
 
#include <drizzled/data_home.h>
28
 
#include <drizzled/display.h>
29
 
#include <drizzled/drizzled.h>
30
 
#include <drizzled/error.h>
31
 
#include <drizzled/gettext.h>
32
 
#include <drizzled/identifier.h>
33
 
#include <drizzled/internal/iocache.h>
34
 
#include <drizzled/internal/thread_var.h>
35
 
#include <drizzled/internal_error_handler.h>
36
 
#include <drizzled/item/cache.h>
37
 
#include <drizzled/item/empty_string.h>
38
 
#include <drizzled/item/float.h>
39
 
#include <drizzled/item/return_int.h>
40
 
#include <drizzled/lock.h>
41
 
#include <drizzled/plugin/authentication.h>
42
 
#include <drizzled/plugin/client.h>
43
 
#include <drizzled/plugin/event_observer.h>
44
 
#include <drizzled/plugin/logging.h>
45
 
#include <drizzled/plugin/query_rewrite.h>
46
 
#include <drizzled/plugin/scheduler.h>
47
 
#include <drizzled/plugin/transactional_storage_engine.h>
48
 
#include <drizzled/probes.h>
49
 
#include <drizzled/pthread_globals.h>
50
 
#include <drizzled/query_id.h>
51
 
#include <drizzled/refresh_version.h>
52
 
#include <drizzled/select_dump.h>
53
 
#include <drizzled/select_exists_subselect.h>
54
 
#include <drizzled/select_export.h>
55
 
#include <drizzled/select_max_min_finder_subselect.h>
56
 
#include <drizzled/select_singlerow_subselect.h>
57
 
#include <drizzled/select_subselect.h>
58
 
#include <drizzled/select_to_file.h>
59
 
#include <drizzled/session.h>
60
 
#include <drizzled/session/cache.h>
61
 
#include <drizzled/show.h>
62
 
#include <drizzled/sql_base.h>
63
 
#include <drizzled/table/singular.h>
64
 
#include <drizzled/table_proto.h>
65
 
#include <drizzled/tmp_table_param.h>
66
 
#include <drizzled/transaction_services.h>
67
 
#include <drizzled/user_var_entry.h>
68
 
#include <drizzled/util/functors.h>
69
 
#include <plugin/myisam/myisam.h>
70
 
 
 
24
#include "config.h"
 
25
#include "drizzled/session.h"
 
26
#include "drizzled/session/cache.h"
 
27
#include <sys/stat.h>
 
28
#include "drizzled/error.h"
 
29
#include "drizzled/gettext.h"
 
30
#include "drizzled/query_id.h"
 
31
#include "drizzled/data_home.h"
 
32
#include "drizzled/sql_base.h"
 
33
#include "drizzled/lock.h"
 
34
#include "drizzled/item/cache.h"
 
35
#include "drizzled/item/float.h"
 
36
#include "drizzled/item/return_int.h"
 
37
#include "drizzled/item/empty_string.h"
 
38
#include "drizzled/show.h"
 
39
#include "drizzled/plugin/client.h"
 
40
#include "drizzled/plugin/scheduler.h"
 
41
#include "drizzled/plugin/authentication.h"
 
42
#include "drizzled/plugin/logging.h"
 
43
#include "drizzled/plugin/transactional_storage_engine.h"
 
44
#include "drizzled/plugin/query_rewrite.h"
 
45
#include "drizzled/probes.h"
 
46
#include "drizzled/table_proto.h"
 
47
#include "drizzled/db.h"
 
48
#include "drizzled/pthread_globals.h"
 
49
#include "drizzled/transaction_services.h"
 
50
#include "drizzled/drizzled.h"
 
51
 
 
52
#include "drizzled/identifier.h"
 
53
 
 
54
#include "drizzled/table/singular.h"
 
55
 
 
56
#include "plugin/myisam/myisam.h"
 
57
#include "drizzled/internal/iocache.h"
 
58
#include "drizzled/internal/thread_var.h"
 
59
#include "drizzled/plugin/event_observer.h"
 
60
 
 
61
#include "drizzled/util/functors.h"
 
62
 
 
63
#include "drizzled/display.h"
 
64
 
 
65
#include <fcntl.h>
71
66
#include <algorithm>
72
67
#include <climits>
73
 
#include <fcntl.h>
74
 
#include <sys/stat.h>
75
68
 
76
69
#include <boost/filesystem.hpp>
77
70
#include <boost/checked_delete.hpp>
78
71
 
79
 
#include <drizzled/util/backtrace.h>
80
 
 
81
 
#include <drizzled/schema.h>
 
72
#include "drizzled/util/backtrace.h"
82
73
 
83
74
using namespace std;
84
75
 
237
228
  open_options=ha_open_options;
238
229
  update_lock_default= TL_WRITE;
239
230
  session_tx_isolation= (enum_tx_isolation) variables.tx_isolation;
240
 
  warn_list.clear();
 
231
  warn_list.empty();
241
232
  memset(warn_count, 0, sizeof(warn_count));
242
233
  memset(&status_var, 0, sizeof(status_var));
243
234
 
311
302
  m_internal_handler= NULL;
312
303
}
313
304
 
314
 
void Session::get_xid(DrizzleXid *xid)
 
305
void Session::get_xid(DRIZZLE_XID *xid)
315
306
{
316
 
  *xid = *(DrizzleXid *) &transaction.xid_state.xid;
 
307
  *xid = *(DRIZZLE_XID *) &transaction.xid_state.xid;
317
308
}
318
309
 
319
310
/* Do operations that may take a long time */
397
388
 
398
389
  plugin::Logging::postEndDo(this);
399
390
  plugin::EventObserver::deregisterSessionEvents(*this); 
 
391
 
 
392
  for (PropertyMap::iterator iter= life_properties.begin(); iter != life_properties.end(); iter++)
 
393
  {
 
394
    boost::checked_delete((*iter).second);
 
395
  }
 
396
  life_properties.clear();
400
397
}
401
398
 
402
399
void Session::setClient(plugin::Client *client_arg)
592
589
*/
593
590
bool Session::isViewable(identifier::User::const_reference user_arg) const
594
591
{
595
 
  return plugin::Authorization::isAuthorized(user_arg, *this, false);
 
592
  return plugin::Authorization::isAuthorized(user_arg, this, false);
596
593
}
597
594
 
598
595
 
635
632
                        const std::string &in_db)
636
633
{
637
634
  bool is_authenticated=
638
 
    plugin::Authentication::isAuthenticated(*user(), passwd_str);
 
635
    plugin::Authentication::isAuthenticated(user(), passwd_str);
639
636
 
640
637
  if (is_authenticated != true)
641
638
  {
648
645
  if (not in_db.empty())
649
646
  {
650
647
    identifier::Schema identifier(in_db);
651
 
    if (schema::change(*this, identifier))
 
648
    if (change_db(this, identifier))
652
649
    {
653
650
      /* change_db() has pushed the error message. */
654
651
      return false;
718
715
    plugin::QueryRewriter::rewriteQuery(*_schema, *new_query);
719
716
  }
720
717
  query.reset(new_query);
721
 
  _state.reset(new session::State(in_packet, in_packet_length));
 
718
  _state.reset(new State(in_packet, in_packet_length));
722
719
 
723
720
  return true;
724
721
}
808
805
{
809
806
  bool result= true;
810
807
 
811
 
  assert(! inTransaction());
812
 
 
813
 
  options|= OPTION_BEGIN;
814
 
  server_status|= SERVER_STATUS_IN_TRANS;
815
 
 
816
 
  if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
 
808
  if (! endActiveTransaction())
817
809
  {
818
810
    result= false;
819
811
  }
 
812
  else
 
813
  {
 
814
    options|= OPTION_BEGIN;
 
815
    server_status|= SERVER_STATUS_IN_TRANS;
 
816
 
 
817
    if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
 
818
    {
 
819
      result= false;
 
820
    }
 
821
  }
820
822
 
821
823
  return result;
822
824
}
876
878
                                     bool allocate_lex_string)
877
879
{
878
880
  if (allocate_lex_string)
879
 
    if (!(lex_str= (LEX_STRING *)getMemRoot()->allocate(sizeof(LEX_STRING))))
 
881
    if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING))))
880
882
      return 0;
881
883
  if (!(lex_str->str= mem_root->strmake_root(str, length)))
882
884
    return 0;
1090
1092
 
1091
1093
  /* Check if there is any blobs in data */
1092
1094
  {
1093
 
    List<Item>::iterator li(list.begin());
 
1095
    List_iterator_fast<Item> li(list);
1094
1096
    Item *item;
1095
1097
    while ((item=li++))
1096
1098
    {
1155
1157
  row_count++;
1156
1158
  Item *item;
1157
1159
  uint32_t used_length=0,items_left=items.elements;
1158
 
  List<Item>::iterator li(items.begin());
 
1160
  List_iterator_fast<Item> li(items);
1159
1161
 
1160
1162
  if (my_b_write(cache,(unsigned char*) exchange->line_start->ptr(),
1161
1163
                 exchange->line_start->length()))
1344
1346
 
1345
1347
bool select_dump::send_data(List<Item> &items)
1346
1348
{
1347
 
  List<Item>::iterator li(items.begin());
 
1349
  List_iterator_fast<Item> li(items);
1348
1350
  char buff[MAX_FIELD_WIDTH];
1349
1351
  String tmp(buff,sizeof(buff),&my_charset_bin),*res;
1350
1352
  tmp.length(0);
1397
1399
    unit->offset_limit_cnt--;
1398
1400
    return(0);
1399
1401
  }
1400
 
  List<Item>::iterator li(items.begin());
 
1402
  List_iterator_fast<Item> li(items);
1401
1403
  Item *val_item;
1402
1404
  for (uint32_t i= 0; (val_item= li++); i++)
1403
1405
    it->store(i, val_item);
1415
1417
bool select_max_min_finder_subselect::send_data(List<Item> &items)
1416
1418
{
1417
1419
  Item_maxmin_subselect *it= (Item_maxmin_subselect *)item;
1418
 
  List<Item>::iterator li(items.begin());
 
1420
  List_iterator_fast<Item> li(items);
1419
1421
  Item *val_item= li++;
1420
1422
  it->register_value();
1421
1423
  if (it->assigned())
1617
1619
  @param  session   Thread handle
1618
1620
  @param  all   true <=> rollback main transaction.
1619
1621
*/
1620
 
void Session::markTransactionForRollback(bool all)
 
1622
void mark_transaction_to_rollback(Session *session, bool all)
1621
1623
{
1622
 
  is_fatal_sub_stmt_error= true;
1623
 
  transaction_rollback_request= all;
 
1624
  if (session)
 
1625
  {
 
1626
    session->is_fatal_sub_stmt_error= true;
 
1627
    session->transaction_rollback_request= all;
 
1628
  }
1624
1629
}
1625
1630
 
1626
1631
void Session::disconnect(enum error_t errcode)
2012
2017
  }
2013
2018
}
2014
2019
 
 
2020
bool Session::TableMessages::storeTableMessage(const identifier::Table &identifier, message::Table &table_message)
 
2021
{
 
2022
  table_message_cache.insert(make_pair(identifier.getPath(), table_message));
 
2023
 
 
2024
  return true;
 
2025
}
 
2026
 
 
2027
bool Session::TableMessages::removeTableMessage(const identifier::Table &identifier)
 
2028
{
 
2029
  TableMessageCache::iterator iter;
 
2030
 
 
2031
  iter= table_message_cache.find(identifier.getPath());
 
2032
 
 
2033
  if (iter == table_message_cache.end())
 
2034
    return false;
 
2035
 
 
2036
  table_message_cache.erase(iter);
 
2037
 
 
2038
  return true;
 
2039
}
 
2040
 
 
2041
bool Session::TableMessages::getTableMessage(const identifier::Table &identifier, message::Table &table_message)
 
2042
{
 
2043
  TableMessageCache::iterator iter;
 
2044
 
 
2045
  iter= table_message_cache.find(identifier.getPath());
 
2046
 
 
2047
  if (iter == table_message_cache.end())
 
2048
    return false;
 
2049
 
 
2050
  table_message.CopyFrom(((*iter).second));
 
2051
 
 
2052
  return true;
 
2053
}
 
2054
 
 
2055
bool Session::TableMessages::doesTableMessageExist(const identifier::Table &identifier)
 
2056
{
 
2057
  TableMessageCache::iterator iter;
 
2058
 
 
2059
  iter= table_message_cache.find(identifier.getPath());
 
2060
 
 
2061
  if (iter == table_message_cache.end())
 
2062
  {
 
2063
    return false;
 
2064
  }
 
2065
 
 
2066
  return true;
 
2067
}
 
2068
 
 
2069
bool Session::TableMessages::renameTableMessage(const identifier::Table &from, const identifier::Table &to)
 
2070
{
 
2071
  TableMessageCache::iterator iter;
 
2072
 
 
2073
  table_message_cache[to.getPath()]= table_message_cache[from.getPath()];
 
2074
 
 
2075
  iter= table_message_cache.find(to.getPath());
 
2076
 
 
2077
  if (iter == table_message_cache.end())
 
2078
  {
 
2079
    return false;
 
2080
  }
 
2081
 
 
2082
  (*iter).second.set_schema(to.getSchemaName());
 
2083
  (*iter).second.set_name(to.getTableName());
 
2084
 
 
2085
  return true;
 
2086
}
 
2087
 
2015
2088
table::Singular *Session::getInstanceTable()
2016
2089
{
2017
2090
  temporary_shares.push_back(new table::Singular()); // This will not go into the tableshare cache, so no key is used.