1
1
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
5
4
* Copyright (C) 2009 Sun Microsystems
7
6
* This program is free software; you can redistribute it and/or modify
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
36
#include "drizzled/definitions.h"
38
37
#include "drizzled/message/table.pb.h"
40
#include "drizzled/identifier.h"
39
#include "drizzled/schema_identifier.h"
42
41
#include <string.h>
48
47
#include <algorithm>
49
48
#include <functional>
51
#include <boost/functional/hash.hpp>
53
50
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);
57
57
class TableIdentifier : public SchemaIdentifier
60
60
typedef message::Table::TableType Type;
61
typedef std::vector <TableIdentifier> vector;
62
typedef const TableIdentifier& const_reference;
63
typedef TableIdentifier& reference;
67
std::vector<char> key_buffer;
77
const char *vector() const
79
return &key_buffer[0];
82
std::vector<char> &vectorPtr()
87
void set(size_t resize_arg, const std::string &a, const std::string &b);
89
friend bool operator==(const Key &left, const Key &right)
91
if (left.hash_value == right.hash_value and left.key_buffer.size() == right.key_buffer.size())
93
if (memcmp(&left.key_buffer[0], &right.key_buffer[0], left.key_buffer.size()) == 0)
100
friend bool operator<(const Key &left, const Key &right)
102
return left.key_buffer < right.key_buffer;
107
return key_buffer.size();
110
size_t getHashValue() const
120
65
std::string table_name;
66
std::string lower_table_name;
126
size_t getKeySize() const
128
return getSchemaName().size() + getTableName().size() + 2;
132
72
TableIdentifier(const Table &table);
174
static bool isView(message::Table::TableType arg) // Not a SQL view, but a view for I_S
179
case message::Table::STANDARD:
180
case message::Table::TEMPORARY:
181
case message::Table::INTERNAL:
183
case message::Table::FUNCTION:
190
bool isView() const // Not a SQL view, but a view for I_S
195
115
Type getType() const
200
virtual void getSQLPath(std::string &sql_path) const;
120
const std::string &getSQLPath();
202
virtual const std::string &getPath() const;
122
const std::string &getPath();
204
124
void setPath(const std::string &new_path)
211
131
return table_name;
214
void copyToTableMessage(message::Table &message) const;
216
friend bool operator<(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
218
if (left.getKey() < right.getKey())
226
friend std::ostream& operator<<(std::ostream& output, TableIdentifier::const_reference identifier)
134
void copyToTableMessage(message::Table &message);
136
friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
228
138
const char *type_str;
251
161
output << type_str;
253
163
output << identifier.path;
255
output << identifier.getHashValue();
258
166
return output; // for multiple << operators.
261
friend bool operator==(TableIdentifier::const_reference left, TableIdentifier::const_reference right)
169
friend bool operator==(TableIdentifier &left, TableIdentifier &right)
263
if (left.getHashValue() == right.getHashValue())
171
if (left.type == right.type)
265
if (left.getKey() == right.getKey())
173
if (static_cast<SchemaIdentifier &>(left) == static_cast<SchemaIdentifier &>(right))
175
if (left.lower_table_name == right.lower_table_name)
272
static uint32_t filename_to_tablename(const char *from, char *to, uint32_t to_length);
273
static size_t build_table_filename(std::string &path, const std::string &db, const std::string &table_name, bool is_tmp);
274
static size_t build_tmptable_filename(std::string &buffer);
275
static size_t build_tmptable_filename(std::vector<char> &buffer);
278
bool isValid() const;
280
size_t getHashValue() const
285
const Key &getKey() const
291
std::size_t hash_value(TableIdentifier const& b);
292
std::size_t hash_value(TableIdentifier::Key const& b);
187
typedef std::vector <TableIdentifier> TableIdentifierList;
294
189
} /* namespace drizzled */
296
#endif /* DRIZZLED_IDENTIFIER_TABLE_H */
191
#endif /* DRIZZLED_TABLE_IDENTIFIER_H */