~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message.cc

  • Committer: Monty Taylor
  • Date: 2011-02-13 17:26:39 UTC
  • mfrom: (2157.2.2 give-in-to-pkg-config)
  • mto: This revision was merged to the branch mainline in revision 2166.
  • Revision ID: mordred@inaugust.com-20110213172639-nhy7i72sfhoq13ms
Merged in pkg-config fixes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
 
2
 *  vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
 
3
 *
 
4
 *  Copyright (C) 2010 Brian Aker
 
5
 *
 
6
 *  This program is free software; you can redistribute it and/or modify
 
7
 *  it under the terms of the GNU General Public License as published by
 
8
 *  the Free Software Foundation; either version 2 of the License, or
 
9
 *  (at your option) any later version.
 
10
 *
 
11
 *  This program is distributed in the hope that it will be useful,
 
12
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 
13
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
14
 *  GNU General Public License for more details.
 
15
 *
 
16
 *  You should have received a copy of the GNU General Public License
 
17
 *  along with this program; if not, write to the Free Software
 
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
 
19
 */
 
20
 
 
21
#include "config.h"
 
22
 
 
23
#include <drizzled/show.h>
 
24
#include <drizzled/session.h>
 
25
#include <drizzled/db.h>
 
26
#include <drizzled/plugin/event_observer.h>
 
27
#include <drizzled/message.h>
 
28
 
 
29
#include "drizzled/message/table.pb.h"
 
30
#include "drizzled/message/schema.pb.h"
 
31
 
 
32
#include <string>
 
33
 
 
34
namespace drizzled {
 
35
namespace message {
 
36
 
 
37
static const std::string PROGRAM_ERROR("PROGRAM_ERROR");
 
38
 
 
39
// These are used to generate strings for types
 
40
static const std::string VARCHAR("VARCHAR");
 
41
static const std::string VARBINARY("VARBINARY");
 
42
static const std::string DOUBLE("DOUBLE");
 
43
static const std::string TEXT("TEXT");
 
44
static const std::string BLOB("BLOB");
 
45
static const std::string ENUM("ENUM");
 
46
static const std::string INTEGER("INTEGER");
 
47
static const std::string BIGINT("BIGINT");
 
48
static const std::string DECIMAL("DECIMAL");
 
49
static const std::string DATE("DATE");
 
50
static const std::string EPOCH("EPOCH");
 
51
static const std::string TIMESTAMP("TIMESTAMP");
 
52
static const std::string MICROTIME("MICROTIME");
 
53
static const std::string DATETIME("DATETIME");
 
54
static const std::string TIME("TIME");
 
55
static const std::string UUID("UUID");
 
56
static const std::string BOOLEAN("BOOLEAN");
 
57
 
 
58
static const std::string UNDEFINED("UNDEFINED");
 
59
static const std::string RESTRICT("RESTRICT");
 
60
static const std::string CASCADE("CASCADE");
 
61
static const std::string SET_NULL("SET NULL");
 
62
static const std::string NO_ACTION("NO ACTION");
 
63
static const std::string SET_DEFAULT("SET DEFAULT");
 
64
 
 
65
static const std::string YES("YES");
 
66
static const std::string NO("NO");
 
67
 
 
68
static const std::string UNKNOWN_INDEX("UNKNOWN_INDEX");
 
69
static const std::string BTREE("BTREE");
 
70
static const std::string RTREE("RTREE");
 
71
static const std::string HASH("HASH");
 
72
static const std::string FULLTEXT("FULLTEXT");
 
73
 
 
74
static const std::string MATCH_FULL("FULL");
 
75
static const std::string MATCH_PARTIAL("PARTIAL");
 
76
static const std::string MATCH_SIMPLE("SIMPLE");
 
77
 
 
78
const static std::string STANDARD_STRING("STANDARD");
 
79
const static std::string TEMPORARY_STRING("TEMPORARY");
 
80
const static std::string INTERNAL_STRING("INTERNAL");
 
81
const static std::string FUNCTION_STRING("FUNCTION");
 
82
 
 
83
void update(drizzled::message::Schema &arg)
 
84
{
 
85
  arg.set_version(arg.version() + 1);
 
86
  arg.set_update_timestamp(time(NULL));
 
87
}
 
88
 
 
89
void update(drizzled::message::Table &arg)
 
90
{
 
91
  arg.set_version(arg.version() + 1);
 
92
  arg.set_update_timestamp(time(NULL));
 
93
}
 
94
 
 
95
bool is_numeric(const message::Table::Field &field)
 
96
{
 
97
  message::Table::Field::FieldType type= field.type();
 
98
 
 
99
  switch (type)
 
100
  {
 
101
  case message::Table::Field::DOUBLE:
 
102
  case message::Table::Field::INTEGER:
 
103
  case message::Table::Field::BIGINT:
 
104
  case message::Table::Field::DECIMAL:
 
105
    return true;
 
106
  case message::Table::Field::BLOB:
 
107
  case message::Table::Field::VARCHAR:
 
108
  case message::Table::Field::ENUM:
 
109
  case message::Table::Field::DATE:
 
110
  case message::Table::Field::EPOCH:
 
111
  case message::Table::Field::DATETIME:
 
112
  case message::Table::Field::TIME:
 
113
  case message::Table::Field::UUID:
 
114
  case message::Table::Field::BOOLEAN:
 
115
    break;
 
116
  }
 
117
 
 
118
  return false;
 
119
}
 
120
 
 
121
const std::string &type(const message::Table::Field &field)
 
122
{
 
123
  message::Table::Field::FieldType type= field.type();
 
124
 
 
125
  switch (type)
 
126
  {
 
127
  case message::Table::Field::VARCHAR:
 
128
    return field.string_options().collation().compare("binary") ? VARCHAR : VARBINARY;
 
129
  case message::Table::Field::DOUBLE:
 
130
    return DOUBLE;
 
131
  case message::Table::Field::BLOB:
 
132
    return field.string_options().collation().compare("binary") ? TEXT : BLOB;
 
133
  case message::Table::Field::ENUM:
 
134
    return ENUM;
 
135
  case message::Table::Field::INTEGER:
 
136
    return INTEGER;
 
137
  case message::Table::Field::BIGINT:
 
138
    return BIGINT;
 
139
  case message::Table::Field::DECIMAL:
 
140
    return DECIMAL;
 
141
  case message::Table::Field::DATE:
 
142
    return DATE;
 
143
  case message::Table::Field::EPOCH:
 
144
    return TIMESTAMP;
 
145
  case message::Table::Field::DATETIME:
 
146
    return DATETIME;
 
147
  case message::Table::Field::TIME:
 
148
    return TIME;
 
149
  case message::Table::Field::UUID:
 
150
    return UUID;
 
151
  case message::Table::Field::BOOLEAN:
 
152
    return BOOLEAN;
 
153
  }
 
154
 
 
155
  abort();
 
156
}
 
157
 
 
158
const std::string &type(drizzled::message::Table::Field::FieldType type)
 
159
{
 
160
  switch (type)
 
161
  {
 
162
  case message::Table::Field::VARCHAR:
 
163
    return VARCHAR;
 
164
  case message::Table::Field::DOUBLE:
 
165
    return DOUBLE;
 
166
  case message::Table::Field::BLOB:
 
167
    return BLOB;
 
168
  case message::Table::Field::ENUM:
 
169
    return ENUM;
 
170
  case message::Table::Field::INTEGER:
 
171
    return INTEGER;
 
172
  case message::Table::Field::BIGINT:
 
173
    return BIGINT;
 
174
  case message::Table::Field::DECIMAL:
 
175
    return DECIMAL;
 
176
  case message::Table::Field::DATE:
 
177
    return DATE;
 
178
  case message::Table::Field::EPOCH:
 
179
    return EPOCH;
 
180
  case message::Table::Field::DATETIME:
 
181
    return DATETIME;
 
182
  case message::Table::Field::TIME:
 
183
    return TIME;
 
184
  case message::Table::Field::UUID:
 
185
    return UUID;
 
186
  case message::Table::Field::BOOLEAN:
 
187
    return BOOLEAN;
 
188
  }
 
189
 
 
190
  abort();
 
191
}
 
192
 
 
193
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
 
194
{
 
195
  switch (type)
 
196
  {
 
197
  case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
 
198
    return RESTRICT;
 
199
  case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
 
200
    return CASCADE;
 
201
  case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
 
202
    return SET_NULL;
 
203
  case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
 
204
  case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
 
205
    return NO_ACTION;
 
206
  case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
 
207
    return SET_DEFAULT;
 
208
  }
 
209
 
 
210
  return NO_ACTION;
 
211
}
 
212
 
 
213
// This matches SQL standard of using YES/NO not the normal TRUE/FALSE
 
214
const std::string &type(bool type)
 
215
{
 
216
  return type ? YES : NO;
 
217
}
 
218
 
 
219
const std::string &type(drizzled::message::Table::Index::IndexType type)
 
220
{
 
221
  switch (type)
 
222
  {
 
223
  case message::Table::Index::UNKNOWN_INDEX:
 
224
    return UNKNOWN_INDEX;
 
225
  case message::Table::Index::BTREE:
 
226
    return BTREE;
 
227
  case message::Table::Index::RTREE:
 
228
    return RTREE;
 
229
  case message::Table::Index::HASH:
 
230
    return HASH;
 
231
  case message::Table::Index::FULLTEXT:
 
232
    return FULLTEXT;
 
233
  }
 
234
 
 
235
  assert(0);
 
236
  return PROGRAM_ERROR;
 
237
}
 
238
 
 
239
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
 
240
{
 
241
  switch (type)
 
242
  {
 
243
  case message::Table::ForeignKeyConstraint::MATCH_FULL:
 
244
    return MATCH_FULL;
 
245
  case message::Table::ForeignKeyConstraint::MATCH_PARTIAL:
 
246
    return MATCH_PARTIAL;
 
247
  case message::Table::ForeignKeyConstraint::MATCH_UNDEFINED:
 
248
  case message::Table::ForeignKeyConstraint::MATCH_SIMPLE:
 
249
    return MATCH_SIMPLE;
 
250
  }
 
251
 
 
252
  return MATCH_SIMPLE;
 
253
}
 
254
 
 
255
const std::string &type(drizzled::message::Table::TableType type)
 
256
{
 
257
  switch (type)
 
258
  {
 
259
  case message::Table::STANDARD:
 
260
    return STANDARD_STRING;
 
261
  case message::Table::TEMPORARY:
 
262
    return TEMPORARY_STRING;
 
263
  case message::Table::INTERNAL:
 
264
    return INTERNAL_STRING;
 
265
  case message::Table::FUNCTION:
 
266
    return FUNCTION_STRING;
 
267
  }
 
268
 
 
269
  assert(0);
 
270
  return PROGRAM_ERROR;
 
271
}
 
272
 
 
273
#if 0
 
274
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
 
275
 
276
    std::string buffer;
 
277
 
 
278
    google::protobuf::TextFormat::PrintToString(message, &buffer);
 
279
    output << buffer;
 
280
 
 
281
    return output;
 
282
}
 
283
 
 
284
std::ostream& operator<<(std::ostream& output, const message::Table &message)
 
285
 
286
  std::string buffer;
 
287
 
 
288
  google::protobuf::TextFormat::PrintToString(message, &buffer);
 
289
  output << buffer;
 
290
 
 
291
  return output;
 
292
}
 
293
#endif
 
294
 
 
295
 
 
296
} /* namespace message */
 
297
} /* namespace drizzled */