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