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"
33
#include <uuid/uuid.h>
38
static const std::string PROGRAM_ERROR("PROGRAM_ERROR");
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");
51
static const std::string UUID("UUID");
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");
58
static const std::string SET_DEFAULT("SET DEFAULT");
60
static const std::string YES("YES");
61
static const std::string NO("NO");
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");
69
static const std::string MATCH_FULL("FULL");
70
static const std::string MATCH_PARTIAL("PARTIAL");
71
static const std::string MATCH_SIMPLE("SIMPLE");
73
void init(drizzled::message::Table &arg, const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg)
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);
81
/* 36 characters for uuid string +1 for NULL */
84
uuid_generate_random(uu);
85
uuid_unparse(uu, uuid_string);
86
arg.set_uuid(uuid_string, 36);
91
void init(drizzled::message::Schema &arg, const std::string &name_arg)
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())
97
arg.set_collation(default_charset_info->name);
100
/* 36 characters for uuid string +1 for NULL */
102
char uuid_string[37];
103
uuid_generate_random(uu);
104
uuid_unparse(uu, uuid_string);
105
arg.set_uuid(uuid_string, 36);
110
void update(drizzled::message::Schema &arg)
112
arg.set_version(arg.version() + 1);
113
arg.set_update_timestamp(time(NULL));
116
void update(drizzled::message::Table &arg)
118
arg.set_version(arg.version() + 1);
119
arg.set_update_timestamp(time(NULL));
122
const std::string &type(drizzled::message::Table::Field::FieldType type)
126
case message::Table::Field::VARCHAR:
128
case message::Table::Field::DOUBLE:
130
case message::Table::Field::BLOB:
132
case message::Table::Field::ENUM:
134
case message::Table::Field::INTEGER:
136
case message::Table::Field::BIGINT:
138
case message::Table::Field::DECIMAL:
140
case message::Table::Field::DATE:
142
case message::Table::Field::TIMESTAMP:
144
case message::Table::Field::DATETIME:
146
case message::Table::Field::UUID:
151
return PROGRAM_ERROR;
154
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
158
case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
160
case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
162
case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
164
case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
165
case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
167
case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
174
// This matches SQL standard of using YES/NO not the normal TRUE/FALSE
175
const std::string &type(bool type)
177
return type ? YES : NO;
180
const std::string &type(drizzled::message::Table::Index::IndexType type)
184
case message::Table::Index::UNKNOWN_INDEX:
185
return UNKNOWN_INDEX;
186
case message::Table::Index::BTREE:
188
case message::Table::Index::RTREE:
190
case message::Table::Index::HASH:
192
case message::Table::Index::FULLTEXT:
197
return PROGRAM_ERROR;
200
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
204
case message::Table::ForeignKeyConstraint::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:
217
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
221
google::protobuf::TextFormat::PrintToString(message, &buffer);
227
std::ostream& operator<<(std::ostream& output, const message::Table &message)
231
google::protobuf::TextFormat::PrintToString(message, &buffer);
239
} /* namespace message */
240
} /* namespace drizzled */