~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Brian Aker
  • Date: 2011-01-18 07:21:16 UTC
  • mfrom: (2079.3.3 session-fix)
  • Revision ID: brian@tangent.org-20110118072116-nuflltzguzhq9rgg
Merge in update so that test-run.pl runs all of test/suite and fix for
create table like and FK.

Show diffs side-by-side

added added

removed removed

Lines of Context:
51
51
 
52
52
#include "drizzled/identifier.h"
53
53
 
54
 
#include "drizzled/table/instance.h"
 
54
#include "drizzled/table/singular.h"
55
55
 
56
56
#include "plugin/myisam/myisam.h"
57
57
#include "drizzled/internal/iocache.h"
65
65
#include <fcntl.h>
66
66
#include <algorithm>
67
67
#include <climits>
 
68
 
68
69
#include <boost/filesystem.hpp>
 
70
#include <boost/checked_delete.hpp>
69
71
 
70
72
#include "drizzled/util/backtrace.h"
71
73
 
161
163
  return (enum_tx_isolation)session->variables.tx_isolation;
162
164
}
163
165
 
164
 
Session::Session(plugin::Client *client_arg) :
 
166
Session::Session(plugin::Client *client_arg, catalog::Instance::shared_ptr catalog_arg) :
165
167
  Open_tables_state(refresh_version),
166
168
  mem_root(&main_mem_root),
167
169
  xa_id(0),
168
170
  lex(&main_lex),
169
171
  query(new std::string),
170
172
  _schema(new std::string("")),
171
 
  catalog("LOCAL"),
172
173
  client(client_arg),
173
174
  scheduler(NULL),
174
175
  scheduler_arg(NULL),
218
219
  transaction_message(NULL),
219
220
  statement_message(NULL),
220
221
  session_event_observers(NULL),
 
222
  _catalog(catalog_arg),
221
223
  use_usage(false)
222
224
{
223
225
  client->setSession(this);
296
298
  m_internal_handler= handler;
297
299
}
298
300
 
299
 
bool Session::handle_error(uint32_t sql_errno, const char *message,
300
 
                       DRIZZLE_ERROR::enum_warning_level level)
 
301
bool Session::handle_error(drizzled::error_t sql_errno, const char *message,
 
302
                           DRIZZLE_ERROR::enum_warning_level level)
301
303
{
302
304
  if (m_internal_handler)
303
305
  {
362
364
       iter++)
363
365
  {
364
366
    user_var_entry *entry= (*iter).second;
365
 
    delete entry;
 
367
    boost::checked_delete(entry);
366
368
  }
367
369
  user_vars.clear();
368
370
 
399
401
  if (client)
400
402
  {
401
403
    client->close();
402
 
    delete client;
 
404
    boost::checked_delete(client);
 
405
    client= NULL;
403
406
  }
404
407
 
405
408
  if (cleanup_done == false)
421
424
 
422
425
  for (PropertyMap::iterator iter= life_properties.begin(); iter != life_properties.end(); iter++)
423
426
  {
424
 
    delete (*iter).second;
 
427
    boost::checked_delete((*iter).second);
425
428
  }
426
429
  life_properties.clear();
427
430
}
674
677
  /* Change database if necessary */
675
678
  if (not in_db.empty())
676
679
  {
677
 
    SchemaIdentifier identifier(in_db);
 
680
    identifier::Schema identifier(in_db);
678
681
    if (change_db(this, identifier))
679
682
    {
680
683
      /* change_db() has pushed the error message. */
951
954
  return (result->send_fields(field_list));
952
955
}
953
956
 
954
 
void select_result::send_error(uint32_t errcode, const char *err)
 
957
void select_result::send_error(drizzled::error_t errcode, const char *err)
955
958
{
956
959
  my_message(errcode, err, MYF(0));
957
960
}
960
963
  Handling writing to file
961
964
************************************************************************/
962
965
 
963
 
void select_to_file::send_error(uint32_t errcode,const char *err)
 
966
void select_to_file::send_error(drizzled::error_t errcode,const char *err)
964
967
{
965
968
  my_message(errcode, err, MYF(0));
966
969
  if (file > 0)
1608
1611
  /* Fix for Intel compiler */
1609
1612
  if (copy_field)
1610
1613
  {
1611
 
    delete [] copy_field;
1612
 
    save_copy_field= copy_field= 0;
 
1614
    boost::checked_array_delete(copy_field);
 
1615
    save_copy_field= save_copy_field_end= copy_field= copy_field_end= 0;
1613
1616
  }
1614
1617
}
1615
1618
 
1616
1619
void Session::send_kill_message() const
1617
1620
{
1618
 
  int err= killed_errno();
1619
 
  if (err)
 
1621
  drizzled::error_t err= static_cast<drizzled::error_t>(killed_errno());
 
1622
  if (err != EE_OK)
1620
1623
    my_message(err, ER(err), MYF(0));
1621
1624
}
1622
1625
 
1780
1783
  table->free_io_cache();
1781
1784
  table->delete_table();
1782
1785
 
1783
 
  TableIdentifier identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), table->getShare()->getPath());
 
1786
  identifier::Table identifier(table->getShare()->getSchemaName(), table->getShare()->getTableName(), table->getShare()->getPath());
1784
1787
  rm_temporary_table(table_type, identifier);
1785
1788
 
1786
 
  delete table->getMutableShare();
 
1789
  boost::checked_delete(table->getMutableShare());
1787
1790
 
1788
 
  delete table;
 
1791
  boost::checked_delete(table);
1789
1792
}
1790
1793
 
1791
1794
/** Clear most status variables. */
1829
1832
 
1830
1833
  if (not returnable.second)
1831
1834
  {
1832
 
    delete entry;
 
1835
    boost::checked_delete(entry);
1833
1836
  }
1834
1837
 
1835
1838
  return entry;
1954
1957
 
1955
1958
    if (not lock_tables(tables, counter, &need_reopen))
1956
1959
      break;
 
1960
 
1957
1961
    if (not need_reopen)
1958
1962
      return true;
 
1963
 
1959
1964
    close_tables_for_reopen(&tables);
1960
1965
  }
1961
 
  if ((handle_derived(lex, &derived_prepare) ||
1962
 
       (
1963
 
        handle_derived(lex, &derived_filling))))
 
1966
 
 
1967
  if ((handle_derived(lex, &derived_prepare) || (handle_derived(lex, &derived_filling))))
1964
1968
    return true;
1965
1969
 
1966
1970
  return false;
1972
1976
  might be an issue (lame engines).
1973
1977
*/
1974
1978
 
1975
 
bool Open_tables_state::rm_temporary_table(const TableIdentifier &identifier, bool best_effort)
 
1979
bool Open_tables_state::rm_temporary_table(const identifier::Table &identifier, bool best_effort)
1976
1980
{
1977
 
  if (plugin::StorageEngine::dropTable(*static_cast<Session *>(this), identifier))
 
1981
  if (not plugin::StorageEngine::dropTable(*static_cast<Session *>(this), identifier))
1978
1982
  {
1979
1983
    if (not best_effort)
1980
1984
    {
1990
1994
  return false;
1991
1995
}
1992
1996
 
1993
 
bool Open_tables_state::rm_temporary_table(plugin::StorageEngine *base, const TableIdentifier &identifier)
 
1997
bool Open_tables_state::rm_temporary_table(plugin::StorageEngine *base, const identifier::Table &identifier)
1994
1998
{
 
1999
  drizzled::error_t error;
1995
2000
  assert(base);
1996
2001
 
1997
 
  if (plugin::StorageEngine::dropTable(*static_cast<Session *>(this), *base, identifier))
 
2002
  if (not plugin::StorageEngine::dropTable(*static_cast<Session *>(this), *base, identifier, error))
1998
2003
  {
1999
2004
    std::string path;
2000
2005
    identifier.getSQLPath(path);
2001
2006
    errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2002
 
                  path.c_str(), errno);
 
2007
                  path.c_str(), error);
2003
2008
 
2004
2009
    return true;
2005
2010
  }
2041
2046
  }
2042
2047
}
2043
2048
 
2044
 
bool Session::TableMessages::storeTableMessage(const TableIdentifier &identifier, message::Table &table_message)
 
2049
bool Session::TableMessages::storeTableMessage(const identifier::Table &identifier, message::Table &table_message)
2045
2050
{
2046
2051
  table_message_cache.insert(make_pair(identifier.getPath(), table_message));
2047
2052
 
2048
2053
  return true;
2049
2054
}
2050
2055
 
2051
 
bool Session::TableMessages::removeTableMessage(const TableIdentifier &identifier)
 
2056
bool Session::TableMessages::removeTableMessage(const identifier::Table &identifier)
2052
2057
{
2053
2058
  TableMessageCache::iterator iter;
2054
2059
 
2062
2067
  return true;
2063
2068
}
2064
2069
 
2065
 
bool Session::TableMessages::getTableMessage(const TableIdentifier &identifier, message::Table &table_message)
 
2070
bool Session::TableMessages::getTableMessage(const identifier::Table &identifier, message::Table &table_message)
2066
2071
{
2067
2072
  TableMessageCache::iterator iter;
2068
2073
 
2076
2081
  return true;
2077
2082
}
2078
2083
 
2079
 
bool Session::TableMessages::doesTableMessageExist(const TableIdentifier &identifier)
 
2084
bool Session::TableMessages::doesTableMessageExist(const identifier::Table &identifier)
2080
2085
{
2081
2086
  TableMessageCache::iterator iter;
2082
2087
 
2090
2095
  return true;
2091
2096
}
2092
2097
 
2093
 
bool Session::TableMessages::renameTableMessage(const TableIdentifier &from, const TableIdentifier &to)
 
2098
bool Session::TableMessages::renameTableMessage(const identifier::Table &from, const identifier::Table &to)
2094
2099
{
2095
2100
  TableMessageCache::iterator iter;
2096
2101
 
2109
2114
  return true;
2110
2115
}
2111
2116
 
2112
 
table::Instance *Session::getInstanceTable()
 
2117
table::Singular *Session::getInstanceTable()
2113
2118
{
2114
 
  temporary_shares.push_back(new table::Instance()); // This will not go into the tableshare cache, so no key is used.
 
2119
  temporary_shares.push_back(new table::Singular()); // This will not go into the tableshare cache, so no key is used.
2115
2120
 
2116
 
  table::Instance *tmp_share= temporary_shares.back();
 
2121
  table::Singular *tmp_share= temporary_shares.back();
2117
2122
 
2118
2123
  assert(tmp_share);
2119
2124
 
2139
2144
  @return
2140
2145
    0 if out of memory, Table object in case of success
2141
2146
*/
2142
 
table::Instance *Session::getInstanceTable(List<CreateField> &field_list)
 
2147
table::Singular *Session::getInstanceTable(List<CreateField> &field_list)
2143
2148
{
2144
 
  temporary_shares.push_back(new table::Instance(this, field_list)); // This will not go into the tableshare cache, so no key is used.
 
2149
  temporary_shares.push_back(new table::Singular(this, field_list)); // This will not go into the tableshare cache, so no key is used.
2145
2150
 
2146
 
  table::Instance *tmp_share= temporary_shares.back();
 
2151
  table::Singular *tmp_share= temporary_shares.back();
2147
2152
 
2148
2153
  assert(tmp_share);
2149
2154