~drizzle-trunk/drizzle/development

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
2173.2.1 by Monty Taylor
Fixes incorrect usage of include
21
#include <config.h>
1802.12.1 by Brian Aker
This solves bug lp:654905
22
23
#include <drizzled/show.h>
24
#include <drizzled/session.h>
2159.2.5 by Brian Aker
Merge in move of schema.
25
#include <drizzled/schema.h>
1802.12.1 by Brian Aker
This solves bug lp:654905
26
#include <drizzled/plugin/event_observer.h>
27
#include <drizzled/message.h>
28
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
29
#include <string>
1802.12.1 by Brian Aker
This solves bug lp:654905
30
31
namespace drizzled {
32
namespace message {
33
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
34
static const std::string PROGRAM_ERROR("PROGRAM_ERROR");
35
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
36
// These are used to generate strings for types
37
static const std::string VARCHAR("VARCHAR");
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
38
static const std::string VARBINARY("VARBINARY");
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
39
static const std::string DOUBLE("DOUBLE");
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
40
static const std::string TEXT("TEXT");
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
41
static const std::string BLOB("BLOB");
42
static const std::string ENUM("ENUM");
43
static const std::string INTEGER("INTEGER");
44
static const std::string BIGINT("BIGINT");
45
static const std::string DECIMAL("DECIMAL");
46
static const std::string DATE("DATE");
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
47
static const std::string EPOCH("EPOCH");
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
48
static const std::string TIMESTAMP("TIMESTAMP");
2046.2.1 by Brian Aker
First pass on micro timestamp.
49
static const std::string MICROTIME("MICROTIME");
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
50
static const std::string DATETIME("DATETIME");
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
51
static const std::string TIME("TIME");
1996.2.1 by Brian Aker
uuid type code.
52
static const std::string UUID("UUID");
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
53
static const std::string BOOLEAN("BOOLEAN");
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
54
static const std::string IPV6("IPV6");
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
55
56
static const std::string UNDEFINED("UNDEFINED");
57
static const std::string RESTRICT("RESTRICT");
58
static const std::string CASCADE("CASCADE");
59
static const std::string SET_NULL("SET NULL");
60
static const std::string NO_ACTION("NO ACTION");
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
61
static const std::string SET_DEFAULT("SET DEFAULT");
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
62
63
static const std::string YES("YES");
64
static const std::string NO("NO");
65
66
static const std::string UNKNOWN_INDEX("UNKNOWN_INDEX");
67
static const std::string BTREE("BTREE");
68
static const std::string RTREE("RTREE");
69
static const std::string HASH("HASH");
70
static const std::string FULLTEXT("FULLTEXT");
71
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
72
static const std::string MATCH_FULL("FULL");
73
static const std::string MATCH_PARTIAL("PARTIAL");
74
static const std::string MATCH_SIMPLE("SIMPLE");
75
2134.1.7 by Brian Aker
Collapse strings used for table.
76
const static std::string STANDARD_STRING("STANDARD");
77
const static std::string TEMPORARY_STRING("TEMPORARY");
78
const static std::string INTERNAL_STRING("INTERNAL");
79
const static std::string FUNCTION_STRING("FUNCTION");
80
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
81
void update(drizzled::message::Schema &arg)
82
{
83
  arg.set_version(arg.version() + 1);
84
  arg.set_update_timestamp(time(NULL));
85
}
86
87
void update(drizzled::message::Table &arg)
88
{
89
  arg.set_version(arg.version() + 1);
90
  arg.set_update_timestamp(time(NULL));
91
}
92
1999.4.11 by Brian Aker
Fix issues with some columns incorrectly reporting NULL if they were of
93
bool is_numeric(const message::Table::Field &field)
94
{
95
  message::Table::Field::FieldType type= field.type();
96
97
  switch (type)
98
  {
99
  case message::Table::Field::DOUBLE:
100
  case message::Table::Field::INTEGER:
101
  case message::Table::Field::BIGINT:
102
  case message::Table::Field::DECIMAL:
103
    return true;
104
  case message::Table::Field::BLOB:
105
  case message::Table::Field::VARCHAR:
106
  case message::Table::Field::ENUM:
107
  case message::Table::Field::DATE:
108
  case message::Table::Field::EPOCH:
109
  case message::Table::Field::DATETIME:
110
  case message::Table::Field::TIME:
111
  case message::Table::Field::UUID:
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
112
  case message::Table::Field::BOOLEAN:
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
113
  case message::Table::Field::IPV6:
1999.4.11 by Brian Aker
Fix issues with some columns incorrectly reporting NULL if they were of
114
    break;
115
  }
116
117
  return false;
118
}
119
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
120
const std::string &type(const message::Table::Field &field)
121
{
122
  message::Table::Field::FieldType type= field.type();
123
124
  switch (type)
125
  {
126
  case message::Table::Field::VARCHAR:
127
    return field.string_options().collation().compare("binary") ? VARCHAR : VARBINARY;
128
  case message::Table::Field::DOUBLE:
129
    return DOUBLE;
130
  case message::Table::Field::BLOB:
131
    return field.string_options().collation().compare("binary") ? TEXT : BLOB;
132
  case message::Table::Field::ENUM:
133
    return ENUM;
134
  case message::Table::Field::INTEGER:
135
    return INTEGER;
136
  case message::Table::Field::BIGINT:
137
    return BIGINT;
138
  case message::Table::Field::DECIMAL:
139
    return DECIMAL;
140
  case message::Table::Field::DATE:
141
    return DATE;
142
  case message::Table::Field::EPOCH:
143
    return TIMESTAMP;
144
  case message::Table::Field::DATETIME:
145
    return DATETIME;
146
  case message::Table::Field::TIME:
147
    return TIME;
148
  case message::Table::Field::UUID:
149
    return UUID;
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
150
  case message::Table::Field::BOOLEAN:
151
    return BOOLEAN;
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
152
  case message::Table::Field::IPV6:
153
    return IPV6;
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
154
  }
155
156
  abort();
157
}
158
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
159
const std::string &type(drizzled::message::Table::Field::FieldType type)
160
{
161
  switch (type)
162
  {
163
  case message::Table::Field::VARCHAR:
164
    return VARCHAR;
165
  case message::Table::Field::DOUBLE:
166
    return DOUBLE;
167
  case message::Table::Field::BLOB:
168
    return BLOB;
169
  case message::Table::Field::ENUM:
170
    return ENUM;
171
  case message::Table::Field::INTEGER:
172
    return INTEGER;
173
  case message::Table::Field::BIGINT:
174
    return BIGINT;
175
  case message::Table::Field::DECIMAL:
176
    return DECIMAL;
177
  case message::Table::Field::DATE:
178
    return DATE;
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
179
  case message::Table::Field::EPOCH:
180
    return EPOCH;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
181
  case message::Table::Field::DATETIME:
182
    return DATETIME;
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
183
  case message::Table::Field::TIME:
184
    return TIME;
1996.2.1 by Brian Aker
uuid type code.
185
  case message::Table::Field::UUID:
186
    return UUID;
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
187
  case message::Table::Field::BOOLEAN:
188
    return BOOLEAN;
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
189
  case message::Table::Field::IPV6:
190
    return IPV6;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
191
  }
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
192
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
193
  abort();
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
194
}
195
196
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
197
{
198
  switch (type)
199
  {
200
  case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
201
    return RESTRICT;
202
  case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
203
    return CASCADE;
204
  case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
205
    return SET_NULL;
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
206
  case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
207
  case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
208
    return NO_ACTION;
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
209
  case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
210
    return SET_DEFAULT;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
211
  }
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
212
213
  return NO_ACTION;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
214
}
215
216
const std::string &type(drizzled::message::Table::Index::IndexType type)
217
{
218
  switch (type)
219
  {
220
  case message::Table::Index::UNKNOWN_INDEX:
221
    return UNKNOWN_INDEX;
222
  case message::Table::Index::BTREE:
223
    return BTREE;
224
  case message::Table::Index::RTREE:
225
    return RTREE;
226
  case message::Table::Index::HASH:
227
    return HASH;
228
  case message::Table::Index::FULLTEXT:
229
    return FULLTEXT;
230
  }
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
231
232
  assert(0);
233
  return PROGRAM_ERROR;
234
}
235
236
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
237
{
238
  switch (type)
239
  {
240
  case message::Table::ForeignKeyConstraint::MATCH_FULL:
241
    return MATCH_FULL;
242
  case message::Table::ForeignKeyConstraint::MATCH_PARTIAL:
243
    return MATCH_PARTIAL;
244
  case message::Table::ForeignKeyConstraint::MATCH_UNDEFINED:
245
  case message::Table::ForeignKeyConstraint::MATCH_SIMPLE:
246
    return MATCH_SIMPLE;
247
  }
248
249
  return MATCH_SIMPLE;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
250
}
251
2134.1.7 by Brian Aker
Collapse strings used for table.
252
const std::string &type(drizzled::message::Table::TableType type)
253
{
254
  switch (type)
255
  {
256
  case message::Table::STANDARD:
257
    return STANDARD_STRING;
258
  case message::Table::TEMPORARY:
259
    return TEMPORARY_STRING;
260
  case message::Table::INTERNAL:
261
    return INTERNAL_STRING;
262
  case message::Table::FUNCTION:
263
    return FUNCTION_STRING;
264
  }
265
266
  assert(0);
267
  return PROGRAM_ERROR;
268
}
269
1921.1.2 by Brian Aker
Remove print helper methods.
270
#if 0
1910.2.12 by Brian Aker
Adding operators to print table, transaction.
271
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
272
{ 
273
    std::string buffer;
274
275
    google::protobuf::TextFormat::PrintToString(message, &buffer);
276
    output << buffer;
277
278
    return output;
279
}
280
281
std::ostream& operator<<(std::ostream& output, const message::Table &message)
282
{ 
283
  std::string buffer;
284
285
  google::protobuf::TextFormat::PrintToString(message, &buffer);
286
  output << buffer;
287
288
  return output;
289
}
1921.1.2 by Brian Aker
Remove print helper methods.
290
#endif
1910.2.12 by Brian Aker
Adding operators to print table, transaction.
291
292
1802.12.1 by Brian Aker
This solves bug lp:654905
293
} /* namespace message */
294
} /* namespace drizzled */