~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message.cc

merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
 
29
29
#include "drizzled/message/table.pb.h"
30
30
#include "drizzled/message/schema.pb.h"
 
31
 
 
32
#include <string>
31
33
#include <uuid/uuid.h>
32
34
 
33
35
namespace drizzled {
34
36
namespace message {
35
37
 
 
38
static const std::string PROGRAM_ERROR("PROGRAM_ERROR");
 
39
 
 
40
// These are used to generate strings for types
 
41
static const std::string VARCHAR("VARCHAR");
 
42
static const std::string DOUBLE("DOUBLE");
 
43
static const std::string BLOB("BLOB");
 
44
static const std::string ENUM("ENUM");
 
45
static const std::string INTEGER("INTEGER");
 
46
static const std::string BIGINT("BIGINT");
 
47
static const std::string DECIMAL("DECIMAL");
 
48
static const std::string DATE("DATE");
 
49
static const std::string TIMESTAMP("TIMESTAMP");
 
50
static const std::string DATETIME("DATETIME");
 
51
 
 
52
static const std::string UNDEFINED("UNDEFINED");
 
53
static const std::string RESTRICT("RESTRICT");
 
54
static const std::string CASCADE("CASCADE");
 
55
static const std::string SET_NULL("SET NULL");
 
56
static const std::string NO_ACTION("NO ACTION");
 
57
static const std::string SET_DEFAULT("SET DEFAULT");
 
58
 
 
59
static const std::string YES("YES");
 
60
static const std::string NO("NO");
 
61
 
 
62
static const std::string UNKNOWN_INDEX("UNKNOWN_INDEX");
 
63
static const std::string BTREE("BTREE");
 
64
static const std::string RTREE("RTREE");
 
65
static const std::string HASH("HASH");
 
66
static const std::string FULLTEXT("FULLTEXT");
 
67
 
 
68
static const std::string MATCH_FULL("FULL");
 
69
static const std::string MATCH_PARTIAL("PARTIAL");
 
70
static const std::string MATCH_SIMPLE("SIMPLE");
 
71
 
36
72
void init(drizzled::message::Table &arg, const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg)
37
73
{
38
74
  arg.set_name(name_arg);
82
118
  arg.set_update_timestamp(time(NULL));
83
119
}
84
120
 
 
121
const std::string &type(drizzled::message::Table::Field::FieldType type)
 
122
{
 
123
  switch (type)
 
124
  {
 
125
  case message::Table::Field::VARCHAR:
 
126
    return VARCHAR;
 
127
  case message::Table::Field::DOUBLE:
 
128
    return DOUBLE;
 
129
  case message::Table::Field::BLOB:
 
130
    return BLOB;
 
131
  case message::Table::Field::ENUM:
 
132
    return ENUM;
 
133
  case message::Table::Field::INTEGER:
 
134
    return INTEGER;
 
135
  case message::Table::Field::BIGINT:
 
136
    return BIGINT;
 
137
  case message::Table::Field::DECIMAL:
 
138
    return DECIMAL;
 
139
  case message::Table::Field::DATE:
 
140
    return DATE;
 
141
  case message::Table::Field::TIMESTAMP:
 
142
    return TIMESTAMP;
 
143
  case message::Table::Field::DATETIME:
 
144
    return DATETIME;
 
145
  }
 
146
 
 
147
  assert(0);
 
148
  return PROGRAM_ERROR;
 
149
}
 
150
 
 
151
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
 
152
{
 
153
  switch (type)
 
154
  {
 
155
  case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
 
156
    return RESTRICT;
 
157
  case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
 
158
    return CASCADE;
 
159
  case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
 
160
    return SET_NULL;
 
161
  case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
 
162
  case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
 
163
    return NO_ACTION;
 
164
  case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
 
165
    return SET_DEFAULT;
 
166
  }
 
167
 
 
168
  return NO_ACTION;
 
169
}
 
170
 
 
171
// This matches SQL standard of using YES/NO not the normal TRUE/FALSE
 
172
const std::string &type(bool type)
 
173
{
 
174
  return type ? YES : NO;
 
175
}
 
176
 
 
177
const std::string &type(drizzled::message::Table::Index::IndexType type)
 
178
{
 
179
  switch (type)
 
180
  {
 
181
  case message::Table::Index::UNKNOWN_INDEX:
 
182
    return UNKNOWN_INDEX;
 
183
  case message::Table::Index::BTREE:
 
184
    return BTREE;
 
185
  case message::Table::Index::RTREE:
 
186
    return RTREE;
 
187
  case message::Table::Index::HASH:
 
188
    return HASH;
 
189
  case message::Table::Index::FULLTEXT:
 
190
    return FULLTEXT;
 
191
  }
 
192
 
 
193
  assert(0);
 
194
  return PROGRAM_ERROR;
 
195
}
 
196
 
 
197
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
 
198
{
 
199
  switch (type)
 
200
  {
 
201
  case message::Table::ForeignKeyConstraint::MATCH_FULL:
 
202
    return MATCH_FULL;
 
203
  case message::Table::ForeignKeyConstraint::MATCH_PARTIAL:
 
204
    return MATCH_PARTIAL;
 
205
  case message::Table::ForeignKeyConstraint::MATCH_UNDEFINED:
 
206
  case message::Table::ForeignKeyConstraint::MATCH_SIMPLE:
 
207
    return MATCH_SIMPLE;
 
208
  }
 
209
 
 
210
  return MATCH_SIMPLE;
 
211
}
 
212
 
85
213
} /* namespace message */
86
214
} /* namespace drizzled */