~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/table_identifier.h

  • Committer: Stewart Smith
  • Date: 2010-02-15 01:56:32 UTC
  • mto: (1273.13.96 build)
  • mto: This revision was merged to the branch mainline in revision 1308.
  • Revision ID: stewart@flamingspork.com-20100215015632-pm7lnxfq5j5uh8kj
move DATABASE() to function plugin. modify parser so that it looks for a function named 'database' when DATABASE() is called. Special case still needed in parser due to hilarity of not-really-reserved words.

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"
38
 
 
39
 
#include "drizzled/schema_identifier.h"
40
 
 
41
37
#include <string.h>
42
38
 
43
 
#include <assert.h>
44
 
 
45
39
#include <ostream>
46
 
#include <set>
47
 
#include <algorithm>
48
 
#include <functional>
49
40
 
50
41
namespace drizzled {
51
42
 
52
 
class Table;
53
 
 
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
 
 
57
 
class TableIdentifier : public SchemaIdentifier
 
43
class TableIdentifier
58
44
{
59
 
public:
60
 
  typedef message::Table::TableType Type;
61
45
private:
62
 
 
63
 
  Type type;
64
 
  std::string path;
65
 
  std::string table_name;
66
 
  std::string lower_table_name;
67
 
  std::string sql_path;
68
 
 
69
 
  void init();
 
46
  bool path_inited;
 
47
 
 
48
  tmp_table_type type;
 
49
  char path[FN_REFLEN];
 
50
  const char *db;
 
51
  const char *table_name;
70
52
 
71
53
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
 
 
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),
88
 
    type(tmp_arg),
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);
 
54
  TableIdentifier( const char *db_arg,
 
55
                   const char *table_name_arg,
 
56
                   tmp_table_type tmp_arg= NO_TMP_TABLE) :
 
57
    path_inited(false),
 
58
    type(tmp_arg),
 
59
    db(db_arg),
 
60
    table_name(table_name_arg)
 
61
  { }
107
62
 
108
63
  bool isTmp() const
109
64
  {
110
 
    if (type == message::Table::TEMPORARY || type == message::Table::INTERNAL)
111
 
      return true;
112
 
    return false;
113
 
  }
114
 
 
115
 
  Type getType() const
116
 
  {
117
 
    return type;
118
 
  }
119
 
 
120
 
  const std::string &getSQLPath();
121
 
 
122
 
  const std::string &getPath();
123
 
 
124
 
  void setPath(const std::string &new_path)
125
 
  {
126
 
    path= new_path;
127
 
  }
128
 
 
129
 
  const std::string &getTableName() const
 
65
    return type == NO_TMP_TABLE ? false  : true;
 
66
  }
 
67
 
 
68
  const char *getPath();
 
69
 
 
70
  const char *getDBName() const
 
71
  {
 
72
    return db;
 
73
  }
 
74
 
 
75
  const char *getSchemaName() const
 
76
  {
 
77
    return db;
 
78
  }
 
79
 
 
80
  const char *getTableName() const
130
81
  {
131
82
    return table_name;
132
83
  }
133
84
 
134
 
  void copyToTableMessage(message::Table &message);
135
 
 
136
 
  bool operator<(TableIdentifier &right)
137
 
  {
138
 
    int first= getLower().compare(right.getLower());
139
 
 
140
 
    if (first < 0)
141
 
    {
142
 
      return true;
143
 
    }
144
 
    else if (first > 0)
145
 
    {
146
 
      return false;
147
 
    }
148
 
    else
149
 
    {
150
 
      int val= lower_table_name.compare(right.lower_table_name);
151
 
 
152
 
      if (val < 0)
153
 
      {
154
 
        return true;
155
 
      }
156
 
      else if (val > 0)
157
 
      {
158
 
        return false;
159
 
      }
160
 
      else
161
 
      {
162
 
        if (type < right.type)
163
 
        {
164
 
          return true;
165
 
        }
166
 
      }
167
 
    }
168
 
 
169
 
    return false;
170
 
  }
171
 
 
172
85
  friend std::ostream& operator<<(std::ostream& output, const TableIdentifier &identifier)
173
86
  {
174
87
    const char *type_str;
175
88
 
176
89
    output << "TableIdentifier:(";
177
 
    output <<  identifier.getSchemaName();
 
90
    output <<  identifier.getDBName();
178
91
    output << ", ";
179
92
    output << identifier.getTableName();
180
93
    output << ", ";
181
94
 
182
95
    switch (identifier.type) {
183
 
    case message::Table::STANDARD:
 
96
    case NO_TMP_TABLE:
184
97
      type_str= "standard";
185
98
      break;
186
 
    case message::Table::INTERNAL:
 
99
    case INTERNAL_TMP_TABLE:
187
100
      type_str= "internal";
188
101
      break;
189
 
    case message::Table::TEMPORARY:
 
102
    case TEMP_TABLE:
190
103
      type_str= "temporary";
191
104
      break;
192
 
    case message::Table::FUNCTION:
193
 
      type_str= "function";
194
 
      break;
 
105
    case SYSTEM_TMP_TABLE:
 
106
      type_str= "system";
195
107
    }
196
108
 
197
109
    output << type_str;
198
 
    output << ", ";
199
 
    output << identifier.path;
200
110
    output << ")";
201
111
 
202
112
    return output;  // for multiple << operators.
203
113
  }
204
114
 
205
 
  friend bool operator==(TableIdentifier &left, TableIdentifier &right)
 
115
  friend bool operator==(const TableIdentifier &left, const TableIdentifier &right)
206
116
  {
207
117
    if (left.type == right.type)
208
118
    {
209
 
      if (static_cast<SchemaIdentifier &>(left) == static_cast<SchemaIdentifier &>(right))
 
119
      if (! strcmp(left.db, right.db))
210
120
      {
211
 
        if (left.lower_table_name == right.lower_table_name)
 
121
        if (! strcmp(left.table_name, right.table_name))
212
122
        {
213
123
          return true;
214
124
        }
220
130
 
221
131
};
222
132
 
223
 
typedef std::vector <TableIdentifier> TableIdentifierList;
224
 
typedef std::list <TableIdentifier> TableIdentifiers;
225
 
 
226
133
} /* namespace drizzled */
227
134
 
228
135
#endif /* DRIZZLED_TABLE_IDENTIFIER_H */