~stewart/drizzle/embedded-innodb-rnd-read

« back to all changes in this revision

Viewing changes to drizzled/table_identifier.h

  • Committer: Stewart Smith
  • Date: 2010-03-30 13:09:42 UTC
  • mfrom: (1310.1.38)
  • Revision ID: stewart@flamingspork.com-20100330130942-859uivdm20p36sk3
Merged embedded-innodb-write-row into embedded-innodb-rnd-read.

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
 
35
35
#include <drizzled/enum.h>
36
36
#include "drizzled/definitions.h"
 
37
#include "drizzled/message/table.pb.h"
37
38
#include <string.h>
38
39
 
39
40
#include <assert.h>
48
49
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
49
50
size_t build_table_filename(std::string &buff, const char *db, const char *table_name, bool is_tmp);
50
51
 
51
 
 
52
52
class TableIdentifier
53
53
{
54
 
  tmp_table_type type;
 
54
public:
 
55
  typedef message::Table::TableType Type;
 
56
private:
 
57
 
 
58
  Type type;
55
59
  std::string path;
56
60
  std::string db;
57
61
  std::string table_name;
59
63
  std::string lower_table_name;
60
64
  std::string sql_path;
61
65
 
 
66
  void primeLower();
 
67
 
62
68
public:
63
69
  TableIdentifier( const std::string &db_arg,
64
70
                   const std::string &table_name_arg,
65
 
                   tmp_table_type tmp_arg= STANDARD_TABLE) :
 
71
                   Type tmp_arg= message::Table::STANDARD) :
66
72
    type(tmp_arg),
67
73
    db(db_arg),
68
 
    table_name(table_name_arg),
69
 
    lower_db(db_arg),
70
 
    lower_table_name(table_name_arg),
71
 
    sql_path(db_arg)
 
74
    table_name(table_name_arg)
72
75
  { 
73
 
    std::transform(lower_table_name.begin(), lower_table_name.end(),
74
 
                   lower_table_name.begin(), ::tolower);
75
 
 
76
 
    std::transform(lower_db.begin(), lower_db.end(),
77
 
                   lower_db.begin(), ::tolower);
78
 
 
79
 
    sql_path.append(".");
80
 
    sql_path.append(table_name);
81
76
  }
82
77
 
83
 
  /**
84
 
    This is only used in scavenging lost tables. Once the temp schema engine goes in, this should go away.
85
 
  */
86
 
  TableIdentifier( const char *path_arg ) :
87
 
    type(TEMP_TABLE),
 
78
  TableIdentifier( const std::string &schema_name_arg,
 
79
                   const std::string &table_name_arg,
 
80
                   const std::string &path_arg ) :
 
81
    type(message::Table::TEMPORARY),
88
82
    path(path_arg),
89
 
    db(path_arg),
90
 
    table_name(path_arg),
91
 
    sql_path(db)
 
83
    db(schema_name_arg),
 
84
    table_name(table_name_arg)
92
85
  { 
93
 
    sql_path.append(".");
94
 
    sql_path.append(table_name);
95
86
  }
96
87
 
97
88
  bool isTmp() const
98
89
  {
99
 
    return type == STANDARD_TABLE ? false  : true;
 
90
    if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
 
91
      return true;
 
92
    return false;
100
93
  }
101
94
 
102
 
  const std::string &getSQLPath()
 
95
  Type getType() const
103
96
  {
104
 
    return sql_path;
 
97
    return type;
105
98
  }
106
99
 
 
100
  const std::string &getSQLPath();
 
101
 
107
102
  const std::string &getPath();
108
103
 
 
104
  void setPath(const std::string &new_path)
 
105
  {
 
106
    path= new_path;
 
107
  }
 
108
 
109
109
  const std::string &getDBName() const
110
110
  {
111
111
    return db;
121
121
    return table_name;
122
122
  }
123
123
 
 
124
  void copyToTableMessage(message::Table &message);
 
125
 
124
126
  friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
125
127
  {
126
128
    const char *type_str;
132
134
    output << ", ";
133
135
 
134
136
    switch (identifier.type) {
135
 
    case STANDARD_TABLE:
 
137
    case message::Table::STANDARD:
136
138
      type_str= "standard";
137
139
      break;
138
 
    case INTERNAL_TMP_TABLE:
 
140
    case message::Table::INTERNAL:
139
141
      type_str= "internal";
140
142
      break;
141
 
    case TEMP_TABLE:
 
143
    case message::Table::TEMPORARY:
142
144
      type_str= "temporary";
143
145
      break;
144
 
    case SYSTEM_TMP_TABLE:
145
 
      type_str= "system";
 
146
    case message::Table::FUNCTION:
 
147
      type_str= "function";
 
148
      break;
146
149
    }
147
150
 
148
151
    output << type_str;
 
152
    output << ", ";
 
153
    output << identifier.path;
149
154
    output << ")";
150
155
 
151
156
    return output;  // for multiple << operators.
152
157
  }
153
158
 
154
 
  friend bool operator==(const TableIdentifier &left, const TableIdentifier &right)
 
159
  friend bool operator==(TableIdentifier &left, TableIdentifier &right)
155
160
  {
 
161
    left.primeLower();
 
162
    right.primeLower();
 
163
 
156
164
    if (left.type == right.type)
157
165
    {
158
 
      if (left.db == right.db)
 
166
      if (left.lower_db == right.lower_db)
159
167
      {
160
 
        if (left.table_name == right.table_name)
 
168
        if (left.lower_table_name == right.lower_table_name)
161
169
        {
162
170
          return true;
163
171
        }
169
177
 
170
178
};
171
179
 
172
 
typedef std::set <TableIdentifier> TableIdentifierList;
 
180
typedef std::vector <TableIdentifier> TableIdentifierList;
173
181
 
174
182
} /* namespace drizzled */
175
183