~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message.cc

  • Committer: Patrick Crews
  • Date: 2011-01-29 14:17:35 UTC
  • mto: (2126.1.1 build)
  • mto: This revision was merged to the branch mainline in revision 2127.
  • Revision ID: gleebix@gmail.com-20110129141735-3y2658vt5ur0a33o
Fixes to make test-dbqp

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
void update(drizzled::message::Schema &arg)
 
79
{
 
80
  arg.set_version(arg.version() + 1);
 
81
  arg.set_update_timestamp(time(NULL));
 
82
}
 
83
 
 
84
void update(drizzled::message::Table &arg)
 
85
{
 
86
  arg.set_version(arg.version() + 1);
 
87
  arg.set_update_timestamp(time(NULL));
 
88
}
 
89
 
 
90
bool is_numeric(const message::Table::Field &field)
 
91
{
 
92
  message::Table::Field::FieldType type= field.type();
 
93
 
 
94
  switch (type)
 
95
  {
 
96
  case message::Table::Field::DOUBLE:
 
97
  case message::Table::Field::INTEGER:
 
98
  case message::Table::Field::BIGINT:
 
99
  case message::Table::Field::DECIMAL:
 
100
    return true;
 
101
  case message::Table::Field::BLOB:
 
102
  case message::Table::Field::VARCHAR:
 
103
  case message::Table::Field::ENUM:
 
104
  case message::Table::Field::DATE:
 
105
  case message::Table::Field::EPOCH:
 
106
  case message::Table::Field::DATETIME:
 
107
  case message::Table::Field::TIME:
 
108
  case message::Table::Field::UUID:
 
109
  case message::Table::Field::BOOLEAN:
 
110
    break;
 
111
  }
 
112
 
 
113
  return false;
 
114
}
 
115
 
 
116
const std::string &type(const message::Table::Field &field)
 
117
{
 
118
  message::Table::Field::FieldType type= field.type();
 
119
 
 
120
  switch (type)
 
121
  {
 
122
  case message::Table::Field::VARCHAR:
 
123
    return field.string_options().collation().compare("binary") ? VARCHAR : VARBINARY;
 
124
  case message::Table::Field::DOUBLE:
 
125
    return DOUBLE;
 
126
  case message::Table::Field::BLOB:
 
127
    return field.string_options().collation().compare("binary") ? TEXT : BLOB;
 
128
  case message::Table::Field::ENUM:
 
129
    return ENUM;
 
130
  case message::Table::Field::INTEGER:
 
131
    return INTEGER;
 
132
  case message::Table::Field::BIGINT:
 
133
    return BIGINT;
 
134
  case message::Table::Field::DECIMAL:
 
135
    return DECIMAL;
 
136
  case message::Table::Field::DATE:
 
137
    return DATE;
 
138
  case message::Table::Field::EPOCH:
 
139
    return TIMESTAMP;
 
140
  case message::Table::Field::DATETIME:
 
141
    return DATETIME;
 
142
  case message::Table::Field::TIME:
 
143
    return TIME;
 
144
  case message::Table::Field::UUID:
 
145
    return UUID;
 
146
  case message::Table::Field::BOOLEAN:
 
147
    return BOOLEAN;
 
148
  }
 
149
 
 
150
  abort();
 
151
}
 
152
 
 
153
const std::string &type(drizzled::message::Table::Field::FieldType type)
 
154
{
 
155
  switch (type)
 
156
  {
 
157
  case message::Table::Field::VARCHAR:
 
158
    return VARCHAR;
 
159
  case message::Table::Field::DOUBLE:
 
160
    return DOUBLE;
 
161
  case message::Table::Field::BLOB:
 
162
    return BLOB;
 
163
  case message::Table::Field::ENUM:
 
164
    return ENUM;
 
165
  case message::Table::Field::INTEGER:
 
166
    return INTEGER;
 
167
  case message::Table::Field::BIGINT:
 
168
    return BIGINT;
 
169
  case message::Table::Field::DECIMAL:
 
170
    return DECIMAL;
 
171
  case message::Table::Field::DATE:
 
172
    return DATE;
 
173
  case message::Table::Field::EPOCH:
 
174
    return EPOCH;
 
175
  case message::Table::Field::DATETIME:
 
176
    return DATETIME;
 
177
  case message::Table::Field::TIME:
 
178
    return TIME;
 
179
  case message::Table::Field::UUID:
 
180
    return UUID;
 
181
  case message::Table::Field::BOOLEAN:
 
182
    return BOOLEAN;
 
183
  }
 
184
 
 
185
  abort();
 
186
}
 
187
 
 
188
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
 
189
{
 
190
  switch (type)
 
191
  {
 
192
  case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
 
193
    return RESTRICT;
 
194
  case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
 
195
    return CASCADE;
 
196
  case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
 
197
    return SET_NULL;
 
198
  case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
 
199
  case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
 
200
    return NO_ACTION;
 
201
  case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
 
202
    return SET_DEFAULT;
 
203
  }
 
204
 
 
205
  return NO_ACTION;
 
206
}
 
207
 
 
208
// This matches SQL standard of using YES/NO not the normal TRUE/FALSE
 
209
const std::string &type(bool type)
 
210
{
 
211
  return type ? YES : NO;
 
212
}
 
213
 
 
214
const std::string &type(drizzled::message::Table::Index::IndexType type)
 
215
{
 
216
  switch (type)
 
217
  {
 
218
  case message::Table::Index::UNKNOWN_INDEX:
 
219
    return UNKNOWN_INDEX;
 
220
  case message::Table::Index::BTREE:
 
221
    return BTREE;
 
222
  case message::Table::Index::RTREE:
 
223
    return RTREE;
 
224
  case message::Table::Index::HASH:
 
225
    return HASH;
 
226
  case message::Table::Index::FULLTEXT:
 
227
    return FULLTEXT;
 
228
  }
 
229
 
 
230
  assert(0);
 
231
  return PROGRAM_ERROR;
 
232
}
 
233
 
 
234
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
 
235
{
 
236
  switch (type)
 
237
  {
 
238
  case message::Table::ForeignKeyConstraint::MATCH_FULL:
 
239
    return MATCH_FULL;
 
240
  case message::Table::ForeignKeyConstraint::MATCH_PARTIAL:
 
241
    return MATCH_PARTIAL;
 
242
  case message::Table::ForeignKeyConstraint::MATCH_UNDEFINED:
 
243
  case message::Table::ForeignKeyConstraint::MATCH_SIMPLE:
 
244
    return MATCH_SIMPLE;
 
245
  }
 
246
 
 
247
  return MATCH_SIMPLE;
 
248
}
 
249
 
 
250
#if 0
 
251
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
 
252
 
253
    std::string buffer;
 
254
 
 
255
    google::protobuf::TextFormat::PrintToString(message, &buffer);
 
256
    output << buffer;
 
257
 
 
258
    return output;
 
259
}
 
260
 
 
261
std::ostream& operator<<(std::ostream& output, const message::Table &message)
 
262
 
263
  std::string buffer;
 
264
 
 
265
  google::protobuf::TextFormat::PrintToString(message, &buffer);
 
266
  output << buffer;
 
267
 
 
268
  return output;
 
269
}
 
270
#endif
 
271
 
 
272
 
 
273
} /* namespace message */
 
274
} /* namespace drizzled */