~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Monty Taylor
  • Date: 2010-12-27 19:58:09 UTC
  • mto: This revision was merged to the branch mainline in revision 2038.
  • Revision ID: mordred@inaugust.com-20101227195809-1k7a4ge19l3u1o1h
Updated pandora-build files to version 0.171

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
 */
23
23
 
24
24
#include "config.h"
25
 
 
26
 
#include <drizzled/copy_field.h>
27
25
#include "drizzled/session.h"
28
26
#include "drizzled/session/cache.h"
 
27
#include <sys/stat.h>
29
28
#include "drizzled/error.h"
30
29
#include "drizzled/gettext.h"
31
30
#include "drizzled/query_id.h"
52
51
 
53
52
#include "drizzled/identifier.h"
54
53
 
55
 
#include <drizzled/refresh_version.h>
56
 
 
57
 
#include "drizzled/table/singular.h"
 
54
#include "drizzled/table/instance.h"
58
55
 
59
56
#include "plugin/myisam/myisam.h"
60
57
#include "drizzled/internal/iocache.h"
65
62
 
66
63
#include "drizzled/display.h"
67
64
 
 
65
#include <fcntl.h>
68
66
#include <algorithm>
69
67
#include <climits>
70
 
#include <fcntl.h>
71
 
#include <sys/stat.h>
72
 
 
73
68
#include <boost/filesystem.hpp>
74
 
#include <boost/checked_delete.hpp>
75
69
 
76
70
#include "drizzled/util/backtrace.h"
77
71
 
118
112
  return fd;
119
113
}
120
114
 
 
115
int session_tablespace_op(const Session *session)
 
116
{
 
117
  return test(session->tablespace_op);
 
118
}
 
119
 
 
120
/**
 
121
   Set the process info field of the Session structure.
 
122
 
 
123
   This function is used by plug-ins. Internally, the
 
124
   Session::set_proc_info() function should be used.
 
125
 
 
126
   @see Session::set_proc_info
 
127
 */
 
128
void set_session_proc_info(Session *session, const char *info)
 
129
{
 
130
  session->set_proc_info(info);
 
131
}
 
132
 
 
133
const char *get_session_proc_info(Session *session)
 
134
{
 
135
  return session->get_proc_info();
 
136
}
 
137
 
121
138
void **Session::getEngineData(const plugin::MonitoredInTransaction *monitored)
122
139
{
123
140
  return static_cast<void **>(&ha_data[monitored->getId()].ha_ptr);
134
151
  return session->options & test_options;
135
152
}
136
153
 
137
 
Session::Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog_arg) :
 
154
int session_sql_command(const Session *session)
 
155
{
 
156
  return (int) session->lex->sql_command;
 
157
}
 
158
 
 
159
enum_tx_isolation session_tx_isolation(const Session *session)
 
160
{
 
161
  return (enum_tx_isolation)session->variables.tx_isolation;
 
162
}
 
163
 
 
164
Session::Session(plugin::Client *client_arg) :
138
165
  Open_tables_state(refresh_version),
139
166
  mem_root(&main_mem_root),
140
167
  xa_id(0),
141
168
  lex(&main_lex),
142
169
  query(new std::string),
143
170
  _schema(new std::string("")),
 
171
  catalog("LOCAL"),
144
172
  client(client_arg),
145
173
  scheduler(NULL),
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),
151
 
  dbug_sentry(Session_SENTRY_MAGIC),
152
 
  mysys_var(0),
153
 
  command(COM_CONNECT),
154
 
  file_id(0),
155
 
  _epoch(boost::gregorian::date(1970,1,1)),
156
 
  _connect_time(boost::posix_time::microsec_clock::universal_time()),
157
 
  utime_after_lock(0),
 
178
  user_time(0),
158
179
  ha_data(plugin::num_trx_monitored_objects),
159
 
  query_id(0),
160
 
  warn_query_id(0),
161
180
  concurrent_execute_allowed(true),
162
181
  arg_of_last_insert_id_function(false),
163
182
  first_successful_insert_id_in_prev_stmt(0),
164
183
  first_successful_insert_id_in_cur_stmt(0),
165
184
  limit_found_rows(0),
166
 
  options(session_startup_options),
167
 
  row_count_func(-1),
168
 
  sent_row_count(0),
169
 
  examined_row_count(0),
170
 
  used_tables(0),
171
 
  total_warn_count(0),
172
 
  col_access(0),
173
 
  statement_id_counter(0),
174
 
  row_count(0),
175
 
  thread_id(0),
176
 
  tmp_table(0),
177
185
  _global_read_lock(NONE),
178
 
  count_cuted_fields(CHECK_FIELD_ERROR_FOR_NULL),
179
186
  _killed(NOT_KILLED),
180
187
  some_tables_deleted(false),
181
188
  no_errors(false),
183
190
  is_fatal_error(false),
184
191
  transaction_rollback_request(false),
185
192
  is_fatal_sub_stmt_error(0),
 
193
  derived_tables_processing(false),
186
194
  tablespace_op(false),
187
 
  derived_tables_processing(false),
188
195
  m_lip(NULL),
189
196
  cached_table(0),
190
197
  transaction_message(NULL),
191
198
  statement_message(NULL),
192
199
  session_event_observers(NULL),
193
 
  _catalog(catalog_arg),
194
200
  use_usage(false)
195
201
{
196
202
  client->setSession(this);
201
207
    will be re-initialized in init_for_queries().
202
208
  */
203
209
  memory::init_sql_alloc(&main_mem_root, memory::ROOT_MIN_BLOCK_SIZE, 0);
 
210
  count_cuted_fields= CHECK_FIELD_ERROR_FOR_NULL;
 
211
  col_access= 0;
 
212
  tmp_table= 0;
 
213
  used_tables= 0;
204
214
  cuted_fields= sent_row_count= row_count= 0L;
 
215
  row_count_func= -1;
 
216
  statement_id_counter= 0UL;
205
217
  // Must be reset to handle error with Session's created for init of mysqld
206
218
  lex->current_select= 0;
 
219
  start_time=(time_t) 0;
 
220
  start_utime= 0L;
 
221
  utime_after_lock= 0L;
207
222
  memset(&variables, 0, sizeof(variables));
 
223
  thread_id= 0;
 
224
  file_id = 0;
 
225
  query_id= 0;
 
226
  warn_query_id= 0;
 
227
  mysys_var= 0;
208
228
  scoreboard_index= -1;
 
229
  dbug_sentry=Session_SENTRY_MAGIC;
209
230
  cleanup_done= abort_on_warning= no_warnings_for_error= false;  
210
231
 
211
232
  /* query_cache init */
214
235
 
215
236
  /* Variables with default values */
216
237
  proc_info="login";
 
238
  where= Session::DEFAULT_WHERE;
 
239
  command= COM_CONNECT;
217
240
 
218
241
  plugin_sessionvar_init(this);
219
242
  /*
223
246
  */
224
247
  variables.pseudo_thread_id= thread_id;
225
248
  server_status= SERVER_STATUS_AUTOCOMMIT;
 
249
  options= session_startup_options;
226
250
 
227
251
  if (variables.max_join_size == HA_POS_ERROR)
228
252
    options |= OPTION_BIG_SELECTS;
234
258
  session_tx_isolation= (enum_tx_isolation) variables.tx_isolation;
235
259
  warn_list.empty();
236
260
  memset(warn_count, 0, sizeof(warn_count));
 
261
  total_warn_count= 0;
237
262
  memset(&status_var, 0, sizeof(status_var));
238
263
 
239
264
  /* Initialize sub structures */
269
294
  m_internal_handler= handler;
270
295
}
271
296
 
272
 
bool Session::handle_error(drizzled::error_t sql_errno, const char *message,
273
 
                           DRIZZLE_ERROR::enum_warning_level level)
 
297
bool Session::handle_error(uint32_t sql_errno, const char *message,
 
298
                       DRIZZLE_ERROR::enum_warning_level level)
274
299
{
275
300
  if (m_internal_handler)
276
301
  {
326
351
#endif
327
352
  {
328
353
    TransactionServices &transaction_services= TransactionServices::singleton();
329
 
    transaction_services.rollbackTransaction(*this, true);
 
354
    transaction_services.rollbackTransaction(this, true);
330
355
    xid_cache_delete(&transaction.xid_state);
331
356
  }
332
357
 
335
360
       iter++)
336
361
  {
337
362
    user_var_entry *entry= (*iter).second;
338
 
    boost::checked_delete(entry);
 
363
    delete entry;
339
364
  }
340
365
  user_vars.clear();
341
366
 
359
384
    assert(security_ctx);
360
385
    if (global_system_variables.log_warnings)
361
386
    {
362
 
      errmsg_printf(error::WARN, ER(ER_FORCING_CLOSE),
 
387
      errmsg_printf(ERRMSG_LVL_WARN, ER(ER_FORCING_CLOSE),
363
388
                    internal::my_progname,
364
389
                    thread_id,
365
390
                    security_ctx->username().c_str());
372
397
  if (client)
373
398
  {
374
399
    client->close();
375
 
    boost::checked_delete(client);
376
 
    client= NULL;
 
400
    delete client;
377
401
  }
378
402
 
379
403
  if (cleanup_done == false)
392
416
 
393
417
  plugin::Logging::postEndDo(this);
394
418
  plugin::EventObserver::deregisterSessionEvents(*this); 
 
419
 
 
420
  for (PropertyMap::iterator iter= life_properties.begin(); iter != life_properties.end(); iter++)
 
421
  {
 
422
    delete (*iter).second;
 
423
  }
 
424
  life_properties.clear();
395
425
}
396
426
 
397
427
void Session::setClient(plugin::Client *client_arg)
541
571
  arg->scheduler= plugin::Scheduler::getScheduler();
542
572
  assert(arg->scheduler);
543
573
 
544
 
  ++connection_count;
545
 
 
546
 
  long current_connections= connection_count;
547
 
 
548
 
  if (current_connections > 0 and static_cast<uint64_t>(current_connections) > current_global_counters.max_used_connections)
 
574
  connection_count.increment();
 
575
 
 
576
  if (connection_count > current_global_counters.max_used_connections)
549
577
  {
550
 
    current_global_counters.max_used_connections= static_cast<uint64_t>(connection_count);
 
578
    current_global_counters.max_used_connections= connection_count;
551
579
  }
552
580
 
553
581
  current_global_counters.connections++;
618
646
 
619
647
bool Session::authenticate()
620
648
{
 
649
  lex->start(this);
621
650
  if (client->authenticate())
622
651
    return false;
623
652
 
642
671
  /* Change database if necessary */
643
672
  if (not in_db.empty())
644
673
  {
645
 
    identifier::Schema identifier(in_db);
 
674
    SchemaIdentifier identifier(in_db);
646
675
    if (change_db(this, identifier))
647
676
    {
648
677
      /* change_db() has pushed the error message. */
713
742
    plugin::QueryRewriter::rewriteQuery(*_schema, *new_query);
714
743
  }
715
744
  query.reset(new_query);
716
 
  _state.reset(new session::State(in_packet, in_packet_length));
 
745
  _state.reset(new State(in_packet, in_packet_length));
717
746
 
718
747
  return true;
719
748
}
738
767
       * (Which of course should never happen...)
739
768
       */
740
769
      server_status&= ~SERVER_STATUS_IN_TRANS;
741
 
      if (transaction_services.commitTransaction(*this, true))
 
770
      if (transaction_services.commitTransaction(this, true))
742
771
        result= false;
743
772
      options&= ~(OPTION_BEGIN);
744
773
      break;
755
784
    case ROLLBACK_AND_CHAIN:
756
785
    {
757
786
      server_status&= ~SERVER_STATUS_IN_TRANS;
758
 
      if (transaction_services.rollbackTransaction(*this, true))
 
787
      if (transaction_services.rollbackTransaction(this, true))
759
788
        result= false;
760
789
      options&= ~(OPTION_BEGIN);
761
790
      if (result == true && (completion == ROLLBACK_AND_CHAIN))
769
798
 
770
799
  if (result == false)
771
800
  {
772
 
    my_error(static_cast<drizzled::error_t>(killed_errno()), MYF(0));
 
801
    my_error(killed_errno(), MYF(0));
773
802
  }
774
803
  else if ((result == true) && do_release)
775
804
  {
792
821
  if (options & (OPTION_NOT_AUTOCOMMIT | OPTION_BEGIN))
793
822
  {
794
823
    server_status&= ~SERVER_STATUS_IN_TRANS;
795
 
    if (transaction_services.commitTransaction(*this, true))
 
824
    if (transaction_services.commitTransaction(this, true))
796
825
      result= false;
797
826
  }
798
827
  options&= ~(OPTION_BEGIN);
803
832
{
804
833
  bool result= true;
805
834
 
806
 
  assert(! inTransaction());
807
 
 
808
 
  options|= OPTION_BEGIN;
809
 
  server_status|= SERVER_STATUS_IN_TRANS;
810
 
 
811
 
  if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
 
835
  if (! endActiveTransaction())
812
836
  {
813
837
    result= false;
814
838
  }
 
839
  else
 
840
  {
 
841
    options|= OPTION_BEGIN;
 
842
    server_status|= SERVER_STATUS_IN_TRANS;
 
843
 
 
844
    if (plugin::TransactionalStorageEngine::notifyStartTransaction(this, opt))
 
845
    {
 
846
      result= false;
 
847
    }
 
848
  }
815
849
 
816
850
  return result;
817
851
}
833
867
    first_successful_insert_id_in_cur_stmt= 0;
834
868
    substitute_null_with_insert_id= true;
835
869
  }
836
 
 
837
870
  arg_of_last_insert_id_function= false;
838
 
 
839
871
  /* Free Items that were created during this execution */
840
872
  free_items();
841
 
 
842
 
  /* Reset _where. */
843
 
  _where= Session::DEFAULT_WHERE;
 
873
  /* Reset where. */
 
874
  where= Session::DEFAULT_WHERE;
844
875
 
845
876
  /* Reset the temporary shares we built */
846
877
  for_each(temporary_shares.begin(),
871
902
                                     bool allocate_lex_string)
872
903
{
873
904
  if (allocate_lex_string)
874
 
    if (!(lex_str= (LEX_STRING *)getMemRoot()->allocate(sizeof(LEX_STRING))))
 
905
    if (!(lex_str= (LEX_STRING *)alloc(sizeof(LEX_STRING))))
875
906
      return 0;
876
907
  if (!(lex_str->str= mem_root->strmake_root(str, length)))
877
908
    return 0;
917
948
  return (result->send_fields(field_list));
918
949
}
919
950
 
920
 
void select_result::send_error(drizzled::error_t errcode, const char *err)
 
951
void select_result::send_error(uint32_t errcode, const char *err)
921
952
{
922
953
  my_message(errcode, err, MYF(0));
923
954
}
926
957
  Handling writing to file
927
958
************************************************************************/
928
959
 
929
 
void select_to_file::send_error(drizzled::error_t errcode,const char *err)
 
960
void select_to_file::send_error(uint32_t errcode,const char *err)
930
961
{
931
962
  my_message(errcode, err, MYF(0));
932
963
  if (file > 0)
1574
1605
  /* Fix for Intel compiler */
1575
1606
  if (copy_field)
1576
1607
  {
1577
 
    boost::checked_array_delete(copy_field);
1578
 
    save_copy_field= save_copy_field_end= copy_field= copy_field_end= 0;
 
1608
    delete [] copy_field;
 
1609
    save_copy_field= copy_field= 0;
1579
1610
  }
1580
1611
}
1581
1612
 
1582
1613
void Session::send_kill_message() const
1583
1614
{
1584
 
  drizzled::error_t err= static_cast<drizzled::error_t>(killed_errno());
1585
 
  if (err != EE_OK)
 
1615
  int err= killed_errno();
 
1616
  if (err)
1586
1617
    my_message(err, ER(err), MYF(0));
1587
1618
}
1588
1619
 
1612
1643
  @param  session   Thread handle
1613
1644
  @param  all   true <=> rollback main transaction.
1614
1645
*/
1615
 
void Session::markTransactionForRollback(bool all)
 
1646
void mark_transaction_to_rollback(Session *session, bool all)
1616
1647
{
1617
 
  is_fatal_sub_stmt_error= true;
1618
 
  transaction_rollback_request= all;
 
1648
  if (session)
 
1649
  {
 
1650
    session->is_fatal_sub_stmt_error= true;
 
1651
    session->transaction_rollback_request= all;
 
1652
  }
1619
1653
}
1620
1654
 
1621
 
void Session::disconnect(enum error_t errcode)
 
1655
void Session::disconnect(enum drizzled_error_code errcode)
1622
1656
{
1623
1657
  /* Allow any plugins to cleanup their session variables */
1624
1658
  plugin_sessionvar_cleanup(this);
1633
1667
  {
1634
1668
    if (not getKilled() && variables.log_warnings > 1)
1635
1669
    {
1636
 
      errmsg_printf(error::WARN, ER(ER_NEW_ABORTING_CONNECTION)
 
1670
      errmsg_printf(ERRMSG_LVL_WARN, ER(ER_NEW_ABORTING_CONNECTION)
1637
1671
                  , thread_id
1638
1672
                  , (_schema->empty() ? "unconnected" : _schema->c_str())
1639
1673
                  , security_ctx->username().empty() == false ? security_ctx->username().c_str() : "unauthenticated"
1743
1777
  table->free_io_cache();
1744
1778
  table->delete_table();
1745
1779
 
1746
 
  identifier::Table identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), table->getShare()->getPath());
 
1780
  TableIdentifier identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), table->getShare()->getPath());
1747
1781
  rm_temporary_table(table_type, identifier);
1748
1782
 
1749
 
  boost::checked_delete(table->getMutableShare());
 
1783
  delete table->getMutableShare();
1750
1784
 
1751
 
  boost::checked_delete(table);
 
1785
  /* This makes me sad, but we're allocating it via malloc */
 
1786
  delete table;
1752
1787
}
1753
1788
 
1754
1789
/** Clear most status variables. */
1771
1806
 
1772
1807
user_var_entry *Session::getVariable(const std::string  &name, bool create_if_not_exists)
1773
1808
{
1774
 
  if (cleanup_done)
1775
 
    return NULL;
 
1809
  UserVarsRange ppp= user_vars.equal_range(name);
1776
1810
 
1777
 
  UserVars::iterator iter= user_vars.find(name);
1778
 
  if (iter != user_vars.end())
 
1811
  for (UserVars::iterator iter= ppp.first;
 
1812
       iter != ppp.second; ++iter)
 
1813
  {
1779
1814
    return (*iter).second;
 
1815
  }
1780
1816
 
1781
1817
  if (not create_if_not_exists)
1782
1818
    return NULL;
1791
1827
 
1792
1828
  if (not returnable.second)
1793
1829
  {
1794
 
    boost::checked_delete(entry);
 
1830
    delete entry;
1795
1831
  }
1796
1832
 
1797
1833
  return entry;
1800
1836
void Session::setVariable(const std::string &name, const std::string &value)
1801
1837
{
1802
1838
  user_var_entry *updateable_var= getVariable(name.c_str(), true);
1803
 
  if (updateable_var)
1804
 
  {
1805
 
    updateable_var->update_hash(false,
1806
 
                                (void*)value.c_str(),
1807
 
                                static_cast<uint32_t>(value.length()), STRING_RESULT,
1808
 
                                &my_charset_bin,
1809
 
                                DERIVATION_IMPLICIT, false);
1810
 
  }
 
1839
 
 
1840
  updateable_var->update_hash(false,
 
1841
                              (void*)value.c_str(),
 
1842
                              static_cast<uint32_t>(value.length()), STRING_RESULT,
 
1843
                              &my_charset_bin,
 
1844
                              DERIVATION_IMPLICIT, false);
1811
1845
}
1812
1846
 
1813
1847
void Open_tables_state::mark_temp_tables_as_free_for_reuse()
1862
1896
  {
1863
1897
    TransactionServices &transaction_services= TransactionServices::singleton();
1864
1898
    main_da.can_overwrite_status= true;
1865
 
    transaction_services.autocommitOrRollback(*this, is_error());
 
1899
    transaction_services.autocommitOrRollback(this, is_error());
1866
1900
    main_da.can_overwrite_status= false;
1867
1901
    transaction.stmt.reset();
1868
1902
  }
1918
1952
 
1919
1953
    if (not lock_tables(tables, counter, &need_reopen))
1920
1954
      break;
1921
 
 
1922
1955
    if (not need_reopen)
1923
1956
      return true;
1924
 
 
1925
1957
    close_tables_for_reopen(&tables);
1926
1958
  }
1927
 
 
1928
 
  if ((handle_derived(lex, &derived_prepare) || (handle_derived(lex, &derived_filling))))
 
1959
  if ((handle_derived(lex, &derived_prepare) ||
 
1960
       (
 
1961
        handle_derived(lex, &derived_filling))))
1929
1962
    return true;
1930
1963
 
1931
1964
  return false;
1937
1970
  might be an issue (lame engines).
1938
1971
*/
1939
1972
 
1940
 
bool Open_tables_state::rm_temporary_table(const identifier::Table &identifier, bool best_effort)
 
1973
bool Open_tables_state::rm_temporary_table(const TableIdentifier &identifier, bool best_effort)
1941
1974
{
1942
 
  if (not plugin::StorageEngine::dropTable(*static_cast<Session *>(this), identifier))
 
1975
  if (plugin::StorageEngine::dropTable(*static_cast<Session *>(this), identifier))
1943
1976
  {
1944
1977
    if (not best_effort)
1945
1978
    {
1946
1979
      std::string path;
1947
1980
      identifier.getSQLPath(path);
1948
 
      errmsg_printf(error::WARN, _("Could not remove temporary table: '%s', error: %d"),
 
1981
      errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
1949
1982
                    path.c_str(), errno);
1950
1983
    }
1951
1984
 
1955
1988
  return false;
1956
1989
}
1957
1990
 
1958
 
bool Open_tables_state::rm_temporary_table(plugin::StorageEngine *base, const identifier::Table &identifier)
 
1991
bool Open_tables_state::rm_temporary_table(plugin::StorageEngine *base, const TableIdentifier &identifier)
1959
1992
{
1960
 
  drizzled::error_t error;
1961
1993
  assert(base);
1962
1994
 
1963
 
  if (not plugin::StorageEngine::dropTable(*static_cast<Session *>(this), *base, identifier, error))
 
1995
  if (plugin::StorageEngine::dropTable(*static_cast<Session *>(this), *base, identifier))
1964
1996
  {
1965
1997
    std::string path;
1966
1998
    identifier.getSQLPath(path);
1967
 
    errmsg_printf(error::WARN, _("Could not remove temporary table: '%s', error: %d"),
1968
 
                  path.c_str(), error);
 
1999
    errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
 
2000
                  path.c_str(), errno);
1969
2001
 
1970
2002
    return true;
1971
2003
  }
1989
2021
  {
1990
2022
    bool have_proto= false;
1991
2023
 
1992
 
    message::Table *proto= table->getShare()->getTableMessage();
1993
 
    if (table->getShare()->getTableMessage())
 
2024
    message::Table *proto= table->getShare()->getTableProto();
 
2025
    if (table->getShare()->getTableProto())
1994
2026
      have_proto= true;
1995
2027
 
1996
2028
    const char *answer= have_proto ? "true" : "false";
2007
2039
  }
2008
2040
}
2009
2041
 
2010
 
table::Singular *Session::getInstanceTable()
2011
 
{
2012
 
  temporary_shares.push_back(new table::Singular()); // This will not go into the tableshare cache, so no key is used.
2013
 
 
2014
 
  table::Singular *tmp_share= temporary_shares.back();
 
2042
bool Session::TableMessages::storeTableMessage(const TableIdentifier &identifier, message::Table &table_message)
 
2043
{
 
2044
  table_message_cache.insert(make_pair(identifier.getPath(), table_message));
 
2045
 
 
2046
  return true;
 
2047
}
 
2048
 
 
2049
bool Session::TableMessages::removeTableMessage(const TableIdentifier &identifier)
 
2050
{
 
2051
  TableMessageCache::iterator iter;
 
2052
 
 
2053
  iter= table_message_cache.find(identifier.getPath());
 
2054
 
 
2055
  if (iter == table_message_cache.end())
 
2056
    return false;
 
2057
 
 
2058
  table_message_cache.erase(iter);
 
2059
 
 
2060
  return true;
 
2061
}
 
2062
 
 
2063
bool Session::TableMessages::getTableMessage(const TableIdentifier &identifier, message::Table &table_message)
 
2064
{
 
2065
  TableMessageCache::iterator iter;
 
2066
 
 
2067
  iter= table_message_cache.find(identifier.getPath());
 
2068
 
 
2069
  if (iter == table_message_cache.end())
 
2070
    return false;
 
2071
 
 
2072
  table_message.CopyFrom(((*iter).second));
 
2073
 
 
2074
  return true;
 
2075
}
 
2076
 
 
2077
bool Session::TableMessages::doesTableMessageExist(const TableIdentifier &identifier)
 
2078
{
 
2079
  TableMessageCache::iterator iter;
 
2080
 
 
2081
  iter= table_message_cache.find(identifier.getPath());
 
2082
 
 
2083
  if (iter == table_message_cache.end())
 
2084
  {
 
2085
    return false;
 
2086
  }
 
2087
 
 
2088
  return true;
 
2089
}
 
2090
 
 
2091
bool Session::TableMessages::renameTableMessage(const TableIdentifier &from, const TableIdentifier &to)
 
2092
{
 
2093
  TableMessageCache::iterator iter;
 
2094
 
 
2095
  table_message_cache[to.getPath()]= table_message_cache[from.getPath()];
 
2096
 
 
2097
  iter= table_message_cache.find(to.getPath());
 
2098
 
 
2099
  if (iter == table_message_cache.end())
 
2100
  {
 
2101
    return false;
 
2102
  }
 
2103
 
 
2104
  (*iter).second.set_schema(to.getSchemaName());
 
2105
  (*iter).second.set_name(to.getTableName());
 
2106
 
 
2107
  return true;
 
2108
}
 
2109
 
 
2110
table::Instance *Session::getInstanceTable()
 
2111
{
 
2112
  temporary_shares.push_back(new table::Instance()); // This will not go into the tableshare cache, so no key is used.
 
2113
 
 
2114
  table::Instance *tmp_share= temporary_shares.back();
2015
2115
 
2016
2116
  assert(tmp_share);
2017
2117
 
2037
2137
  @return
2038
2138
    0 if out of memory, Table object in case of success
2039
2139
*/
2040
 
table::Singular *Session::getInstanceTable(List<CreateField> &field_list)
 
2140
table::Instance *Session::getInstanceTable(List<CreateField> &field_list)
2041
2141
{
2042
 
  temporary_shares.push_back(new table::Singular(this, field_list)); // This will not go into the tableshare cache, so no key is used.
 
2142
  temporary_shares.push_back(new table::Instance(this, field_list)); // This will not go into the tableshare cache, so no key is used.
2043
2143
 
2044
 
  table::Singular *tmp_share= temporary_shares.back();
 
2144
  table::Instance *tmp_share= temporary_shares.back();
2045
2145
 
2046
2146
  assert(tmp_share);
2047
2147