~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"); 
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;
2191.1.1 by Brian Aker
Add in KILL protocol support.
137
  case drizzled::COM_KILL : 
138
    {
139
      static std::string COM_KILL("COM_KILL");
140
      return COM_KILL;
141
    }
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
142
  case drizzled::COM_QUIT : 
143
    return COM_QUIT;
144
  case drizzled::COM_INIT_DB : 
145
    return COM_INIT_DB;
146
  case drizzled::COM_QUERY : 
147
    return COM_QUERY;
148
  case drizzled::COM_SHUTDOWN : 
149
    return COM_SHUTDOWN;
150
  case drizzled::COM_CONNECT : 
151
    return COM_CONNECT;
152
  case drizzled::COM_PING : 
153
    return COM_PING;
154
  case drizzled::COM_END : 
155
    return COM_END;
156
  }
157
158
  assert(0);
159
  return PROGRAM_ERROR;
160
}
161
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
162
const std::string &type(drizzled::Item::Type type)
163
{
164
  switch (type)
165
  {
166
  case drizzled::Item::FIELD_ITEM :
167
    return FIELD_ITEM;
168
  case drizzled::Item::FUNC_ITEM :
169
    return FUNC_ITEM;
170
  case drizzled::Item::SUM_FUNC_ITEM :
171
    return SUM_FUNC_ITEM;
172
  case drizzled::Item::STRING_ITEM :
173
    return STRING_ITEM;
174
  case drizzled::Item::INT_ITEM :
175
    return INT_ITEM;
176
  case drizzled::Item::REAL_ITEM :
177
    return REAL_ITEM;
178
  case drizzled::Item::NULL_ITEM :
179
    return NULL_ITEM;
180
  case drizzled::Item::VARBIN_ITEM :
181
    return VARBIN_ITEM;
182
  case drizzled::Item::COPY_STR_ITEM :
183
    return COPY_STR_ITEM;
184
  case drizzled::Item::FIELD_AVG_ITEM :
185
    return FIELD_AVG_ITEM;
186
  case drizzled::Item::DEFAULT_VALUE_ITEM :
187
    return DEFAULT_VALUE_ITEM;
188
  case drizzled::Item::PROC_ITEM :
189
    return PROC_ITEM;
190
  case drizzled::Item::COND_ITEM :
191
    return COND_ITEM;
192
  case drizzled::Item::REF_ITEM :
193
    return REF_ITEM;
194
  case drizzled::Item::FIELD_STD_ITEM :
195
    return FIELD_STD_ITEM;
196
  case drizzled::Item::FIELD_VARIANCE_ITEM :
197
    return FIELD_VARIANCE_ITEM;
198
  case drizzled::Item::INSERT_VALUE_ITEM :
199
    return INSERT_VALUE_ITEM;
200
  case drizzled::Item::SUBSELECT_ITEM :
201
    return SUBSELECT_ITEM;
202
  case drizzled::Item::ROW_ITEM:
203
    return ROW_ITEM;
204
  case drizzled::Item::CACHE_ITEM :
205
    return CACHE_ITEM;
206
  case drizzled::Item::TYPE_HOLDER :
207
    return TYPE_HOLDER;
208
  case drizzled::Item::PARAM_ITEM :
209
    return PARAM_ITEM;
2023.2.7 by Brian Aker
Create an Bool primtive type for item.
210
  case drizzled::Item::BOOLEAN_ITEM :
211
    return BOOLEAN_ITEM;
1992.5.1 by Brian Aker
Additional cerr output bits for a few classes (Item, Field,...)
212
  case drizzled::Item::DECIMAL_ITEM :
213
    return DECIMAL_ITEM;
214
  }
215
216
  assert(0);
217
  return PROGRAM_ERROR;
218
}
219
2039.3.3 by Brian Aker
result_type() to display the internal type.
220
const std::string &type(Item_result type)
221
{
222
  switch (type)
223
  {
224
  case STRING_RESULT:
225
    return STRING_RESULT_STRING;
226
  case REAL_RESULT:
227
    return REAL_RESULT_STRING;
228
  case INT_RESULT:
229
    return INT_RESULT_STRING;
230
  case ROW_RESULT:
231
    return ROW_RESULT_STRING;
232
  case DECIMAL_RESULT:
233
    return DECIMAL_RESULT_STRING;
234
  }
235
236
  assert(0);
237
  return PROGRAM_ERROR;
238
}
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
239
240
const std::string &type(drizzled::enum_field_types type)
241
{
242
  switch (type)
243
  {
244
  case drizzled::DRIZZLE_TYPE_LONG : 
245
    return DRIZZLE_TYPE_LONG;
246
  case drizzled::DRIZZLE_TYPE_DOUBLE : 
247
    return DRIZZLE_TYPE_DOUBLE;
248
  case drizzled::DRIZZLE_TYPE_NULL : 
249
    return DRIZZLE_TYPE_NULL;
2046.2.1 by Brian Aker
First pass on micro timestamp.
250
  case drizzled::DRIZZLE_TYPE_MICROTIME : 
251
    return DRIZZLE_TYPE_MICROTIME;
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
252
  case drizzled::DRIZZLE_TYPE_TIMESTAMP : 
253
    return DRIZZLE_TYPE_TIMESTAMP;
254
  case drizzled::DRIZZLE_TYPE_LONGLONG : 
255
    return DRIZZLE_TYPE_LONGLONG;
256
  case drizzled::DRIZZLE_TYPE_DATETIME : 
257
    return DRIZZLE_TYPE_DATETIME;
1999.4.7 by Brian Aker
Merge in first pass of TIME type (closer to EPOCH time).
258
  case drizzled::DRIZZLE_TYPE_TIME : 
259
    return DRIZZLE_TYPE_TIME;
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
260
  case drizzled::DRIZZLE_TYPE_DATE : 
261
    return DRIZZLE_TYPE_DATE;
262
  case drizzled::DRIZZLE_TYPE_VARCHAR : 
263
    return DRIZZLE_TYPE_VARCHAR;
264
  case drizzled::DRIZZLE_TYPE_DECIMAL : 
265
    return DRIZZLE_TYPE_DECIMAL;
266
  case drizzled::DRIZZLE_TYPE_ENUM : 
267
    return DRIZZLE_TYPE_ENUM;
268
  case drizzled::DRIZZLE_TYPE_BLOB : 
269
    return DRIZZLE_TYPE_BLOB;
1996.2.1 by Brian Aker
uuid type code.
270
  case drizzled::DRIZZLE_TYPE_UUID : 
271
    return DRIZZLE_TYPE_UUID;
2023.2.2 by Brian Aker
Merge in BOOL change to BOOLEAN.
272
  case drizzled::DRIZZLE_TYPE_BOOLEAN : 
273
    return DRIZZLE_TYPE_BOOLEAN;
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
274
  }
275
276
  assert(0);
277
  return PROGRAM_ERROR;
278
}
279
1996.2.1 by Brian Aker
uuid type code.
280
std::string hexdump(const unsigned char *str, size_t length)
281
{
282
  static const char hexval[16] = { '0', '1', '2', '3', 
283
    '4', '5', '6', '7', 
284
    '8', '9', 'a', 'b', 
285
    'c', 'd', 'e', 'f' };
286
  unsigned max_cols = 16; 
287
  std::ostringstream buf;
288
  std::ostringstream raw_buf;
289
290
  const unsigned char *e= str + length;
291
  for (const unsigned char *i= str; i != e;)
292
  {
293
    raw_buf.str("");
294
    for (unsigned col = 0; col < max_cols; ++col)
295
    {
296
      if (i != e)
297
      {
298
        buf << hexval[ ( (*i >> 4) & 0xF ) ]
299
          << hexval[ ( *i & 0x0F ) ]
300
          << ' ';
301
        raw_buf << (isprint(*i) ? *i : '.');
302
        ++i;
303
      }
304
      else
305
      {
306
        buf << "   ";
307
      }
308
    }
309
  }
310
311
  return buf.str();
312
}
313
1921.4.7 by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single
314
} /* namespace display */
315
} /* namespace drizzled */