~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message.cc

  • Committer: Brian Aker
  • Date: 2011-02-22 06:12:02 UTC
  • mfrom: (2190.1.6 drizzle-build)
  • Revision ID: brian@tangent.org-20110222061202-k03czxykqy4x9hjs
List update, header fixes, multiple symbols, and David deletes some code.

Show diffs side-by-side

added added

removed removed

Lines of Context:
18
18
 *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
19
19
 */
20
20
 
21
 
#include "config.h"
 
21
#include <config.h>
22
22
 
23
23
#include <drizzled/show.h>
24
24
#include <drizzled/session.h>
25
 
#include <drizzled/db.h>
 
25
#include <drizzled/schema.h>
26
26
#include <drizzled/plugin/event_observer.h>
27
27
#include <drizzled/message.h>
28
28
 
29
 
#include "drizzled/message/table.pb.h"
30
 
#include "drizzled/message/schema.pb.h"
 
29
#include <drizzled/message/table.pb.h>
 
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
 
}
 
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");
109
82
 
110
83
void update(drizzled::message::Schema &arg)
111
84
{
119
92
  arg.set_update_timestamp(time(NULL));
120
93
}
121
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
 
122
158
const std::string &type(drizzled::message::Table::Field::FieldType type)
123
159
{
124
160
  switch (type)
139
175
    return DECIMAL;
140
176
  case message::Table::Field::DATE:
141
177
    return DATE;
142
 
  case message::Table::Field::TIMESTAMP:
143
 
    return TIMESTAMP;
 
178
  case message::Table::Field::EPOCH:
 
179
    return EPOCH;
144
180
  case message::Table::Field::DATETIME:
145
181
    return DATETIME;
 
182
  case message::Table::Field::TIME:
 
183
    return TIME;
146
184
  case message::Table::Field::UUID:
147
185
    return UUID;
 
186
  case message::Table::Field::BOOLEAN:
 
187
    return BOOLEAN;
148
188
  }
149
189
 
150
 
  assert(0);
151
 
  return PROGRAM_ERROR;
 
190
  abort();
152
191
}
153
192
 
154
193
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
213
252
  return MATCH_SIMPLE;
214
253
}
215
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
 
216
273
#if 0
217
274
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
218
275