~drizzle-trunk/drizzle/development

1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
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>
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
22
2154.2.4 by Brian Aker
This fixes 716459
23
#include <drizzled/display.h>
24
#include <drizzled/item.h>
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
25
2154.2.4 by Brian Aker
This fixes 716459
26
#include <cassert>
27
#include <iostream>
28
#include <sstream>
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
29
30
namespace drizzled {
31
namespace display {
32
33
static const std::string PROGRAM_ERROR("PROGRAM_ERROR");
34
35
static const std::string COM_SLEEP("COM_SLEEP"); 
36
static const std::string COM_QUIT("COM_QUIT"); 
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
37
static const std::string COM_USE_SCHEMA("COM_USE_SCHEMA"); 
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
38
static const std::string COM_QUERY("COM_QUERY"); 
39
static const std::string COM_SHUTDOWN("COM_SHUTDOWN"); 
40
static const std::string COM_CONNECT("COM_CONNECT"); 
41
static const std::string COM_PING("COM_PING"); 
42
static const std::string COM_END("COM_END"); 
43
44
static const std::string DRIZZLE_TYPE_LONG("DRIZZLE_TYPE_LONG"); 
45
static const std::string DRIZZLE_TYPE_DOUBLE("DRIZZLE_TYPE_DOUBLE"); 
46
static const std::string DRIZZLE_TYPE_NULL("DRIZZLE_TYPE_NULL"); 
47
static const std::string DRIZZLE_TYPE_TIMESTAMP("DRIZZLE_TYPE_TIMESTAMP"); 
2046.2.1 by Brian Aker
First pass on micro timestamp.
48
static const std::string DRIZZLE_TYPE_MICROTIME("DRIZZLE_TYPE_MICROTIME"); 
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
49
static const std::string DRIZZLE_TYPE_LONGLONG("DRIZZLE_TYPE_LONGLONG"); 
50
static const std::string DRIZZLE_TYPE_DATETIME("DRIZZLE_TYPE_DATETIME"); 
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
51
static const std::string DRIZZLE_TYPE_TIME("DRIZZLE_TYPE_TIME"); 
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
52
static const std::string DRIZZLE_TYPE_DATE("DRIZZLE_TYPE_DATE"); 
53
static const std::string DRIZZLE_TYPE_VARCHAR("DRIZZLE_TYPE_VARCHAR"); 
54
static const std::string DRIZZLE_TYPE_DECIMAL("DRIZZLE_TYPE_DECIMAL"); 
55
static const std::string DRIZZLE_TYPE_ENUM("DRIZZLE_TYPE_ENUM"); 
56
static const std::string DRIZZLE_TYPE_BLOB("DRIZZLE_TYPE_BLOB"); 
1996.2.1 by Brian Aker
uuid type code.
57
static const std::string DRIZZLE_TYPE_UUID("DRIZZLE_TYPE_UUID"); 
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
58
static const std::string DRIZZLE_TYPE_BOOLEAN("DRIZZLE_TYPE_BOOLEAN"); 
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
59
static const std::string DRIZZLE_TYPE_IPV6("DRIZZLE_TYPE_IPV6"); 
1996.2.1 by Brian Aker
uuid type code.
60
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
61
static const std::string FIELD_ITEM("FIELD_ITEM");
62
static const std::string FUNC_ITEM("FUNC_ITEM");
63
static const std::string SUM_FUNC_ITEM("SUM_FUNC_ITEM");
64
static const std::string STRING_ITEM("STRING_ITEM");
65
static const std::string INT_ITEM("INT_ITEM");
66
static const std::string REAL_ITEM("REAL_ITEM");
67
static const std::string NULL_ITEM("NULL_ITEM");
68
static const std::string VARBIN_ITEM("VARBIN_ITEM");
69
static const std::string COPY_STR_ITEM("COPY_STR_ITEM");
70
static const std::string FIELD_AVG_ITEM("FIELD_AVG_ITEM");
71
static const std::string DEFAULT_VALUE_ITEM("DEFAULT_VALUE_ITEM");
72
static const std::string PROC_ITEM("PROC_ITEM");
73
static const std::string COND_ITEM("COND_ITEM");
74
static const std::string REF_ITEM("REF_ITEM");
75
static const std::string FIELD_STD_ITEM("FIELD_STD_ITEM");
76
static const std::string FIELD_VARIANCE_ITEM("FIELD_VARIANCE_ITEM");
77
static const std::string INSERT_VALUE_ITEM("INSERT_VALUE_ITEM");
78
static const std::string SUBSELECT_ITEM("SUBSELECT_ITEM");
79
static const std::string ROW_ITEM("ROW_ITEM");
80
static const std::string CACHE_ITEM("CACHE_ITEM");
81
static const std::string TYPE_HOLDER("TYPE_HOLDER");
82
static const std::string PARAM_ITEM("PARAM_ITEM");
2023.2.7 by Brian Aker
Create an Bool primtive type for item.
83
static const std::string BOOLEAN_ITEM("BOOLEAN_ITEM");
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
84
static const std::string DECIMAL_ITEM("DECIMAL_ITEM");
85
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
86
static const std::string ITEM_CAST_SIGNED("ITEM_CAST_SIGNED");
87
static const std::string ITEM_CAST_UNSIGNED("ITEM_CAST_UNSIGNED");
1999.4.12 by Brian Aker
Adds additional testing, and fixes CAST again.
88
static const std::string ITEM_CAST_BINARY("ITEM_CAST_BINARY");
2023.2.4 by Brian Aker
Merge in cast() for BOOLEAN.
89
static const std::string ITEM_CAST_BOOLEAN("ITEM_CAST_BOOLEAN");
1999.4.12 by Brian Aker
Adds additional testing, and fixes CAST again.
90
static const std::string ITEM_CAST_DATE("ITEM_CAST_DATE");
91
static const std::string ITEM_CAST_TIME("ITEM_CAST_TIME");
92
static const std::string ITEM_CAST_DATETIME("ITEM_CAST_DATETIME");
93
static const std::string ITEM_CAST_CHAR("ITEM_CAST_CHAR");
94
static const std::string ITEM_CAST_DECIMAL("ITEM_CAST_DECIMAL");
95
2039.3.3 by Brian Aker
result_type() to display the internal type.
96
static const std::string STRING_RESULT_STRING("STRING");
97
static const std::string REAL_RESULT_STRING("REAL");
98
static const std::string INT_RESULT_STRING("INTEGER");
99
static const std::string ROW_RESULT_STRING("ROW");
100
static const std::string DECIMAL_RESULT_STRING("DECIMAL");
101
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
102
static const std::string YES("YES");
103
static const std::string NO("NO");
104
1999.4.12 by Brian Aker
Adds additional testing, and fixes CAST again.
105
const std::string &type(drizzled::Cast_target type)
106
{
107
  switch (type)
108
  {
2015.1.3 by Brian Aker
Merge in CAST operators for SIGNED/UNSIGNED
109
  case drizzled::ITEM_CAST_SIGNED:
110
    return ITEM_CAST_SIGNED;
111
  case drizzled::ITEM_CAST_UNSIGNED:
112
    return ITEM_CAST_UNSIGNED;
1999.4.12 by Brian Aker
Adds additional testing, and fixes CAST again.
113
  case drizzled::ITEM_CAST_BINARY:
114
    return ITEM_CAST_BINARY;
2023.2.4 by Brian Aker
Merge in cast() for BOOLEAN.
115
  case drizzled::ITEM_CAST_BOOLEAN:
116
    return ITEM_CAST_BOOLEAN;
1999.4.12 by Brian Aker
Adds additional testing, and fixes CAST again.
117
  case drizzled::ITEM_CAST_DATE:
118
    return ITEM_CAST_DATE;
119
  case drizzled::ITEM_CAST_TIME:
120
    return ITEM_CAST_TIME;
121
  case drizzled::ITEM_CAST_DATETIME:
122
    return ITEM_CAST_DATETIME;
123
  case drizzled::ITEM_CAST_CHAR:
124
    return ITEM_CAST_CHAR;
125
  case drizzled::ITEM_CAST_DECIMAL:
126
    return ITEM_CAST_DECIMAL;
127
  }
128
129
  abort();
130
}
131
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
132
const std::string &type(drizzled::enum_server_command type)
133
{
134
  switch (type)
135
  {
136
  case drizzled::COM_SLEEP : 
137
    return COM_SLEEP;
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
138
2191.1.1 by Brian Aker
Add in KILL protocol support.
139
  case drizzled::COM_KILL : 
140
    {
141
      static std::string COM_KILL("COM_KILL");
142
      return COM_KILL;
143
    }
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
144
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
145
  case drizzled::COM_QUIT : 
146
    return COM_QUIT;
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
147
148
  case drizzled::COM_USE_SCHEMA : 
149
    return COM_USE_SCHEMA;
150
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
151
  case drizzled::COM_QUERY : 
152
    return COM_QUERY;
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
153
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
154
  case drizzled::COM_SHUTDOWN : 
155
    return COM_SHUTDOWN;
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
156
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
157
  case drizzled::COM_CONNECT : 
158
    return COM_CONNECT;
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
159
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
160
  case drizzled::COM_PING : 
161
    return COM_PING;
2312.1.2 by Brian Aker
Just a shuffle so that INIT_DB enum makes a bit more sense when you read it.
162
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
163
  case drizzled::COM_END : 
164
    return COM_END;
165
  }
166
167
  assert(0);
168
  return PROGRAM_ERROR;
169
}
170
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
171
const std::string &type(drizzled::Item::Type type)
172
{
173
  switch (type)
174
  {
175
  case drizzled::Item::FIELD_ITEM :
176
    return FIELD_ITEM;
177
  case drizzled::Item::FUNC_ITEM :
178
    return FUNC_ITEM;
179
  case drizzled::Item::SUM_FUNC_ITEM :
180
    return SUM_FUNC_ITEM;
181
  case drizzled::Item::STRING_ITEM :
182
    return STRING_ITEM;
183
  case drizzled::Item::INT_ITEM :
184
    return INT_ITEM;
185
  case drizzled::Item::REAL_ITEM :
186
    return REAL_ITEM;
187
  case drizzled::Item::NULL_ITEM :
188
    return NULL_ITEM;
189
  case drizzled::Item::VARBIN_ITEM :
190
    return VARBIN_ITEM;
191
  case drizzled::Item::COPY_STR_ITEM :
192
    return COPY_STR_ITEM;
193
  case drizzled::Item::FIELD_AVG_ITEM :
194
    return FIELD_AVG_ITEM;
195
  case drizzled::Item::DEFAULT_VALUE_ITEM :
196
    return DEFAULT_VALUE_ITEM;
197
  case drizzled::Item::PROC_ITEM :
198
    return PROC_ITEM;
199
  case drizzled::Item::COND_ITEM :
200
    return COND_ITEM;
201
  case drizzled::Item::REF_ITEM :
202
    return REF_ITEM;
203
  case drizzled::Item::FIELD_STD_ITEM :
204
    return FIELD_STD_ITEM;
205
  case drizzled::Item::FIELD_VARIANCE_ITEM :
206
    return FIELD_VARIANCE_ITEM;
207
  case drizzled::Item::INSERT_VALUE_ITEM :
208
    return INSERT_VALUE_ITEM;
209
  case drizzled::Item::SUBSELECT_ITEM :
210
    return SUBSELECT_ITEM;
211
  case drizzled::Item::ROW_ITEM:
212
    return ROW_ITEM;
213
  case drizzled::Item::CACHE_ITEM :
214
    return CACHE_ITEM;
215
  case drizzled::Item::TYPE_HOLDER :
216
    return TYPE_HOLDER;
217
  case drizzled::Item::PARAM_ITEM :
218
    return PARAM_ITEM;
2023.2.7 by Brian Aker
Create an Bool primtive type for item.
219
  case drizzled::Item::BOOLEAN_ITEM :
220
    return BOOLEAN_ITEM;
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
221
  case drizzled::Item::DECIMAL_ITEM :
222
    return DECIMAL_ITEM;
223
  }
224
225
  assert(0);
226
  return PROGRAM_ERROR;
227
}
228
2039.3.3 by Brian Aker
result_type() to display the internal type.
229
const std::string &type(Item_result type)
230
{
231
  switch (type)
232
  {
233
  case STRING_RESULT:
234
    return STRING_RESULT_STRING;
235
  case REAL_RESULT:
236
    return REAL_RESULT_STRING;
237
  case INT_RESULT:
238
    return INT_RESULT_STRING;
239
  case ROW_RESULT:
240
    return ROW_RESULT_STRING;
241
  case DECIMAL_RESULT:
242
    return DECIMAL_RESULT_STRING;
243
  }
244
245
  assert(0);
246
  return PROGRAM_ERROR;
247
}
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
248
249
const std::string &type(drizzled::enum_field_types type)
250
{
251
  switch (type)
252
  {
253
  case drizzled::DRIZZLE_TYPE_LONG : 
254
    return DRIZZLE_TYPE_LONG;
255
  case drizzled::DRIZZLE_TYPE_DOUBLE : 
256
    return DRIZZLE_TYPE_DOUBLE;
257
  case drizzled::DRIZZLE_TYPE_NULL : 
258
    return DRIZZLE_TYPE_NULL;
2046.2.1 by Brian Aker
First pass on micro timestamp.
259
  case drizzled::DRIZZLE_TYPE_MICROTIME : 
260
    return DRIZZLE_TYPE_MICROTIME;
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
261
  case drizzled::DRIZZLE_TYPE_TIMESTAMP : 
262
    return DRIZZLE_TYPE_TIMESTAMP;
263
  case drizzled::DRIZZLE_TYPE_LONGLONG : 
264
    return DRIZZLE_TYPE_LONGLONG;
265
  case drizzled::DRIZZLE_TYPE_DATETIME : 
266
    return DRIZZLE_TYPE_DATETIME;
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
267
  case drizzled::DRIZZLE_TYPE_TIME : 
268
    return DRIZZLE_TYPE_TIME;
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
269
  case drizzled::DRIZZLE_TYPE_DATE : 
270
    return DRIZZLE_TYPE_DATE;
271
  case drizzled::DRIZZLE_TYPE_VARCHAR : 
272
    return DRIZZLE_TYPE_VARCHAR;
273
  case drizzled::DRIZZLE_TYPE_DECIMAL : 
274
    return DRIZZLE_TYPE_DECIMAL;
275
  case drizzled::DRIZZLE_TYPE_ENUM : 
276
    return DRIZZLE_TYPE_ENUM;
277
  case drizzled::DRIZZLE_TYPE_BLOB : 
278
    return DRIZZLE_TYPE_BLOB;
1996.2.1 by Brian Aker
uuid type code.
279
  case drizzled::DRIZZLE_TYPE_UUID : 
280
    return DRIZZLE_TYPE_UUID;
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
281
  case drizzled::DRIZZLE_TYPE_BOOLEAN : 
282
    return DRIZZLE_TYPE_BOOLEAN;
2398.1.1 by Muhammad Umair
merge lp:~mumair/drizzle/drizzle-IPv6Address
283
  case drizzled::DRIZZLE_TYPE_IPV6 : 
284
    return DRIZZLE_TYPE_IPV6;
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
285
  }
286
287
  assert(0);
288
  return PROGRAM_ERROR;
289
}
290
1996.2.1 by Brian Aker
uuid type code.
291
std::string hexdump(const unsigned char *str, size_t length)
292
{
293
  static const char hexval[16] = { '0', '1', '2', '3', 
294
    '4', '5', '6', '7', 
295
    '8', '9', 'a', 'b', 
296
    'c', 'd', 'e', 'f' };
297
  unsigned max_cols = 16; 
298
  std::ostringstream buf;
299
  std::ostringstream raw_buf;
300
301
  const unsigned char *e= str + length;
302
  for (const unsigned char *i= str; i != e;)
303
  {
304
    raw_buf.str("");
305
    for (unsigned col = 0; col < max_cols; ++col)
306
    {
307
      if (i != e)
308
      {
309
        buf << hexval[ ( (*i >> 4) & 0xF ) ]
310
          << hexval[ ( *i & 0x0F ) ]
311
          << ' ';
312
        raw_buf << (isprint(*i) ? *i : '.');
313
        ++i;
314
      }
315
      else
316
      {
317
        buf << "   ";
318
      }
319
    }
320
  }
321
322
  return buf.str();
323
}
324
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
325
} /* namespace display */
326
} /* namespace drizzled */