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