~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message.cc

  • Committer: Stewart Smith
  • Date: 2011-01-14 05:09:04 UTC
  • mto: (2086.1.3 build)
  • mto: This revision was merged to the branch mainline in revision 2087.
  • Revision ID: stewart@flamingspork.com-20110114050904-a98kswwpqnpl413s
add a bit of a note on how variables docs should be expanded

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include "drizzled/message/schema.pb.h"
31
31
 
32
32
#include <string>
33
 
#include <uuid/uuid.h>
34
33
 
35
34
namespace drizzled {
36
35
namespace message {
39
38
 
40
39
// These are used to generate strings for types
41
40
static const std::string VARCHAR("VARCHAR");
 
41
static const std::string VARBINARY("VARBINARY");
42
42
static const std::string DOUBLE("DOUBLE");
 
43
static const std::string TEXT("TEXT");
43
44
static const std::string BLOB("BLOB");
44
45
static const std::string ENUM("ENUM");
45
46
static const std::string INTEGER("INTEGER");
46
47
static const std::string BIGINT("BIGINT");
47
48
static const std::string DECIMAL("DECIMAL");
48
49
static const std::string DATE("DATE");
 
50
static const std::string EPOCH("EPOCH");
49
51
static const std::string TIMESTAMP("TIMESTAMP");
 
52
static const std::string MICROTIME("MICROTIME");
50
53
static const std::string DATETIME("DATETIME");
 
54
static const std::string TIME("TIME");
51
55
static const std::string UUID("UUID");
 
56
static const std::string BOOLEAN("BOOLEAN");
52
57
 
53
58
static const std::string UNDEFINED("UNDEFINED");
54
59
static const std::string RESTRICT("RESTRICT");
70
75
static const std::string MATCH_PARTIAL("PARTIAL");
71
76
static const std::string MATCH_SIMPLE("SIMPLE");
72
77
 
73
 
void init(drizzled::message::Table &arg, const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg)
74
 
{
75
 
  arg.set_name(name_arg);
76
 
  arg.set_schema(schema_arg);
77
 
  arg.set_creation_timestamp(time(NULL));
78
 
  arg.set_update_timestamp(time(NULL));
79
 
  arg.mutable_engine()->set_name(engine_arg);
80
 
 
81
 
  /* 36 characters for uuid string +1 for NULL */
82
 
  uuid_t uu;
83
 
  char uuid_string[37];
84
 
  uuid_generate_random(uu);
85
 
  uuid_unparse(uu, uuid_string);
86
 
  arg.set_uuid(uuid_string, 36);
87
 
 
88
 
  arg.set_version(1);
89
 
}
90
 
 
91
 
void init(drizzled::message::Schema &arg, const std::string &name_arg)
92
 
{
93
 
  arg.set_name(name_arg);
94
 
  arg.mutable_engine()->set_name(std::string("filesystem")); // For the moment we have only one.
95
 
  if (not arg.has_collation())
96
 
  {
97
 
    arg.set_collation(default_charset_info->name);
98
 
  }
99
 
 
100
 
  /* 36 characters for uuid string +1 for NULL */
101
 
  uuid_t uu;
102
 
  char uuid_string[37];
103
 
  uuid_generate_random(uu);
104
 
  uuid_unparse(uu, uuid_string);
105
 
  arg.set_uuid(uuid_string, 36);
106
 
 
107
 
  arg.set_version(1);
108
 
}
109
 
 
110
78
void update(drizzled::message::Schema &arg)
111
79
{
112
80
  arg.set_version(arg.version() + 1);
119
87
  arg.set_update_timestamp(time(NULL));
120
88
}
121
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
 
122
153
const std::string &type(drizzled::message::Table::Field::FieldType type)
123
154
{
124
155
  switch (type)
139
170
    return DECIMAL;
140
171
  case message::Table::Field::DATE:
141
172
    return DATE;
142
 
  case message::Table::Field::TIMESTAMP:
143
 
    return TIMESTAMP;
 
173
  case message::Table::Field::EPOCH:
 
174
    return EPOCH;
144
175
  case message::Table::Field::DATETIME:
145
176
    return DATETIME;
 
177
  case message::Table::Field::TIME:
 
178
    return TIME;
146
179
  case message::Table::Field::UUID:
147
180
    return UUID;
 
181
  case message::Table::Field::BOOLEAN:
 
182
    return BOOLEAN;
148
183
  }
149
184
 
150
 
  assert(0);
151
 
  return PROGRAM_ERROR;
 
185
  abort();
152
186
}
153
187
 
154
188
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)