1
/* - mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Brian Aker
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.
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.
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
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>
29
#include "drizzled/message/table.pb.h"
30
#include "drizzled/message/schema.pb.h"
37
static const std::string PROGRAM_ERROR("PROGRAM_ERROR");
39
// These are used to generate strings for types
40
static const std::string VARCHAR("VARCHAR");
41
static const std::string VARBINARY("VARBINARY");
42
static const std::string DOUBLE("DOUBLE");
43
static const std::string TEXT("TEXT");
44
static const std::string BLOB("BLOB");
45
static const std::string ENUM("ENUM");
46
static const std::string INTEGER("INTEGER");
47
static const std::string BIGINT("BIGINT");
48
static const std::string DECIMAL("DECIMAL");
49
static const std::string DATE("DATE");
50
static const std::string EPOCH("EPOCH");
51
static const std::string TIMESTAMP("TIMESTAMP");
52
static const std::string MICROTIME("MICROTIME");
53
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");
58
static const std::string UNDEFINED("UNDEFINED");
59
static const std::string RESTRICT("RESTRICT");
60
static const std::string CASCADE("CASCADE");
61
static const std::string SET_NULL("SET NULL");
62
static const std::string NO_ACTION("NO ACTION");
63
static const std::string SET_DEFAULT("SET DEFAULT");
65
static const std::string YES("YES");
66
static const std::string NO("NO");
68
static const std::string UNKNOWN_INDEX("UNKNOWN_INDEX");
69
static const std::string BTREE("BTREE");
70
static const std::string RTREE("RTREE");
71
static const std::string HASH("HASH");
72
static const std::string FULLTEXT("FULLTEXT");
74
static const std::string MATCH_FULL("FULL");
75
static const std::string MATCH_PARTIAL("PARTIAL");
76
static const std::string MATCH_SIMPLE("SIMPLE");
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");
83
void update(drizzled::message::Schema &arg)
85
arg.set_version(arg.version() + 1);
86
arg.set_update_timestamp(time(NULL));
89
void update(drizzled::message::Table &arg)
91
arg.set_version(arg.version() + 1);
92
arg.set_update_timestamp(time(NULL));
95
bool is_numeric(const message::Table::Field &field)
97
message::Table::Field::FieldType type= field.type();
101
case message::Table::Field::DOUBLE:
102
case message::Table::Field::INTEGER:
103
case message::Table::Field::BIGINT:
104
case message::Table::Field::DECIMAL:
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:
121
const std::string &type(const message::Table::Field &field)
123
message::Table::Field::FieldType type= field.type();
127
case message::Table::Field::VARCHAR:
128
return field.string_options().collation().compare("binary") ? VARCHAR : VARBINARY;
129
case message::Table::Field::DOUBLE:
131
case message::Table::Field::BLOB:
132
return field.string_options().collation().compare("binary") ? TEXT : BLOB;
133
case message::Table::Field::ENUM:
135
case message::Table::Field::INTEGER:
137
case message::Table::Field::BIGINT:
139
case message::Table::Field::DECIMAL:
141
case message::Table::Field::DATE:
143
case message::Table::Field::EPOCH:
145
case message::Table::Field::DATETIME:
147
case message::Table::Field::TIME:
149
case message::Table::Field::UUID:
151
case message::Table::Field::BOOLEAN:
158
const std::string &type(drizzled::message::Table::Field::FieldType type)
162
case message::Table::Field::VARCHAR:
164
case message::Table::Field::DOUBLE:
166
case message::Table::Field::BLOB:
168
case message::Table::Field::ENUM:
170
case message::Table::Field::INTEGER:
172
case message::Table::Field::BIGINT:
174
case message::Table::Field::DECIMAL:
176
case message::Table::Field::DATE:
178
case message::Table::Field::EPOCH:
180
case message::Table::Field::DATETIME:
182
case message::Table::Field::TIME:
184
case message::Table::Field::UUID:
186
case message::Table::Field::BOOLEAN:
193
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
197
case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
199
case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
201
case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
203
case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
204
case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
206
case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
213
// This matches SQL standard of using YES/NO not the normal TRUE/FALSE
214
const std::string &type(bool type)
216
return type ? YES : NO;
219
const std::string &type(drizzled::message::Table::Index::IndexType type)
223
case message::Table::Index::UNKNOWN_INDEX:
224
return UNKNOWN_INDEX;
225
case message::Table::Index::BTREE:
227
case message::Table::Index::RTREE:
229
case message::Table::Index::HASH:
231
case message::Table::Index::FULLTEXT:
236
return PROGRAM_ERROR;
239
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
243
case message::Table::ForeignKeyConstraint::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:
255
const std::string &type(drizzled::message::Table::TableType type)
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;
270
return PROGRAM_ERROR;
274
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
278
google::protobuf::TextFormat::PrintToString(message, &buffer);
284
std::ostream& operator<<(std::ostream& output, const message::Table &message)
288
google::protobuf::TextFormat::PrintToString(message, &buffer);
296
} /* namespace message */
297
} /* namespace drizzled */