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 |
||
23 |
#include "drizzled/display.h" |
|
1996.2.1
by Brian Aker
uuid type code. |
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 |
|
26 |
#include <assert.h> |
|
27 |
||
28 |
namespace drizzled { |
|
29 |
namespace display { |
|
30 |
||
31 |
static const std::string PROGRAM_ERROR("PROGRAM_ERROR"); |
|
32 |
||
33 |
static const std::string COM_SLEEP("COM_SLEEP"); |
|
34 |
static const std::string COM_QUIT("COM_QUIT"); |
|
35 |
static const std::string COM_INIT_DB("COM_INIT_DB"); |
|
36 |
static const std::string COM_QUERY("COM_QUERY"); |
|
37 |
static const std::string COM_SHUTDOWN("COM_SHUTDOWN"); |
|
38 |
static const std::string COM_CONNECT("COM_CONNECT"); |
|
39 |
static const std::string COM_PING("COM_PING"); |
|
40 |
static const std::string COM_END("COM_END"); |
|
41 |
||
42 |
static const std::string DRIZZLE_TYPE_LONG("DRIZZLE_TYPE_LONG"); |
|
43 |
static const std::string DRIZZLE_TYPE_DOUBLE("DRIZZLE_TYPE_DOUBLE"); |
|
44 |
static const std::string DRIZZLE_TYPE_NULL("DRIZZLE_TYPE_NULL"); |
|
45 |
static const std::string DRIZZLE_TYPE_TIMESTAMP("DRIZZLE_TYPE_TIMESTAMP"); |
|
46 |
static const std::string DRIZZLE_TYPE_LONGLONG("DRIZZLE_TYPE_LONGLONG"); |
|
47 |
static const std::string DRIZZLE_TYPE_DATETIME("DRIZZLE_TYPE_DATETIME"); |
|
48 |
static const std::string DRIZZLE_TYPE_DATE("DRIZZLE_TYPE_DATE"); |
|
49 |
static const std::string DRIZZLE_TYPE_VARCHAR("DRIZZLE_TYPE_VARCHAR"); |
|
50 |
static const std::string DRIZZLE_TYPE_DECIMAL("DRIZZLE_TYPE_DECIMAL"); |
|
51 |
static const std::string DRIZZLE_TYPE_ENUM("DRIZZLE_TYPE_ENUM"); |
|
52 |
static const std::string DRIZZLE_TYPE_BLOB("DRIZZLE_TYPE_BLOB"); |
|
1996.2.1
by Brian Aker
uuid type code. |
53 |
static const std::string DRIZZLE_TYPE_UUID("DRIZZLE_TYPE_UUID"); |
54 |
||
55 |
static const std::string FIELD_ITEM("FIELD_ITEM"); |
|
56 |
static const std::string FUNC_ITEM("FUNC_ITEM"); |
|
57 |
static const std::string SUM_FUNC_ITEM("SUM_FUNC_ITEM"); |
|
58 |
static const std::string STRING_ITEM("STRING_ITEM"); |
|
59 |
static const std::string INT_ITEM("INT_ITEM"); |
|
60 |
static const std::string REAL_ITEM("REAL_ITEM"); |
|
61 |
static const std::string NULL_ITEM("NULL_ITEM"); |
|
62 |
static const std::string VARBIN_ITEM("VARBIN_ITEM"); |
|
63 |
static const std::string COPY_STR_ITEM("COPY_STR_ITEM"); |
|
64 |
static const std::string FIELD_AVG_ITEM("FIELD_AVG_ITEM"); |
|
65 |
static const std::string DEFAULT_VALUE_ITEM("DEFAULT_VALUE_ITEM"); |
|
66 |
static const std::string PROC_ITEM("PROC_ITEM"); |
|
67 |
static const std::string COND_ITEM("COND_ITEM"); |
|
68 |
static const std::string REF_ITEM("REF_ITEM"); |
|
69 |
static const std::string FIELD_STD_ITEM("FIELD_STD_ITEM"); |
|
70 |
static const std::string FIELD_VARIANCE_ITEM("FIELD_VARIANCE_ITEM"); |
|
71 |
static const std::string INSERT_VALUE_ITEM("INSERT_VALUE_ITEM"); |
|
72 |
static const std::string SUBSELECT_ITEM("SUBSELECT_ITEM"); |
|
73 |
static const std::string ROW_ITEM("ROW_ITEM"); |
|
74 |
static const std::string CACHE_ITEM("CACHE_ITEM"); |
|
75 |
static const std::string TYPE_HOLDER("TYPE_HOLDER"); |
|
76 |
static const std::string PARAM_ITEM("PARAM_ITEM"); |
|
77 |
static const std::string DECIMAL_ITEM("DECIMAL_ITEM"); |
|
1921.4.7
by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single |
78 |
|
79 |
static const std::string YES("YES"); |
|
80 |
static const std::string NO("NO"); |
|
81 |
||
82 |
const std::string &type(drizzled::enum_server_command type) |
|
83 |
{
|
|
84 |
switch (type) |
|
85 |
{
|
|
86 |
case drizzled::COM_SLEEP : |
|
87 |
return COM_SLEEP; |
|
88 |
case drizzled::COM_QUIT : |
|
89 |
return COM_QUIT; |
|
90 |
case drizzled::COM_INIT_DB : |
|
91 |
return COM_INIT_DB; |
|
92 |
case drizzled::COM_QUERY : |
|
93 |
return COM_QUERY; |
|
94 |
case drizzled::COM_SHUTDOWN : |
|
95 |
return COM_SHUTDOWN; |
|
96 |
case drizzled::COM_CONNECT : |
|
97 |
return COM_CONNECT; |
|
98 |
case drizzled::COM_PING : |
|
99 |
return COM_PING; |
|
100 |
case drizzled::COM_END : |
|
101 |
return COM_END; |
|
102 |
}
|
|
103 |
||
104 |
assert(0); |
|
105 |
return PROGRAM_ERROR; |
|
106 |
}
|
|
107 |
||
1996.2.1
by Brian Aker
uuid type code. |
108 |
const std::string &type(drizzled::Item::Type type) |
109 |
{
|
|
110 |
switch (type) |
|
111 |
{
|
|
112 |
case drizzled::Item::FIELD_ITEM : |
|
113 |
return FIELD_ITEM; |
|
114 |
case drizzled::Item::FUNC_ITEM : |
|
115 |
return FUNC_ITEM; |
|
116 |
case drizzled::Item::SUM_FUNC_ITEM : |
|
117 |
return SUM_FUNC_ITEM; |
|
118 |
case drizzled::Item::STRING_ITEM : |
|
119 |
return STRING_ITEM; |
|
120 |
case drizzled::Item::INT_ITEM : |
|
121 |
return INT_ITEM; |
|
122 |
case drizzled::Item::REAL_ITEM : |
|
123 |
return REAL_ITEM; |
|
124 |
case drizzled::Item::NULL_ITEM : |
|
125 |
return NULL_ITEM; |
|
126 |
case drizzled::Item::VARBIN_ITEM : |
|
127 |
return VARBIN_ITEM; |
|
128 |
case drizzled::Item::COPY_STR_ITEM : |
|
129 |
return COPY_STR_ITEM; |
|
130 |
case drizzled::Item::FIELD_AVG_ITEM : |
|
131 |
return FIELD_AVG_ITEM; |
|
132 |
case drizzled::Item::DEFAULT_VALUE_ITEM : |
|
133 |
return DEFAULT_VALUE_ITEM; |
|
134 |
case drizzled::Item::PROC_ITEM : |
|
135 |
return PROC_ITEM; |
|
136 |
case drizzled::Item::COND_ITEM : |
|
137 |
return COND_ITEM; |
|
138 |
case drizzled::Item::REF_ITEM : |
|
139 |
return REF_ITEM; |
|
140 |
case drizzled::Item::FIELD_STD_ITEM : |
|
141 |
return FIELD_STD_ITEM; |
|
142 |
case drizzled::Item::FIELD_VARIANCE_ITEM : |
|
143 |
return FIELD_VARIANCE_ITEM; |
|
144 |
case drizzled::Item::INSERT_VALUE_ITEM : |
|
145 |
return INSERT_VALUE_ITEM; |
|
146 |
case drizzled::Item::SUBSELECT_ITEM : |
|
147 |
return SUBSELECT_ITEM; |
|
148 |
case drizzled::Item::ROW_ITEM: |
|
149 |
return ROW_ITEM; |
|
150 |
case drizzled::Item::CACHE_ITEM : |
|
151 |
return CACHE_ITEM; |
|
152 |
case drizzled::Item::TYPE_HOLDER : |
|
153 |
return TYPE_HOLDER; |
|
154 |
case drizzled::Item::PARAM_ITEM : |
|
155 |
return PARAM_ITEM; |
|
156 |
case drizzled::Item::DECIMAL_ITEM : |
|
157 |
return DECIMAL_ITEM; |
|
158 |
}
|
|
159 |
||
160 |
assert(0); |
|
161 |
return PROGRAM_ERROR; |
|
162 |
}
|
|
163 |
||
1921.4.7
by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single |
164 |
|
165 |
const std::string &type(drizzled::enum_field_types type) |
|
166 |
{
|
|
167 |
switch (type) |
|
168 |
{
|
|
169 |
case drizzled::DRIZZLE_TYPE_LONG : |
|
170 |
return DRIZZLE_TYPE_LONG; |
|
171 |
case drizzled::DRIZZLE_TYPE_DOUBLE : |
|
172 |
return DRIZZLE_TYPE_DOUBLE; |
|
173 |
case drizzled::DRIZZLE_TYPE_NULL : |
|
174 |
return DRIZZLE_TYPE_NULL; |
|
175 |
case drizzled::DRIZZLE_TYPE_TIMESTAMP : |
|
176 |
return DRIZZLE_TYPE_TIMESTAMP; |
|
177 |
case drizzled::DRIZZLE_TYPE_LONGLONG : |
|
178 |
return DRIZZLE_TYPE_LONGLONG; |
|
179 |
case drizzled::DRIZZLE_TYPE_DATETIME : |
|
180 |
return DRIZZLE_TYPE_DATETIME; |
|
181 |
case drizzled::DRIZZLE_TYPE_DATE : |
|
182 |
return DRIZZLE_TYPE_DATE; |
|
183 |
case drizzled::DRIZZLE_TYPE_VARCHAR : |
|
184 |
return DRIZZLE_TYPE_VARCHAR; |
|
185 |
case drizzled::DRIZZLE_TYPE_DECIMAL : |
|
186 |
return DRIZZLE_TYPE_DECIMAL; |
|
187 |
case drizzled::DRIZZLE_TYPE_ENUM : |
|
188 |
return DRIZZLE_TYPE_ENUM; |
|
189 |
case drizzled::DRIZZLE_TYPE_BLOB : |
|
190 |
return DRIZZLE_TYPE_BLOB; |
|
1996.2.1
by Brian Aker
uuid type code. |
191 |
case drizzled::DRIZZLE_TYPE_UUID : |
192 |
return DRIZZLE_TYPE_UUID; |
|
1921.4.7
by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single |
193 |
}
|
194 |
||
195 |
assert(0); |
|
196 |
return PROGRAM_ERROR; |
|
197 |
}
|
|
198 |
||
1996.2.1
by Brian Aker
uuid type code. |
199 |
std::string hexdump(const unsigned char *str, size_t length) |
200 |
{
|
|
201 |
static const char hexval[16] = { '0', '1', '2', '3', |
|
202 |
'4', '5', '6', '7', |
|
203 |
'8', '9', 'a', 'b', |
|
204 |
'c', 'd', 'e', 'f' }; |
|
205 |
unsigned max_cols = 16; |
|
206 |
std::ostringstream buf; |
|
207 |
std::ostringstream raw_buf; |
|
208 |
||
209 |
const unsigned char *e= str + length; |
|
210 |
for (const unsigned char *i= str; i != e;) |
|
211 |
{
|
|
212 |
raw_buf.str(""); |
|
213 |
for (unsigned col = 0; col < max_cols; ++col) |
|
214 |
{
|
|
215 |
if (i != e) |
|
216 |
{
|
|
217 |
buf << hexval[ ( (*i >> 4) & 0xF ) ] |
|
218 |
<< hexval[ ( *i & 0x0F ) ] |
|
219 |
<< ' '; |
|
220 |
raw_buf << (isprint(*i) ? *i : '.'); |
|
221 |
++i; |
|
222 |
}
|
|
223 |
else
|
|
224 |
{
|
|
225 |
buf << " "; |
|
226 |
}
|
|
227 |
}
|
|
228 |
}
|
|
229 |
||
230 |
return buf.str(); |
|
231 |
}
|
|
232 |
||
1921.4.7
by Brian Aker
Test for issues on CONCURRENT to be sure it operates in a single |
233 |
} /* namespace display */ |
234 |
} /* namespace drizzled */ |