~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/message.cc

  • Committer: Lee Bieber
  • Date: 2010-11-20 22:04:04 UTC
  • mfrom: (1942.1.4 b)
  • Revision ID: kalebral@gmail.com-20101120220404-2qpb4xuik9wv9u1q
Merge Lee -  Run bzr ignore for leftover files
Merge Shrews - Add a --replicate-query option to the server which controls whether or not the SQL query string is included in the GPB Statement messages.
Merge Andrew - fix bug 665119: drizzleslap has -i mapped to two options
Merge Andrew fix bug 674145: Table Names Not Case Matched

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>
33
34
 
34
35
namespace drizzled {
35
36
namespace message {
38
39
 
39
40
// These are used to generate strings for types
40
41
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");
44
43
static const std::string BLOB("BLOB");
45
44
static const std::string ENUM("ENUM");
46
45
static const std::string INTEGER("INTEGER");
47
46
static const std::string BIGINT("BIGINT");
48
47
static const std::string DECIMAL("DECIMAL");
49
48
static const std::string DATE("DATE");
50
 
static const std::string EPOCH("EPOCH");
51
49
static const std::string TIMESTAMP("TIMESTAMP");
52
 
static const std::string MICROTIME("MICROTIME");
53
50
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
51
 
58
52
static const std::string UNDEFINED("UNDEFINED");
59
53
static const std::string RESTRICT("RESTRICT");
75
69
static const std::string MATCH_PARTIAL("PARTIAL");
76
70
static const std::string MATCH_SIMPLE("SIMPLE");
77
71
 
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");
 
72
void init(drizzled::message::Table &arg, const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg)
 
73
{
 
74
  arg.set_name(name_arg);
 
75
  arg.set_schema(schema_arg);
 
76
  arg.set_creation_timestamp(time(NULL));
 
77
  arg.set_update_timestamp(time(NULL));
 
78
  arg.mutable_engine()->set_name(engine_arg);
 
79
 
 
80
  /* 36 characters for uuid string +1 for NULL */
 
81
  uuid_t uu;
 
82
  char uuid_string[37];
 
83
  uuid_generate_random(uu);
 
84
  uuid_unparse(uu, uuid_string);
 
85
  arg.set_uuid(uuid_string, 36);
 
86
 
 
87
  arg.set_version(1);
 
88
}
 
89
 
 
90
void init(drizzled::message::Schema &arg, const std::string &name_arg)
 
91
{
 
92
  arg.set_name(name_arg);
 
93
  arg.mutable_engine()->set_name(std::string("filesystem")); // For the moment we have only one.
 
94
  if (not arg.has_collation())
 
95
  {
 
96
    arg.set_collation(default_charset_info->name);
 
97
  }
 
98
 
 
99
  /* 36 characters for uuid string +1 for NULL */
 
100
  uuid_t uu;
 
101
  char uuid_string[37];
 
102
  uuid_generate_random(uu);
 
103
  uuid_unparse(uu, uuid_string);
 
104
  arg.set_uuid(uuid_string, 36);
 
105
 
 
106
  arg.set_version(1);
 
107
}
82
108
 
83
109
void update(drizzled::message::Schema &arg)
84
110
{
92
118
  arg.set_update_timestamp(time(NULL));
93
119
}
94
120
 
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
121
const std::string &type(drizzled::message::Table::Field::FieldType type)
159
122
{
160
123
  switch (type)
175
138
    return DECIMAL;
176
139
  case message::Table::Field::DATE:
177
140
    return DATE;
178
 
  case message::Table::Field::EPOCH:
179
 
    return EPOCH;
 
141
  case message::Table::Field::TIMESTAMP:
 
142
    return TIMESTAMP;
180
143
  case message::Table::Field::DATETIME:
181
144
    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
145
  }
189
146
 
190
 
  abort();
 
147
  assert(0);
 
148
  return PROGRAM_ERROR;
191
149
}
192
150
 
193
151
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
252
210
  return MATCH_SIMPLE;
253
211
}
254
212
 
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
213
#if 0
274
214
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
275
215