29
30
This will replace Table_ident.
32
#ifndef DRIZZLED_TABLE_IDENTIFIER_H
33
#define DRIZZLED_TABLE_IDENTIFIER_H
33
#ifndef DRIZZLED_IDENTIFIER_TABLE_H
34
#define DRIZZLED_IDENTIFIER_TABLE_H
35
36
#include <drizzled/enum.h>
36
37
#include "drizzled/definitions.h"
37
38
#include "drizzled/message/table.pb.h"
39
#include "drizzled/schema_identifier.h"
40
#include "drizzled/identifier.h"
41
42
#include <string.h>
47
48
#include <algorithm>
48
49
#include <functional>
51
#include <boost/functional/hash.hpp>
50
53
namespace drizzled {
54
uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
55
size_t build_table_filename(std::string &buff, const char *db, const char *table_name, bool is_tmp);
56
namespace identifier {
57
class TableIdentifier : public SchemaIdentifier
58
class Table : public identifier::Schema
60
61
typedef message::Table::TableType Type;
62
typedef std::vector <Table> vector;
63
typedef const Table& const_reference;
64
typedef Table& reference;
68
std::vector<char> key_buffer;
78
const char *vector() const
80
return &key_buffer[0];
83
std::vector<char> &vectorPtr()
88
void set(size_t resize_arg, const std::string &a, const std::string &b);
90
friend bool operator==(const Key &left, const Key &right)
92
if (left.hash_value == right.hash_value and left.key_buffer.size() == right.key_buffer.size())
94
if (memcmp(&left.key_buffer[0], &right.key_buffer[0], left.key_buffer.size()) == 0)
101
friend bool operator<(const Key &left, const Key &right)
103
return left.key_buffer < right.key_buffer;
108
return key_buffer.size();
111
size_t getHashValue() const
65
121
std::string table_name;
66
std::string lower_table_name;
127
size_t getKeySize() const
129
return getSchemaName().size() + getTableName().size() + 2;
72
TableIdentifier(const Table &table);
134
Table(const drizzled::Table &table);
74
TableIdentifier( const SchemaIdentifier &schema,
75
const std::string &table_name_arg,
76
Type tmp_arg= message::Table::STANDARD) :
77
SchemaIdentifier(schema),
79
table_name(table_name_arg)
84
TableIdentifier( const std::string &db_arg,
85
const std::string &table_name_arg,
86
Type tmp_arg= message::Table::STANDARD) :
87
SchemaIdentifier(db_arg),
89
table_name(table_name_arg)
94
TableIdentifier( const std::string &schema_name_arg,
136
Table(const identifier::Schema &schema,
137
const std::string &table_name_arg,
138
Type tmp_arg= message::Table::STANDARD) :
141
table_name(table_name_arg)
146
Table( const std::string &db_arg,
147
const std::string &table_name_arg,
148
Type tmp_arg= message::Table::STANDARD) :
151
table_name(table_name_arg)
156
Table( const std::string &schema_name_arg,
95
157
const std::string &table_name_arg,
96
158
const std::string &path_arg ) :
97
SchemaIdentifier(schema_name_arg),
159
Schema(schema_name_arg),
98
160
type(message::Table::TEMPORARY),
100
162
table_name(table_name_arg)
176
static bool isView(message::Table::TableType arg) // Not a SQL view, but a view for I_S
181
case message::Table::STANDARD:
182
case message::Table::TEMPORARY:
183
case message::Table::INTERNAL:
185
case message::Table::FUNCTION:
192
bool isView() const // Not a SQL view, but a view for I_S
115
197
Type getType() const
120
const std::string &getSQLPath();
202
virtual void getSQLPath(std::string &sql_path) const;
122
const std::string &getPath();
204
virtual const std::string &getPath() const;
124
206
void setPath(const std::string &new_path)
131
213
return table_name;
134
void copyToTableMessage(message::Table &message);
216
void copyToTableMessage(message::Table &message) const;
136
bool operator<(TableIdentifier &right)
218
friend bool operator<(Table::const_reference left, Table::const_reference right)
138
int first= getLower().compare(right.getLower());
220
if (left.getKey() < right.getKey())
150
int val= lower_table_name.compare(right.lower_table_name);
162
if (type < right.type)
172
friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
228
friend std::ostream& operator<<(std::ostream& output, Table::const_reference identifier)
174
230
const char *type_str;
176
output << "TableIdentifier:(";
177
233
output << identifier.getSchemaName();
179
235
output << identifier.getTableName();
197
253
output << type_str;
199
255
output << identifier.path;
257
output << identifier.getHashValue();
202
260
return output; // for multiple << operators.
205
friend bool operator==(TableIdentifier &left, TableIdentifier &right)
263
friend bool operator==(Table::const_reference left, Table::const_reference right)
207
if (left.type == right.type)
265
if (left.getHashValue() == right.getHashValue())
209
if (static_cast<SchemaIdentifier &>(left) == static_cast<SchemaIdentifier &>(right))
211
if (left.lower_table_name == right.lower_table_name)
267
if (left.getKey() == right.getKey())
274
static uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
275
static size_t build_table_filename(std::string &path, const std::string &db, const std::string &table_name, bool is_tmp);
276
static size_t build_tmptable_filename(std::string &buffer);
277
static size_t build_tmptable_filename(std::vector<char> &buffer);
280
bool isValid() const;
282
size_t getHashValue() const
287
const Key &getKey() const
223
typedef std::vector <TableIdentifier> TableIdentifierList;
224
typedef std::list <TableIdentifier> TableIdentifiers;
293
std::size_t hash_value(Table const& b);
294
std::size_t hash_value(Table::Key const& b);
296
} /* namespace identifier */
226
297
} /* namespace drizzled */
228
#endif /* DRIZZLED_TABLE_IDENTIFIER_H */
299
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */