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");
52
static const std::string UNDEFINED("UNDEFINED");
53
static const std::string RESTRICT("RESTRICT");
54
static const std::string CASCADE("CASCADE");
55
static const std::string SET_NULL("SET NULL");
56
static const std::string NO_ACTION("NO ACTION");
57
static const std::string SET_DEFAULT("SET DEFAULT");
59
static const std::string YES("YES");
60
static const std::string NO("NO");
62
static const std::string UNKNOWN_INDEX("UNKNOWN_INDEX");
63
static const std::string BTREE("BTREE");
64
static const std::string RTREE("RTREE");
65
static const std::string HASH("HASH");
66
static const std::string FULLTEXT("FULLTEXT");
68
static const std::string MATCH_FULL("FULL");
69
static const std::string MATCH_PARTIAL("PARTIAL");
70
static const std::string MATCH_SIMPLE("SIMPLE");
72
void init(drizzled::message::Table &arg, const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg)
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);
80
/* 36 characters for uuid string +1 for NULL */
83
uuid_generate_random(uu);
84
uuid_unparse(uu, uuid_string);
85
arg.set_uuid(uuid_string, 36);
90
void init(drizzled::message::Schema &arg, const std::string &name_arg)
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())
96
arg.set_collation(default_charset_info->name);
99
/* 36 characters for uuid string +1 for NULL */
101
char uuid_string[37];
102
uuid_generate_random(uu);
103
uuid_unparse(uu, uuid_string);
104
arg.set_uuid(uuid_string, 36);
109
void update(drizzled::message::Schema &arg)
111
arg.set_version(arg.version() + 1);
112
arg.set_update_timestamp(time(NULL));
115
void update(drizzled::message::Table &arg)
117
arg.set_version(arg.version() + 1);
118
arg.set_update_timestamp(time(NULL));
121
const std::string &type(drizzled::message::Table::Field::FieldType type)
125
case message::Table::Field::VARCHAR:
127
case message::Table::Field::DOUBLE:
129
case message::Table::Field::BLOB:
131
case message::Table::Field::ENUM:
133
case message::Table::Field::INTEGER:
135
case message::Table::Field::BIGINT:
137
case message::Table::Field::DECIMAL:
139
case message::Table::Field::DATE:
141
case message::Table::Field::TIMESTAMP:
143
case message::Table::Field::DATETIME:
148
return PROGRAM_ERROR;
151
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
155
case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
157
case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
159
case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
161
case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
162
case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
164
case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
171
// This matches SQL standard of using YES/NO not the normal TRUE/FALSE
172
const std::string &type(bool type)
174
return type ? YES : NO;
177
const std::string &type(drizzled::message::Table::Index::IndexType type)
181
case message::Table::Index::UNKNOWN_INDEX:
182
return UNKNOWN_INDEX;
183
case message::Table::Index::BTREE:
185
case message::Table::Index::RTREE:
187
case message::Table::Index::HASH:
189
case message::Table::Index::FULLTEXT:
194
return PROGRAM_ERROR;
197
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
201
case message::Table::ForeignKeyConstraint::MATCH_FULL:
203
case message::Table::ForeignKeyConstraint::MATCH_PARTIAL:
204
return MATCH_PARTIAL;
205
case message::Table::ForeignKeyConstraint::MATCH_UNDEFINED:
206
case message::Table::ForeignKeyConstraint::MATCH_SIMPLE:
214
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
218
google::protobuf::TextFormat::PrintToString(message, &buffer);
224
std::ostream& operator<<(std::ostream& output, const message::Table &message)
228
google::protobuf::TextFormat::PrintToString(message, &buffer);
236
} /* namespace message */
237
} /* namespace drizzled */