~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
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
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
1802.12.2 by Brian Aker
Correcting alter schema to fix bug around schema not altering collate
78
void update(drizzled::message::Schema &arg)
79
{
80
  arg.set_version(arg.version() + 1);
81
  arg.set_update_timestamp(time(NULL));
82
}
83
84
void update(drizzled::message::Table &arg)
85
{
86
  arg.set_version(arg.version() + 1);
87
  arg.set_update_timestamp(time(NULL));
88
}
89
1999.4.11 by Brian Aker
Fix issues with some columns incorrectly reporting NULL if they were of
90
bool is_numeric(const message::Table::Field &field)
91
{
92
  message::Table::Field::FieldType type= field.type();
93
94
  switch (type)
95
  {
96
  case message::Table::Field::DOUBLE:
97
  case message::Table::Field::INTEGER:
98
  case message::Table::Field::BIGINT:
99
  case message::Table::Field::DECIMAL:
100
    return true;
101
  case message::Table::Field::BLOB:
102
  case message::Table::Field::VARCHAR:
103
  case message::Table::Field::ENUM:
104
  case message::Table::Field::DATE:
105
  case message::Table::Field::EPOCH:
106
  case message::Table::Field::DATETIME:
107
  case message::Table::Field::TIME:
108
  case message::Table::Field::UUID:
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
109
  case message::Table::Field::BOOLEAN:
1999.4.11 by Brian Aker
Fix issues with some columns incorrectly reporting NULL if they were of
110
    break;
111
  }
112
113
  return false;
114
}
115
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
116
const std::string &type(const message::Table::Field &field)
117
{
118
  message::Table::Field::FieldType type= field.type();
119
120
  switch (type)
121
  {
122
  case message::Table::Field::VARCHAR:
123
    return field.string_options().collation().compare("binary") ? VARCHAR : VARBINARY;
124
  case message::Table::Field::DOUBLE:
125
    return DOUBLE;
126
  case message::Table::Field::BLOB:
127
    return field.string_options().collation().compare("binary") ? TEXT : BLOB;
128
  case message::Table::Field::ENUM:
129
    return ENUM;
130
  case message::Table::Field::INTEGER:
131
    return INTEGER;
132
  case message::Table::Field::BIGINT:
133
    return BIGINT;
134
  case message::Table::Field::DECIMAL:
135
    return DECIMAL;
136
  case message::Table::Field::DATE:
137
    return DATE;
138
  case message::Table::Field::EPOCH:
139
    return TIMESTAMP;
140
  case message::Table::Field::DATETIME:
141
    return DATETIME;
142
  case message::Table::Field::TIME:
143
    return TIME;
144
  case message::Table::Field::UUID:
145
    return UUID;
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
146
  case message::Table::Field::BOOLEAN:
147
    return BOOLEAN;
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
148
  }
149
150
  abort();
151
}
152
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
153
const std::string &type(drizzled::message::Table::Field::FieldType type)
154
{
155
  switch (type)
156
  {
157
  case message::Table::Field::VARCHAR:
158
    return VARCHAR;
159
  case message::Table::Field::DOUBLE:
160
    return DOUBLE;
161
  case message::Table::Field::BLOB:
162
    return BLOB;
163
  case message::Table::Field::ENUM:
164
    return ENUM;
165
  case message::Table::Field::INTEGER:
166
    return INTEGER;
167
  case message::Table::Field::BIGINT:
168
    return BIGINT;
169
  case message::Table::Field::DECIMAL:
170
    return DECIMAL;
171
  case message::Table::Field::DATE:
172
    return DATE;
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
173
  case message::Table::Field::EPOCH:
174
    return EPOCH;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
175
  case message::Table::Field::DATETIME:
176
    return DATETIME;
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
177
  case message::Table::Field::TIME:
178
    return TIME;
1996.2.1 by Brian Aker
uuid type code.
179
  case message::Table::Field::UUID:
180
    return UUID;
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
181
  case message::Table::Field::BOOLEAN:
182
    return BOOLEAN;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
183
  }
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
184
1999.4.10 by Brian Aker
This fixes the bug where we were not displaying the correct field type in
185
  abort();
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
186
}
187
188
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyOption type)
189
{
190
  switch (type)
191
  {
192
  case message::Table::ForeignKeyConstraint::OPTION_RESTRICT:
193
    return RESTRICT;
194
  case message::Table::ForeignKeyConstraint::OPTION_CASCADE:
195
    return CASCADE;
196
  case message::Table::ForeignKeyConstraint::OPTION_SET_NULL:
197
    return SET_NULL;
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
198
  case message::Table::ForeignKeyConstraint::OPTION_UNDEF:
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
199
  case message::Table::ForeignKeyConstraint::OPTION_NO_ACTION:
200
    return NO_ACTION;
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
201
  case message::Table::ForeignKeyConstraint::OPTION_SET_DEFAULT:
202
    return SET_DEFAULT;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
203
  }
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
204
205
  return NO_ACTION;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
206
}
207
208
// This matches SQL standard of using YES/NO not the normal TRUE/FALSE
209
const std::string &type(bool type)
210
{
211
  return type ? YES : NO;
212
}
213
214
const std::string &type(drizzled::message::Table::Index::IndexType type)
215
{
216
  switch (type)
217
  {
218
  case message::Table::Index::UNKNOWN_INDEX:
219
    return UNKNOWN_INDEX;
220
  case message::Table::Index::BTREE:
221
    return BTREE;
222
  case message::Table::Index::RTREE:
223
    return RTREE;
224
  case message::Table::Index::HASH:
225
    return HASH;
226
  case message::Table::Index::FULLTEXT:
227
    return FULLTEXT;
228
  }
1861.4.8 by Brian Aker
Adds in a portion of the ref constraints table.
229
230
  assert(0);
231
  return PROGRAM_ERROR;
232
}
233
234
const std::string &type(drizzled::message::Table::ForeignKeyConstraint::ForeignKeyMatchOption type)
235
{
236
  switch (type)
237
  {
238
  case message::Table::ForeignKeyConstraint::MATCH_FULL:
239
    return MATCH_FULL;
240
  case message::Table::ForeignKeyConstraint::MATCH_PARTIAL:
241
    return MATCH_PARTIAL;
242
  case message::Table::ForeignKeyConstraint::MATCH_UNDEFINED:
243
  case message::Table::ForeignKeyConstraint::MATCH_SIMPLE:
244
    return MATCH_SIMPLE;
245
  }
246
247
  return MATCH_SIMPLE;
1861.4.4 by Brian Aker
Cleanup display code around DD/IS
248
}
249
1921.1.2 by Brian Aker
Remove print helper methods.
250
#if 0
1910.2.12 by Brian Aker
Adding operators to print table, transaction.
251
std::ostream& operator<<(std::ostream& output, const message::Transaction &message)
252
{ 
253
    std::string buffer;
254
255
    google::protobuf::TextFormat::PrintToString(message, &buffer);
256
    output << buffer;
257
258
    return output;
259
}
260
261
std::ostream& operator<<(std::ostream& output, const message::Table &message)
262
{ 
263
  std::string buffer;
264
265
  google::protobuf::TextFormat::PrintToString(message, &buffer);
266
  output << buffer;
267
268
  return output;
269
}
1921.1.2 by Brian Aker
Remove print helper methods.
270
#endif
1910.2.12 by Brian Aker
Adding operators to print table, transaction.
271
272
1802.12.1 by Brian Aker
This solves bug lp:654905
273
} /* namespace message */
274
} /* namespace drizzled */