drizzle
C++ MySQL-protocol-compatible database server
Loading...
Searching...
No Matches
message.cc
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/schema.h>
26#include <drizzled/plugin/event_observer.h>
27#include <drizzled/message.h>
28
29#include <string>
30
31namespace drizzled {
32namespace message {
33
34static const std::string PROGRAM_ERROR("PROGRAM_ERROR");
35
36// These are used to generate strings for types
37static const std::string VARCHAR("VARCHAR");
38static const std::string VARBINARY("VARBINARY");
39static const std::string DOUBLE("DOUBLE");
40static const std::string TEXT("TEXT");
41static const std::string BLOB("BLOB");
42static const std::string ENUM("ENUM");
43static const std::string INTEGER("INTEGER");
44static const std::string BIGINT("BIGINT");
45static const std::string DECIMAL("DECIMAL");
46static const std::string DATE("DATE");
47static const std::string EPOCH("EPOCH");
48static const std::string TIMESTAMP("TIMESTAMP");
49static const std::string MICROTIME("MICROTIME");
50static const std::string DATETIME("DATETIME");
51static const std::string TIME("TIME");
52static const std::string UUID("UUID");
53static const std::string BOOLEAN("BOOLEAN");
54static const std::string IPV6("IPV6");
55
56static const std::string UNDEFINED("UNDEFINED");
57static const std::string RESTRICT("RESTRICT");
58static const std::string CASCADE("CASCADE");
59static const std::string SET_NULL("SET NULL");
60static const std::string NO_ACTION("NO ACTION");
61static const std::string SET_DEFAULT("SET DEFAULT");
62
63static const std::string YES("YES");
64static const std::string NO("NO");
65
66static const std::string UNKNOWN_INDEX("UNKNOWN_INDEX");
67static const std::string BTREE("BTREE");
68static const std::string RTREE("RTREE");
69static const std::string HASH("HASH");
70static const std::string FULLTEXT("FULLTEXT");
71static const std::string LSMTREE("LSMTREE");
72
73static const std::string MATCH_FULL("FULL");
74static const std::string MATCH_PARTIAL("PARTIAL");
75static const std::string MATCH_SIMPLE("SIMPLE");
76
77const static std::string STANDARD_STRING("STANDARD");
78const static std::string TEMPORARY_STRING("TEMPORARY");
79const static std::string INTERNAL_STRING("INTERNAL");
80const static std::string FUNCTION_STRING("FUNCTION");
81
82void update(drizzled::message::Schema &arg)
83{
84 arg.set_version(arg.version() + 1);
85 arg.set_update_timestamp(time(NULL));
86}
87
88void update(drizzled::message::Table &arg)
89{
90 arg.set_version(arg.version() + 1);
91 arg.set_update_timestamp(time(NULL));
92}
93
94bool is_numeric(const message::Table::Field &field)
95{
96 message::Table::Field::FieldType type= field.type();
97
98 switch (type)
99 {
100 case message::Table::Field::DOUBLE:
101 case message::Table::Field::INTEGER:
102 case message::Table::Field::BIGINT:
103 case message::Table::Field::DECIMAL:
104 return true;
105 case message::Table::Field::BLOB:
106 case message::Table::Field::VARCHAR:
107 case message::Table::Field::ENUM:
108 case message::Table::Field::DATE:
109 case message::Table::Field::EPOCH:
110 case message::Table::Field::DATETIME:
111 case message::Table::Field::TIME:
112 case message::Table::Field::UUID:
113 case message::Table::Field::BOOLEAN:
114 case message::Table::Field::IPV6:
115 break;
116 }
117
118 return false;
119}
120
121const 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 case message::Table::Field::IPV6:
154 return IPV6;
155 }
156
157 abort();
158}
159
160const std::string &type(drizzled::message::Table::Field::FieldType type)
161{
162 switch (type)
163 {
164 case message::Table::Field::VARCHAR:
165 return VARCHAR;
166 case message::Table::Field::DOUBLE:
167 return DOUBLE;
168 case message::Table::Field::BLOB:
169 return BLOB;
170 case message::Table::Field::ENUM:
171 return ENUM;
172 case message::Table::Field::INTEGER:
173 return INTEGER;
174 case message::Table::Field::BIGINT:
175 return BIGINT;
176 case message::Table::Field::DECIMAL:
177 return DECIMAL;
178 case message::Table::Field::DATE:
179 return DATE;
180 case message::Table::Field::EPOCH:
181 return EPOCH;
182 case message::Table::Field::DATETIME:
183 return DATETIME;
184 case message::Table::Field::TIME:
185 return TIME;
186 case message::Table::Field::UUID:
187 return UUID;
188 case message::Table::Field::BOOLEAN:
189 return BOOLEAN;
190 case message::Table::Field::IPV6:
191 return IPV6;
192 }
193
194 abort();
195}
196
197const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
198{
199 switch (type)
200 {
201 case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
202 return RESTRICT;
203 case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
204 return CASCADE;
205 case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
206 return SET_NULL;
207 case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
208 case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
209 return NO_ACTION;
210 case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
211 return SET_DEFAULT;
212 }
213
214 return NO_ACTION;
215}
216
217const std::string &type(drizzled::message::Table::Index::IndexType type)
218{
219 switch (type)
220 {
221 case message::Table::Index::UNKNOWN_INDEX:
222 return UNKNOWN_INDEX;
223 case message::Table::Index::BTREE:
224 return BTREE;
225 case message::Table::Index::RTREE:
226 return RTREE;
227 case message::Table::Index::HASH:
228 return HASH;
229 case message::Table::Index::FULLTEXT:
230 return FULLTEXT;
231 case message::Table::Index::LSMTREE:
232 return LSMTREE;
233 }
234
235 assert(0);
236 return PROGRAM_ERROR;
237}
238
239const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
240{
241 switch (type)
242 {
243 case message::Table::ForeignKeyConstraint::MATCH_FULL:
244 return MATCH_FULL;
245 case message::Table::ForeignKeyConstraint::MATCH_PARTIAL:
246 return MATCH_PARTIAL;
247 case message::Table::ForeignKeyConstraint::MATCH_UNDEFINED:
248 case message::Table::ForeignKeyConstraint::MATCH_SIMPLE:
249 return MATCH_SIMPLE;
250 }
251
252 return MATCH_SIMPLE;
253}
254
255const 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#if 0
274std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
275{
276 std::string buffer;
277
278 google::protobuf::TextFormat::PrintToString(message, &buffer);
279 output << buffer;
280
281 return output;
282}
283
284std::ostream& operator<<(std::ostream& output, const message::Table &message)
285{
286 std::string buffer;
287
288 google::protobuf::TextFormat::PrintToString(message, &buffer);
289 output << buffer;
290
291 return output;
292}
293#endif
294
295
296} /* namespace message */
297} /* namespace drizzled */
TODO: Rename this file - func.h is stupid.