~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Djellel E. Difallah
  • Date: 2010-04-02 07:45:12 UTC
  • mfrom: (1435 bad-staging)
  • mto: This revision was merged to the branch mainline in revision 1440.
  • Revision ID: ded@ubuntu-20100402074512-rck7fl88o76h9tya
merge to trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
383
383
 
384
384
Session::~Session()
385
385
{
386
 
  Session_CHECK_SENTRY(this);
 
386
  this->checkSentry();
387
387
  add_to_status(&global_status_var, &status_var);
388
388
 
389
389
  if (client->isConnected())
470
470
 
471
471
void Session::awake(Session::killed_state state_to_set)
472
472
{
473
 
  Session_CHECK_SENTRY(this);
 
473
  this->checkSentry();
474
474
  safe_mutex_assert_owner(&LOCK_delete);
475
475
 
476
476
  killed= state_to_set;
687
687
  /* Change database if necessary */
688
688
  if (in_db && in_db[0])
689
689
  {
690
 
    if (mysql_change_db(this, in_db))
 
690
    SchemaIdentifier identifier(in_db);
 
691
    if (mysql_change_db(this, identifier))
691
692
    {
692
693
      /* mysql_change_db() has pushed the error message. */
693
694
      return false;
1142
1143
  return 0;
1143
1144
}
1144
1145
 
1145
 
 
1146
 
#define NEED_ESCAPING(x) ((int) (unsigned char) (x) == escape_char    || \
1147
 
                          (enclosed ? (int) (unsigned char) (x) == field_sep_char      \
1148
 
                                    : (int) (unsigned char) (x) == field_term_char) || \
1149
 
                          (int) (unsigned char) (x) == line_sep_char  || \
1150
 
                          !(x))
1151
 
 
1152
1146
bool select_export::send_data(List<Item> &items)
1153
1147
{
1154
1148
  char buff[MAX_FIELD_WIDTH],null_buff[2],space[MAX_FIELD_WIDTH];
1265
1259
            assert before the loop makes that sure.
1266
1260
          */
1267
1261
 
1268
 
          if ((NEED_ESCAPING(*pos) ||
 
1262
          if ((needs_escaping(*pos, enclosed) ||
1269
1263
               (check_second_byte &&
1270
1264
                my_mbcharlen(character_set_client, (unsigned char) *pos) == 2 &&
1271
1265
                pos + 1 < end &&
1272
 
                NEED_ESCAPING(pos[1]))) &&
 
1266
                needs_escaping(pos[1], enclosed))) &&
1273
1267
              /*
1274
1268
                Don't escape field_term_char by doubling - doubling is only
1275
1269
                valid for ENCLOSED BY characters:
1623
1617
  set_open_tables_state(backup);
1624
1618
}
1625
1619
 
1626
 
bool Session::set_db(const char *new_db, size_t length)
 
1620
bool Session::set_db(const std::string &new_db)
1627
1621
{
1628
1622
  /* Do not reallocate memory if current chunk is big enough. */
1629
 
  if (length)
 
1623
  if (new_db.length())
1630
1624
    db= new_db;
1631
1625
  else
1632
1626
    db.clear();
1760
1754
  Table *table;
1761
1755
  Table *tmp_next;
1762
1756
 
1763
 
  if (!temporary_tables)
 
1757
  if (not temporary_tables)
1764
1758
    return;
1765
1759
 
1766
1760
  for (table= temporary_tables; table; table= tmp_next)
1767
1761
  {
1768
1762
    tmp_next= table->next;
1769
 
    close_temporary(table);
 
1763
    nukeTable(table);
1770
1764
  }
1771
1765
  temporary_tables= NULL;
1772
1766
}
1796
1790
    if (temporary_tables)
1797
1791
      table->next->prev= NULL;
1798
1792
  }
1799
 
  close_temporary(table);
 
1793
  nukeTable(table);
1800
1794
}
1801
1795
 
1802
1796
/*
1803
 
  Close and delete a temporary table
 
1797
  Close and drop a temporary table
1804
1798
 
1805
1799
  NOTE
1806
1800
  This dosn't unlink table from session->temporary
1807
1801
  If this is needed, use close_temporary_table()
1808
1802
*/
1809
1803
 
1810
 
void Session::close_temporary(Table *table)
 
1804
void Session::nukeTable(Table *table)
1811
1805
{
1812
1806
  plugin::StorageEngine *table_type= table->s->db_type();
1813
1807
 
1814
1808
  table->free_io_cache();
1815
1809
  table->closefrm(false);
1816
1810
 
1817
 
  rm_temporary_table(table_type, table->s->path.str);
 
1811
  TableIdentifier identifier(table->s->getSchemaName(), table->s->table_name.str, table->s->path.str);
 
1812
  rm_temporary_table(table_type, identifier);
1818
1813
 
1819
1814
  table->s->free_table_share();
1820
1815
 
2006
2001
    if (open_tables_from_list(&tables, &counter))
2007
2002
      return true;
2008
2003
 
2009
 
    if (!lock_tables(tables, counter, &need_reopen))
 
2004
    if (not lock_tables(tables, counter, &need_reopen))
2010
2005
      break;
2011
 
    if (!need_reopen)
 
2006
    if (not need_reopen)
2012
2007
      return true;
2013
2008
    close_tables_for_reopen(&tables);
2014
2009
  }
2033
2028
 
2034
2029
bool Session::rm_temporary_table(TableIdentifier &identifier)
2035
2030
{
2036
 
  if (not plugin::StorageEngine::dropTable(*this, identifier))
 
2031
  if (plugin::StorageEngine::dropTable(*this, identifier))
2037
2032
  {
2038
2033
    errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2039
 
                  identifier.getPath().c_str(), errno);
 
2034
                  identifier.getSQLPath().c_str(), errno);
 
2035
    dumpTemporaryTableNames("rm_temporary_table()");
2040
2036
 
2041
2037
    return true;
2042
2038
  }
2044
2040
  return false;
2045
2041
}
2046
2042
 
2047
 
bool Session::rm_temporary_table(plugin::StorageEngine *base, const char *path)
 
2043
bool Session::rm_temporary_table(plugin::StorageEngine *base, TableIdentifier &identifier)
2048
2044
{
2049
 
  bool error= false;
2050
 
  TableIdentifier dummy(path);
2051
 
 
2052
2045
  assert(base);
2053
2046
 
2054
 
  if (delete_table_proto_file(path))
2055
 
    error= true;
2056
 
 
2057
 
  if (base->doDropTable(*this, dummy))
 
2047
  if (plugin::StorageEngine::dropTable(*this, *base, identifier))
2058
2048
  {
2059
 
    error= true;
2060
2049
    errmsg_printf(ERRMSG_LVL_WARN, _("Could not remove temporary table: '%s', error: %d"),
2061
 
                  path, errno);
2062
 
  }
2063
 
  return error;
 
2050
                  identifier.getSQLPath().c_str(), errno);
 
2051
    dumpTemporaryTableNames("rm_temporary_table()");
 
2052
 
 
2053
    return true;
 
2054
  }
 
2055
 
 
2056
  return false;
 
2057
}
 
2058
 
 
2059
/**
 
2060
  @note this will be removed, I am looking through Hudson to see if it is finding
 
2061
  any tables that are missed during cleanup.
 
2062
*/
 
2063
void Session::dumpTemporaryTableNames(const char *foo)
 
2064
{
 
2065
  Table *table;
 
2066
 
 
2067
  if (not temporary_tables)
 
2068
    return;
 
2069
 
 
2070
  cerr << "Begin Run: " << foo << "\n";
 
2071
  for (table= temporary_tables; table; table= table->next)
 
2072
  {
 
2073
    bool have_proto= false;
 
2074
 
 
2075
    message::Table *proto= table->s->getTableProto();
 
2076
    if (table->s->getTableProto())
 
2077
      have_proto= true;
 
2078
 
 
2079
    const char *answer= have_proto ? "true" : "false";
 
2080
 
 
2081
    if (have_proto)
 
2082
    {
 
2083
      cerr << "\tTable Name " << table->s->getSchemaName() << "." << table->s->table_name.str << " : " << answer << "\n";
 
2084
      cerr << "\t\t Proto " << proto->schema() << " " << proto->name() << "\n";
 
2085
    }
 
2086
    else
 
2087
      cerr << "\tTabl;e Name " << table->s->getSchemaName() << "." << table->s->table_name.str << " : " << answer << "\n";
 
2088
  }
2064
2089
}
2065
2090
 
2066
2091
bool Session::storeTableMessage(TableIdentifier &identifier, message::Table &table_message)
2125
2150
    return false;
2126
2151
  }
2127
2152
 
2128
 
  to.copyToTableMessage((*iter).second);
2129
 
 
2130
 
  (void)removeTableMessage(from);
 
2153
  (*iter).second.set_schema(to.getSchemaName());
 
2154
  (*iter).second.set_name(to.getTableName());
2131
2155
 
2132
2156
  return true;
2133
2157
}