30
29
This will replace Table_ident.
33
#ifndef DRIZZLED_IDENTIFIER_TABLE_H
34
#define DRIZZLED_IDENTIFIER_TABLE_H
32
#ifndef DRIZZLED_TABLE_IDENTIFIER_H
33
#define DRIZZLED_TABLE_IDENTIFIER_H
36
35
#include <drizzled/enum.h>
37
#include <drizzled/definitions.h>
38
#include <drizzled/message/table.pb.h>
36
#include "drizzled/definitions.h"
37
#include "drizzled/message/table.pb.h"
39
#include "drizzled/schema_identifier.h"
40
41
#include <string.h>
49
50
#include <boost/functional/hash.hpp>
51
#include <drizzled/visibility.h>
53
52
namespace drizzled {
56
namespace identifier {
58
class DRIZZLED_API Table : public Schema
56
class TableIdentifier : public SchemaIdentifier
61
59
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
60
typedef std::vector<char> Key;
121
std::string key_path;
122
65
std::string table_name;
66
std::string lower_table_name;
124
69
size_t hash_value;
135
Table(const drizzled::Table &table);
79
TableIdentifier(const Table &table);
137
Table(const identifier::Schema &schema,
138
const std::string &table_name_arg,
139
Type tmp_arg= message::Table::STANDARD) :
142
table_name(table_name_arg)
147
Table( const std::string &db_arg,
148
const std::string &table_name_arg,
149
Type tmp_arg= message::Table::STANDARD) :
152
table_name(table_name_arg)
157
Table( const std::string &schema_name_arg,
81
TableIdentifier( const SchemaIdentifier &schema,
82
const std::string &table_name_arg,
83
Type tmp_arg= message::Table::STANDARD) :
84
SchemaIdentifier(schema),
86
table_name(table_name_arg)
91
TableIdentifier( const std::string &db_arg,
92
const std::string &table_name_arg,
93
Type tmp_arg= message::Table::STANDARD) :
94
SchemaIdentifier(db_arg),
96
table_name(table_name_arg)
101
TableIdentifier( const std::string &schema_name_arg,
158
102
const std::string &table_name_arg,
159
103
const std::string &path_arg ) :
160
Schema(schema_name_arg),
104
SchemaIdentifier(schema_name_arg),
161
105
type(message::Table::TEMPORARY),
163
107
table_name(table_name_arg)
168
using Schema::compare;
112
using SchemaIdentifier::compare;
113
bool compare(std::string schema_arg, std::string table_arg) const;
170
115
bool isTmp() const
172
117
if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
178
static bool isView(message::Table::TableType arg) // Not a SQL view, but a view for I_S
183
case message::Table::STANDARD:
184
case message::Table::TEMPORARY:
185
case message::Table::INTERNAL:
187
case message::Table::FUNCTION:
194
122
bool isView() const // Not a SQL view, but a view for I_S
124
if (type == message::Table::FUNCTION)
199
129
Type getType() const
219
148
void copyToTableMessage(message::Table &message) const;
221
friend bool operator<(Table::const_reference left, Table::const_reference right)
150
friend bool operator<(const TableIdentifier &left, const TableIdentifier &right)
223
if (left.getKey() < right.getKey())
152
// Compare the schema names. You must use schema, path is not valid for
154
int first= left.getLower().compare(right.getLower());
231
friend bool operator==(Table::const_reference left, Table::const_reference right)
233
if (left.getHashValue() == right.getHashValue())
235
if (left.getKey() == right.getKey())
165
// Compare the tables names.
166
int val= left.lower_table_name.compare(right.lower_table_name);
178
if (left.type < right.type)
188
friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
190
const char *type_str;
192
output << "TableIdentifier:(";
193
output << identifier.getSchemaName();
195
output << identifier.getTableName();
198
switch (identifier.type) {
199
case message::Table::STANDARD:
200
type_str= "standard";
202
case message::Table::INTERNAL:
203
type_str= "internal";
205
case message::Table::TEMPORARY:
206
type_str= "temporary";
208
case message::Table::FUNCTION:
209
type_str= "function";
215
output << identifier.path;
217
output << identifier.getHashValue();
220
return output; // for multiple << operators.
223
friend bool operator==(TableIdentifier &left, TableIdentifier &right)
225
if (left.type == right.type)
227
if (static_cast<SchemaIdentifier &>(left) == static_cast<SchemaIdentifier &>(right))
229
if (left.lower_table_name == right.lower_table_name)
242
239
static uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
243
static size_t build_table_filename(std::string &path, const std::string &db, const std::string &table_name, bool is_tmp);
240
static size_t build_table_filename(std::string &buff, const char *db, const char *table_name, bool is_tmp);
244
241
static size_t build_tmptable_filename(std::string &buffer);
245
242
static size_t build_tmptable_filename(std::vector<char> &buffer);
248
bool isValid() const;
245
Create a table cache key
249
key Create key here (must be of size MAX_DBKEY_LENGTH)
250
table_list Table definition
253
The table cache_key is created from:
257
if the table is a tmp table, we add the following to make each tmp table
260
4 bytes for master thread id
261
4 bytes pseudo thread id
266
static uint32_t createKey(char *key, const char *db_arg, const char *table_name_arg)
271
key_pos= strcpy(key_pos, db_arg) + strlen(db_arg);
272
key_pos= strcpy(key_pos+1, table_name_arg) +
273
strlen(table_name_arg);
274
key_length= (uint32_t)(key_pos-key)+1;
279
static uint32_t createKey(char *key, const TableIdentifier &identifier)
284
key_pos= strcpy(key_pos, identifier.getSchemaName().c_str()) + identifier.getSchemaName().length();
285
key_pos= strcpy(key_pos + 1, identifier.getTableName().c_str()) + identifier.getTableName().length();
286
key_length= (uint32_t)(key_pos-key)+1;
250
291
size_t getHashValue() const
261
std::ostream& operator<<(std::ostream& output, Table::const_reference identifier);
262
std::size_t hash_value(Table const& b);
263
std::size_t hash_value(Table::Key const& b);
265
} /* namespace identifier */
302
std::size_t hash_value(TableIdentifier const& b);
304
typedef std::vector <TableIdentifier> TableIdentifiers;
266
306
} /* namespace drizzled */
268
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */
308
#endif /* DRIZZLED_TABLE_IDENTIFIER_H */