~drizzle-trunk/drizzle/development

1802.12.1 by Brian Aker
This solves bug lp:654905
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"
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
31
32
#include <string>
1802.12.1 by Brian Aker
This solves bug lp:654905
33
#include <uuid/uuid.h>
34
35
namespace drizzled {
36
namespace message {
37
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
38
static const std::string PROGRAM_ERROR("PROGRAM_ERROR");
39
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
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");
1996.2.1 by Brian Aker
uuid type code.
51
static const std::string UUID("UUID");
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
52
53
static const std::string UNDEFINED("UNDEFINED");
54
static const std::string RESTRICT("RESTRICT");
55
static const std::string CASCADE("CASCADE");
56
static const std::string SET_NULL("SET NULL");
57
static const std::string NO_ACTION("NO ACTION");
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
58
static const std::string SET_DEFAULT("SET DEFAULT");
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
59
60
static const std::string YES("YES");
61
static const std::string NO("NO");
62
63
static const std::string UNKNOWN_INDEX("UNKNOWN_INDEX");
64
static const std::string BTREE("BTREE");
65
static const std::string RTREE("RTREE");
66
static const std::string HASH("HASH");
67
static const std::string FULLTEXT("FULLTEXT");
68
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
69
static const std::string MATCH_FULL("FULL");
70
static const std::string MATCH_PARTIAL("PARTIAL");
71
static const std::string MATCH_SIMPLE("SIMPLE");
72
1802.12.1 by Brian Aker
This solves bug lp:654905
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
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
110
void update(drizzled::message::Schema &arg)
111
{
112
  arg.set_version(arg.version() + 1);
113
  arg.set_update_timestamp(time(NULL));
114
}
115
116
void update(drizzled::message::Table &arg)
117
{
118
  arg.set_version(arg.version() + 1);
119
  arg.set_update_timestamp(time(NULL));
120
}
121
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
122
const std::string &type(drizzled::message::Table::Field::FieldType type)
123
{
124
  switch (type)
125
  {
126
  case message::Table::Field::VARCHAR:
127
    return VARCHAR;
128
  case message::Table::Field::DOUBLE:
129
    return DOUBLE;
130
  case message::Table::Field::BLOB:
131
    return BLOB;
132
  case message::Table::Field::ENUM:
133
    return ENUM;
134
  case message::Table::Field::INTEGER:
135
    return INTEGER;
136
  case message::Table::Field::BIGINT:
137
    return BIGINT;
138
  case message::Table::Field::DECIMAL:
139
    return DECIMAL;
140
  case message::Table::Field::DATE:
141
    return DATE;
142
  case message::Table::Field::TIMESTAMP:
143
    return TIMESTAMP;
144
  case message::Table::Field::DATETIME:
145
    return DATETIME;
1996.2.1 by Brian Aker
uuid type code.
146
  case message::Table::Field::UUID:
147
    return UUID;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
148
  }
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
149
150
  assert(0);
151
  return PROGRAM_ERROR;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
152
}
153
154
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
155
{
156
  switch (type)
157
  {
158
  case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
159
    return RESTRICT;
160
  case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
161
    return CASCADE;
162
  case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
163
    return SET_NULL;
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
164
  case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
165
  case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
166
    return NO_ACTION;
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
167
  case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
168
    return SET_DEFAULT;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
169
  }
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
170
171
  return NO_ACTION;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
172
}
173
174
// This matches SQL standard of using YES/NO not the normal TRUE/FALSE
175
const std::string &type(bool type)
176
{
177
  return type ? YES : NO;
178
}
179
180
const std::string &type(drizzled::message::Table::Index::IndexType type)
181
{
182
  switch (type)
183
  {
184
  case message::Table::Index::UNKNOWN_INDEX:
185
    return UNKNOWN_INDEX;
186
  case message::Table::Index::BTREE:
187
    return BTREE;
188
  case message::Table::Index::RTREE:
189
    return RTREE;
190
  case message::Table::Index::HASH:
191
    return HASH;
192
  case message::Table::Index::FULLTEXT:
193
    return FULLTEXT;
194
  }
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
195
196
  assert(0);
197
  return PROGRAM_ERROR;
198
}
199
200
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
201
{
202
  switch (type)
203
  {
204
  case message::Table::ForeignKeyConstraint::MATCH_FULL:
205
    return MATCH_FULL;
206
  case message::Table::ForeignKeyConstraint::MATCH_PARTIAL:
207
    return MATCH_PARTIAL;
208
  case message::Table::ForeignKeyConstraint::MATCH_UNDEFINED:
209
  case message::Table::ForeignKeyConstraint::MATCH_SIMPLE:
210
    return MATCH_SIMPLE;
211
  }
212
213
  return MATCH_SIMPLE;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
214
}
215
1921.1.2 by Brian Aker
Remove print helper methods.
216
#if 0
1910.2.12 by Brian Aker
Adding operators to print table, transaction.
217
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
218
{ 
219
    std::string buffer;
220
221
    google::protobuf::TextFormat::PrintToString(message, &buffer);
222
    output << buffer;
223
224
    return output;
225
}
226
227
std::ostream& operator<<(std::ostream& output, const message::Table &message)
228
{ 
229
  std::string buffer;
230
231
  google::protobuf::TextFormat::PrintToString(message, &buffer);
232
  output << buffer;
233
234
  return output;
235
}
1921.1.2 by Brian Aker
Remove print helper methods.
236
#endif
1910.2.12 by Brian Aker
Adding operators to print table, transaction.
237
238
1802.12.1 by Brian Aker
This solves bug lp:654905
239
} /* namespace message */
240
} /* namespace drizzled */