~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_identifier.h

Merged trunk and use-std-unordred.

Show diffs side-by-side

added added

removed removed

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