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"); |
|
51 |
||
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"); |
|
1861.4.8
by Brian Aker
Adds in a portion of the ref constraints table. |
57 |
static const std::string SET_DEFAULT("SET DEFAULT"); |
1861.4.4
by Brian Aker
Cleanup display code around DD/IS |
58 |
|
59 |
static const std::string YES("YES"); |
|
60 |
static const std::string NO("NO"); |
|
61 |
||
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"); |
|
67 |
||
1861.4.8
by Brian Aker
Adds in a portion of the ref constraints table. |
68 |
static const std::string MATCH_FULL("FULL"); |
69 |
static const std::string MATCH_PARTIAL("PARTIAL"); |
|
70 |
static const std::string MATCH_SIMPLE("SIMPLE"); |
|
71 |
||
1802.12.1
by Brian Aker
This solves bug lp:654905 |
72 |
void init(drizzled::message::Table &arg, const std::string &name_arg, const std::string &schema_arg, const std::string &engine_arg) |
73 |
{
|
|
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); |
|
79 |
||
80 |
/* 36 characters for uuid string +1 for NULL */
|
|
81 |
uuid_t uu; |
|
82 |
char uuid_string[37]; |
|
83 |
uuid_generate_random(uu); |
|
84 |
uuid_unparse(uu, uuid_string); |
|
85 |
arg.set_uuid(uuid_string, 36); |
|
86 |
||
87 |
arg.set_version(1); |
|
88 |
}
|
|
89 |
||
90 |
void init(drizzled::message::Schema &arg, const std::string &name_arg) |
|
91 |
{
|
|
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()) |
|
95 |
{
|
|
96 |
arg.set_collation(default_charset_info->name); |
|
97 |
}
|
|
98 |
||
99 |
/* 36 characters for uuid string +1 for NULL */
|
|
100 |
uuid_t uu; |
|
101 |
char uuid_string[37]; |
|
102 |
uuid_generate_random(uu); |
|
103 |
uuid_unparse(uu, uuid_string); |
|
104 |
arg.set_uuid(uuid_string, 36); |
|
105 |
||
106 |
arg.set_version(1); |
|
107 |
}
|
|
108 |
||
1802.12.2
by Brian Aker
Correcting alter schema to fix bug around schema not altering collate |
109 |
void update(drizzled::message::Schema &arg) |
110 |
{
|
|
111 |
arg.set_version(arg.version() + 1); |
|
112 |
arg.set_update_timestamp(time(NULL)); |
|
113 |
}
|
|
114 |
||
115 |
void update(drizzled::message::Table &arg) |
|
116 |
{
|
|
117 |
arg.set_version(arg.version() + 1); |
|
118 |
arg.set_update_timestamp(time(NULL)); |
|
119 |
}
|
|
120 |
||
1861.4.4
by Brian Aker
Cleanup display code around DD/IS |
121 |
const std::string &type(drizzled::message::Table::Field::FieldType type) |
122 |
{
|
|
123 |
switch (type) |
|
124 |
{
|
|
125 |
case message::Table::Field::VARCHAR: |
|
126 |
return VARCHAR; |
|
127 |
case message::Table::Field::DOUBLE: |
|
128 |
return DOUBLE; |
|
129 |
case message::Table::Field::BLOB: |
|
130 |
return BLOB; |
|
131 |
case message::Table::Field::ENUM: |
|
132 |
return ENUM; |
|
133 |
case message::Table::Field::INTEGER: |
|
134 |
return INTEGER; |
|
135 |
case message::Table::Field::BIGINT: |
|
136 |
return BIGINT; |
|
137 |
case message::Table::Field::DECIMAL: |
|
138 |
return DECIMAL; |
|
139 |
case message::Table::Field::DATE: |
|
140 |
return DATE; |
|
141 |
case message::Table::Field::TIMESTAMP: |
|
142 |
return TIMESTAMP; |
|
143 |
case message::Table::Field::DATETIME: |
|
144 |
return DATETIME; |
|
145 |
}
|
|
1861.4.8
by Brian Aker
Adds in a portion of the ref constraints table. |
146 |
|
147 |
assert(0); |
|
148 |
return PROGRAM_ERROR; |
|
1861.4.4
by Brian Aker
Cleanup display code around DD/IS |
149 |
}
|
150 |
||
151 |
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type) |
|
152 |
{
|
|
153 |
switch (type) |
|
154 |
{
|
|
155 |
case message::Table::ForeignKeyConstraint::OPTION_RESTRICT: |
|
156 |
return RESTRICT; |
|
157 |
case message::Table::ForeignKeyConstraint::OPTION_CASCADE: |
|
158 |
return CASCADE; |
|
159 |
case message::Table::ForeignKeyConstraint::OPTION_SET_NULL: |
|
160 |
return SET_NULL; |
|
1861.4.8
by Brian Aker
Adds in a portion of the ref constraints table. |
161 |
case message::Table::ForeignKeyConstraint::OPTION_UNDEF: |
1861.4.4
by Brian Aker
Cleanup display code around DD/IS |
162 |
case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION: |
163 |
return NO_ACTION; |
|
1861.4.8
by Brian Aker
Adds in a portion of the ref constraints table. |
164 |
case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT: |
165 |
return SET_DEFAULT; |
|
1861.4.4
by Brian Aker
Cleanup display code around DD/IS |
166 |
}
|
1861.4.8
by Brian Aker
Adds in a portion of the ref constraints table. |
167 |
|
168 |
return NO_ACTION; |
|
1861.4.4
by Brian Aker
Cleanup display code around DD/IS |
169 |
}
|
170 |
||
171 |
// This matches SQL standard of using YES/NO not the normal TRUE/FALSE
|
|
172 |
const std::string &type(bool type) |
|
173 |
{
|
|
174 |
return type ? YES : NO; |
|
175 |
}
|
|
176 |
||
177 |
const std::string &type(drizzled::message::Table::Index::IndexType type) |
|
178 |
{
|
|
179 |
switch (type) |
|
180 |
{
|
|
181 |
case message::Table::Index::UNKNOWN_INDEX: |
|
182 |
return UNKNOWN_INDEX; |
|
183 |
case message::Table::Index::BTREE: |
|
184 |
return BTREE; |
|
185 |
case message::Table::Index::RTREE: |
|
186 |
return RTREE; |
|
187 |
case message::Table::Index::HASH: |
|
188 |
return HASH; |
|
189 |
case message::Table::Index::FULLTEXT: |
|
190 |
return FULLTEXT; |
|
191 |
}
|
|
1861.4.8
by Brian Aker
Adds in a portion of the ref constraints table. |
192 |
|
193 |
assert(0); |
|
194 |
return PROGRAM_ERROR; |
|
195 |
}
|
|
196 |
||
197 |
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type) |
|
198 |
{
|
|
199 |
switch (type) |
|
200 |
{
|
|
201 |
case message::Table::ForeignKeyConstraint::MATCH_FULL: |
|
202 |
return 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: |
|
207 |
return MATCH_SIMPLE; |
|
208 |
}
|
|
209 |
||
210 |
return MATCH_SIMPLE; |
|
1861.4.4
by Brian Aker
Cleanup display code around DD/IS |
211 |
}
|
212 |
||
1921.1.2
by Brian Aker
Remove print helper methods. |
213 |
#if 0
|
1910.2.12
by Brian Aker
Adding operators to print table, transaction. |
214 |
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
|
215 |
{
|
|
216 |
std::string buffer;
|
|
217 |
||
218 |
google::protobuf::TextFormat::PrintToString(message, &buffer);
|
|
219 |
output << buffer;
|
|
220 |
||
221 |
return output;
|
|
222 |
}
|
|
223 |
||
224 |
std::ostream& operator<<(std::ostream& output, const message::Table &message)
|
|
225 |
{
|
|
226 |
std::string buffer;
|
|
227 |
||
228 |
google::protobuf::TextFormat::PrintToString(message, &buffer);
|
|
229 |
output << buffer;
|
|
230 |
||
231 |
return output;
|
|
232 |
}
|
|
1921.1.2
by Brian Aker
Remove print helper methods. |
233 |
#endif
|
1910.2.12
by Brian Aker
Adding operators to print table, transaction. |
234 |
|
235 |
||
1802.12.1
by Brian Aker
This solves bug lp:654905 |
236 |
} /* namespace message */ |
237 |
} /* namespace drizzled */ |