584.4.5
by Monty Taylor
Split out cache_row and type_holder. |
1 |
/* -*- mode: c++; c-basic-offset: 2; indent-tabs-mode: nil; -*-
|
2 |
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
|
|
3 |
*
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
4 |
* Copyright (C) 2008-2009 Sun Microsystems
|
584.4.5
by Monty Taylor
Split out cache_row and type_holder. |
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; version 2 of the License.
|
|
9 |
*
|
|
10 |
* This program is distributed in the hope that it will be useful,
|
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13 |
* GNU General Public License for more details.
|
|
14 |
*
|
|
15 |
* You should have received a copy of the GNU General Public License
|
|
16 |
* along with this program; if not, write to the Free Software
|
|
17 |
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
18 |
*/
|
|
1
by brian
clean slate |
19 |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
20 |
#include "drizzled/server_includes.h" |
21 |
#include "drizzled/sql_select.h" |
|
22 |
#include "drizzled/error.h" |
|
23 |
#include "drizzled/show.h" |
|
24 |
#include "drizzled/item/cmpfunc.h" |
|
25 |
#include "drizzled/item/cache_row.h" |
|
26 |
#include "drizzled/item/type_holder.h" |
|
27 |
#include "drizzled/item/sum.h" |
|
28 |
#include "drizzled/item/copy_string.h" |
|
29 |
#include "drizzled/function/str/conv_charset.h" |
|
30 |
#include "drizzled/sql_base.h" |
|
31 |
#include "drizzled/util/convert.h" |
|
32 |
||
33 |
#include "drizzled/field/str.h" |
|
34 |
#include "drizzled/field/num.h" |
|
35 |
#include "drizzled/field/blob.h" |
|
36 |
#include "drizzled/field/enum.h" |
|
37 |
#include "drizzled/field/null.h" |
|
38 |
#include "drizzled/field/date.h" |
|
39 |
#include "drizzled/field/decimal.h" |
|
40 |
#include "drizzled/field/real.h" |
|
41 |
#include "drizzled/field/double.h" |
|
42 |
#include "drizzled/field/long.h" |
|
43 |
#include "drizzled/field/int64_t.h" |
|
44 |
#include "drizzled/field/num.h" |
|
45 |
#include "drizzled/field/timestamp.h" |
|
46 |
#include "drizzled/field/datetime.h" |
|
47 |
#include "drizzled/field/varstring.h" |
|
584.5.1
by Monty Taylor
Removed field includes from field.h. |
48 |
|
919.2.11
by Monty Taylor
Removed C99 isnan() usage, which allows us to remove the util/math.{cc,h} workarounds. Yay for standards! |
49 |
#include <math.h> |
1067.4.4
by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc). |
50 |
#include <algorithm> |
51 |
||
52 |
using namespace std; |
|
971.3.65
by Eric Day
Namespace cleanup for Protocol and Listen. |
53 |
using namespace drizzled; |
1067.4.4
by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc). |
54 |
|
1
by brian
clean slate |
55 |
const String my_null_string("NULL", 4, default_charset_info); |
56 |
||
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
57 |
bool Item::is_expensive_processor(unsigned char *) |
58 |
{
|
|
681
by Brian Aker
Style cleanup |
59 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
60 |
}
|
61 |
||
846
by Brian Aker
Removing on typedeffed class. |
62 |
void Item::fix_after_pullout(Select_Lex *, Item **) |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
63 |
{}
|
64 |
||
65 |
Field *Item::tmp_table_field(Table *) |
|
66 |
{
|
|
681
by Brian Aker
Style cleanup |
67 |
return NULL; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
68 |
}
|
69 |
||
70 |
const char *Item::full_name(void) const |
|
71 |
{
|
|
72 |
return name ? name : "???"; |
|
73 |
}
|
|
74 |
||
75 |
int64_t Item::val_int_endpoint(bool, bool *) |
|
76 |
{
|
|
77 |
assert(0); |
|
78 |
return 0; |
|
79 |
}
|
|
80 |
||
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
81 |
/** @todo Make this functions class dependent */
|
1
by brian
clean slate |
82 |
bool Item::val_bool() |
83 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
84 |
switch(result_type()) |
1
by brian
clean slate |
85 |
{
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
86 |
case INT_RESULT: |
87 |
return val_int() != 0; |
|
88 |
case DECIMAL_RESULT: |
|
89 |
{
|
|
90 |
my_decimal decimal_value; |
|
91 |
my_decimal *val= val_decimal(&decimal_value); |
|
92 |
if (val) |
|
93 |
return !my_decimal_is_zero(val); |
|
94 |
return false; |
|
95 |
}
|
|
96 |
case REAL_RESULT: |
|
97 |
case STRING_RESULT: |
|
98 |
return val_real() != 0.0; |
|
99 |
case ROW_RESULT: |
|
100 |
default: |
|
101 |
assert(0); |
|
102 |
return false; |
|
1
by brian
clean slate |
103 |
}
|
104 |
}
|
|
105 |
||
106 |
String *Item::val_string_from_real(String *str) |
|
107 |
{
|
|
108 |
double nr= val_real(); |
|
109 |
if (null_value) |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
110 |
return NULL; /* purecov: inspected */ |
681
by Brian Aker
Style cleanup |
111 |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
112 |
str->set_real(nr, decimals, &my_charset_bin); |
1
by brian
clean slate |
113 |
return str; |
114 |
}
|
|
115 |
||
116 |
String *Item::val_string_from_int(String *str) |
|
117 |
{
|
|
152
by Brian Aker
longlong replacement |
118 |
int64_t nr= val_int(); |
1
by brian
clean slate |
119 |
if (null_value) |
681
by Brian Aker
Style cleanup |
120 |
return NULL; |
121 |
||
1
by brian
clean slate |
122 |
str->set_int(nr, unsigned_flag, &my_charset_bin); |
123 |
return str; |
|
124 |
}
|
|
125 |
||
126 |
String *Item::val_string_from_decimal(String *str) |
|
127 |
{
|
|
128 |
my_decimal dec_buf, *dec= val_decimal(&dec_buf); |
|
129 |
if (null_value) |
|
681
by Brian Aker
Style cleanup |
130 |
return NULL; |
131 |
||
56
by brian
Next pass of true/false update. |
132 |
my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, false, &dec_buf); |
1
by brian
clean slate |
133 |
my_decimal2string(E_DEC_FATAL_ERROR, &dec_buf, 0, 0, 0, str); |
134 |
return str; |
|
135 |
}
|
|
136 |
||
137 |
my_decimal *Item::val_decimal_from_real(my_decimal *decimal_value) |
|
138 |
{
|
|
139 |
double nr= val_real(); |
|
140 |
if (null_value) |
|
681
by Brian Aker
Style cleanup |
141 |
return NULL; |
142 |
||
1
by brian
clean slate |
143 |
double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value); |
144 |
return (decimal_value); |
|
145 |
}
|
|
146 |
||
147 |
my_decimal *Item::val_decimal_from_int(my_decimal *decimal_value) |
|
148 |
{
|
|
152
by Brian Aker
longlong replacement |
149 |
int64_t nr= val_int(); |
1
by brian
clean slate |
150 |
if (null_value) |
681
by Brian Aker
Style cleanup |
151 |
return NULL; |
152 |
||
1
by brian
clean slate |
153 |
int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value); |
154 |
return decimal_value; |
|
155 |
}
|
|
156 |
||
157 |
my_decimal *Item::val_decimal_from_string(my_decimal *decimal_value) |
|
158 |
{
|
|
159 |
String *res; |
|
160 |
char *end_ptr; |
|
161 |
if (!(res= val_str(&str_value))) |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
162 |
return NULL; |
1
by brian
clean slate |
163 |
|
164 |
end_ptr= (char*) res->ptr()+ res->length(); |
|
165 |
if (str2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM, |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
166 |
res->ptr(), |
167 |
res->length(), |
|
168 |
res->charset(), |
|
1
by brian
clean slate |
169 |
decimal_value) & E_DEC_BAD_NUM) |
170 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
171 |
push_warning_printf(current_session, |
172 |
DRIZZLE_ERROR::WARN_LEVEL_WARN, |
|
1
by brian
clean slate |
173 |
ER_TRUNCATED_WRONG_VALUE, |
174 |
ER(ER_TRUNCATED_WRONG_VALUE), "DECIMAL", |
|
175 |
str_value.c_ptr()); |
|
176 |
}
|
|
177 |
return decimal_value; |
|
178 |
}
|
|
179 |
||
180 |
my_decimal *Item::val_decimal_from_date(my_decimal *decimal_value) |
|
181 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
182 |
assert(fixed); |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
183 |
DRIZZLE_TIME ltime; |
1
by brian
clean slate |
184 |
if (get_date(<ime, TIME_FUZZY_DATE)) |
185 |
{
|
|
186 |
my_decimal_set_zero(decimal_value); |
|
187 |
null_value= 1; // set NULL, stop processing |
|
681
by Brian Aker
Style cleanup |
188 |
return NULL; |
1
by brian
clean slate |
189 |
}
|
190 |
return date2my_decimal(<ime, decimal_value); |
|
191 |
}
|
|
192 |
||
193 |
my_decimal *Item::val_decimal_from_time(my_decimal *decimal_value) |
|
194 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
195 |
assert(fixed); |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
196 |
DRIZZLE_TIME ltime; |
1
by brian
clean slate |
197 |
if (get_time(<ime)) |
198 |
{
|
|
199 |
my_decimal_set_zero(decimal_value); |
|
681
by Brian Aker
Style cleanup |
200 |
return NULL; |
1
by brian
clean slate |
201 |
}
|
202 |
return date2my_decimal(<ime, decimal_value); |
|
203 |
}
|
|
204 |
||
205 |
double Item::val_real_from_decimal() |
|
206 |
{
|
|
207 |
/* Note that fix_fields may not be called for Item_avg_field items */
|
|
208 |
double result; |
|
209 |
my_decimal value_buff, *dec_val= val_decimal(&value_buff); |
|
210 |
if (null_value) |
|
211 |
return 0.0; |
|
212 |
my_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result); |
|
213 |
return result; |
|
214 |
}
|
|
215 |
||
152
by Brian Aker
longlong replacement |
216 |
int64_t Item::val_int_from_decimal() |
1
by brian
clean slate |
217 |
{
|
218 |
/* Note that fix_fields may not be called for Item_avg_field items */
|
|
152
by Brian Aker
longlong replacement |
219 |
int64_t result; |
1
by brian
clean slate |
220 |
my_decimal value, *dec_val= val_decimal(&value); |
221 |
if (null_value) |
|
222 |
return 0; |
|
223 |
my_decimal2int(E_DEC_FATAL_ERROR, dec_val, unsigned_flag, &result); |
|
224 |
return result; |
|
225 |
}
|
|
226 |
||
227 |
int Item::save_time_in_field(Field *field) |
|
228 |
{
|
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
229 |
DRIZZLE_TIME ltime; |
1
by brian
clean slate |
230 |
if (get_time(<ime)) |
231 |
return set_field_to_null(field); |
|
232 |
field->set_notnull(); |
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
233 |
return field->store_time(<ime, DRIZZLE_TIMESTAMP_TIME); |
1
by brian
clean slate |
234 |
}
|
235 |
||
236 |
int Item::save_date_in_field(Field *field) |
|
237 |
{
|
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
238 |
DRIZZLE_TIME ltime; |
1
by brian
clean slate |
239 |
if (get_date(<ime, TIME_FUZZY_DATE)) |
240 |
return set_field_to_null(field); |
|
241 |
field->set_notnull(); |
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
242 |
return field->store_time(<ime, DRIZZLE_TIMESTAMP_DATETIME); |
1
by brian
clean slate |
243 |
}
|
244 |
||
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
245 |
/**
|
246 |
* Check if the Item is null and stores the NULL or the
|
|
247 |
* result value in the field accordingly.
|
|
248 |
*/
|
|
1
by brian
clean slate |
249 |
int Item::save_str_value_in_field(Field *field, String *result) |
250 |
{
|
|
251 |
if (null_value) |
|
252 |
return set_field_to_null(field); |
|
253 |
field->set_notnull(); |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
254 |
return field->store(result->ptr(), result->length(), collation.collation); |
1
by brian
clean slate |
255 |
}
|
256 |
||
257 |
Item::Item(): |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
258 |
is_expensive_cache(-1), |
259 |
name(0), |
|
260 |
name_length(0), |
|
261 |
orig_name(0), |
|
262 |
max_length(0), |
|
263 |
marker(0), |
|
264 |
decimals(0), |
|
265 |
fixed(false), |
|
266 |
maybe_null(false), |
|
267 |
null_value(false), |
|
268 |
unsigned_flag(false), |
|
269 |
with_sum_func(false), |
|
270 |
is_autogenerated_name(true), |
|
271 |
with_subselect(false), |
|
1
by brian
clean slate |
272 |
collation(&my_charset_bin, DERIVATION_COERCIBLE) |
273 |
{
|
|
274 |
cmp_context= (Item_result)-1; |
|
275 |
||
276 |
/* Put item in free list so that we can free all items at end */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
277 |
Session *session= current_session; |
278 |
next= session->free_list; |
|
279 |
session->free_list= this; |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
280 |
|
1
by brian
clean slate |
281 |
/*
|
282 |
Item constructor can be called during execution other then SQL_COM
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
283 |
command => we should check session->lex->current_select on zero (session->lex
|
1
by brian
clean slate |
284 |
can be uninitialised)
|
285 |
*/
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
286 |
if (session->lex->current_select) |
1
by brian
clean slate |
287 |
{
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
288 |
enum_parsing_place place= session->lex->current_select->parsing_place; |
289 |
if (place == SELECT_LIST || place == IN_HAVING) |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
290 |
session->lex->current_select->select_n_having_items++; |
1
by brian
clean slate |
291 |
}
|
292 |
}
|
|
293 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
294 |
Item::Item(Session *session, Item *item): |
1
by brian
clean slate |
295 |
is_expensive_cache(-1), |
296 |
str_value(item->str_value), |
|
297 |
name(item->name), |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
298 |
name_length(item->name_length), |
1
by brian
clean slate |
299 |
orig_name(item->orig_name), |
300 |
max_length(item->max_length), |
|
301 |
marker(item->marker), |
|
302 |
decimals(item->decimals), |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
303 |
fixed(item->fixed), |
1
by brian
clean slate |
304 |
maybe_null(item->maybe_null), |
305 |
null_value(item->null_value), |
|
306 |
unsigned_flag(item->unsigned_flag), |
|
307 |
with_sum_func(item->with_sum_func), |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
308 |
is_autogenerated_name(item->is_autogenerated_name), |
309 |
with_subselect(item->with_subselect), |
|
1
by brian
clean slate |
310 |
collation(item->collation), |
311 |
cmp_context(item->cmp_context) |
|
312 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
313 |
/* Put this item in the session's free list */
|
314 |
next= session->free_list; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
315 |
session->free_list= this; |
1
by brian
clean slate |
316 |
}
|
317 |
||
482
by Brian Aker
Remove uint. |
318 |
uint32_t Item::decimal_precision() const |
1
by brian
clean slate |
319 |
{
|
320 |
Item_result restype= result_type(); |
|
321 |
||
322 |
if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT)) |
|
1067.4.4
by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc). |
323 |
return min(my_decimal_length_to_precision(max_length, decimals, unsigned_flag), |
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
324 |
(uint32_t) DECIMAL_MAX_PRECISION); |
1067.4.4
by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc). |
325 |
return min(max_length, (uint32_t) DECIMAL_MAX_PRECISION); |
1
by brian
clean slate |
326 |
}
|
327 |
||
584.1.14
by Monty Taylor
Removed field.h from common_includes. |
328 |
int Item::decimal_int_part() const |
329 |
{
|
|
330 |
return my_decimal_int_part(decimal_precision(), decimals); |
|
331 |
}
|
|
332 |
||
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
333 |
void Item::print(String *str, enum_query_type) |
334 |
{
|
|
335 |
str->append(full_name()); |
|
336 |
}
|
|
337 |
||
1
by brian
clean slate |
338 |
void Item::print_item_w_name(String *str, enum_query_type query_type) |
339 |
{
|
|
340 |
print(str, query_type); |
|
341 |
||
342 |
if (name) |
|
343 |
{
|
|
344 |
str->append(STRING_WITH_LEN(" AS ")); |
|
895
by Brian Aker
Completion (?) of uint conversion. |
345 |
str->append_identifier(name, (uint32_t) strlen(name)); |
1
by brian
clean slate |
346 |
}
|
347 |
}
|
|
348 |
||
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
349 |
void Item::split_sum_func(Session *, Item **, List<Item> &) |
350 |
{}
|
|
351 |
||
1
by brian
clean slate |
352 |
void Item::cleanup() |
353 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
354 |
fixed= false; |
1
by brian
clean slate |
355 |
marker= 0; |
356 |
if (orig_name) |
|
357 |
name= orig_name; |
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
358 |
return; |
1
by brian
clean slate |
359 |
}
|
360 |
||
361 |
void Item::rename(char *new_name) |
|
362 |
{
|
|
363 |
/*
|
|
364 |
we can compare pointers to names here, because if name was not changed,
|
|
365 |
pointer will be same
|
|
366 |
*/
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
367 |
if (! orig_name && new_name != name) |
1
by brian
clean slate |
368 |
orig_name= name; |
369 |
name= new_name; |
|
370 |
}
|
|
371 |
||
481
by Brian Aker
Remove all of uchar. |
372 |
Item* Item::transform(Item_transformer transformer, unsigned char *arg) |
1
by brian
clean slate |
373 |
{
|
374 |
return (this->*transformer)(arg); |
|
375 |
}
|
|
376 |
||
482
by Brian Aker
Remove uint. |
377 |
bool Item::check_cols(uint32_t c) |
1
by brian
clean slate |
378 |
{
|
379 |
if (c != 1) |
|
380 |
{
|
|
381 |
my_error(ER_OPERAND_COLUMNS, MYF(0), c); |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
382 |
return true; |
1
by brian
clean slate |
383 |
}
|
681
by Brian Aker
Style cleanup |
384 |
return false; |
1
by brian
clean slate |
385 |
}
|
386 |
||
482
by Brian Aker
Remove uint. |
387 |
void Item::set_name(const char *str, uint32_t length, const CHARSET_INFO * const cs) |
1
by brian
clean slate |
388 |
{
|
389 |
if (!length) |
|
390 |
{
|
|
391 |
/* Empty string, used by AS or internal function like last_insert_id() */
|
|
392 |
name= (char*) str; |
|
393 |
name_length= 0; |
|
394 |
return; |
|
395 |
}
|
|
396 |
if (cs->ctype) |
|
397 |
{
|
|
482
by Brian Aker
Remove uint. |
398 |
uint32_t orig_len= length; |
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
399 |
while (length && ! my_isgraph(cs, *str)) |
400 |
{
|
|
401 |
/* Fix problem with yacc */
|
|
1
by brian
clean slate |
402 |
length--; |
403 |
str++; |
|
404 |
}
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
405 |
if (orig_len != length && ! is_autogenerated_name) |
1
by brian
clean slate |
406 |
{
|
407 |
if (length == 0) |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
408 |
push_warning_printf(current_session, |
409 |
DRIZZLE_ERROR::WARN_LEVEL_WARN, |
|
410 |
ER_NAME_BECOMES_EMPTY, |
|
411 |
ER(ER_NAME_BECOMES_EMPTY), |
|
1
by brian
clean slate |
412 |
str + length - orig_len); |
413 |
else
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
414 |
push_warning_printf(current_session, |
415 |
DRIZZLE_ERROR::WARN_LEVEL_WARN, |
|
416 |
ER_REMOVED_SPACES, |
|
417 |
ER(ER_REMOVED_SPACES), |
|
1
by brian
clean slate |
418 |
str + length - orig_len); |
419 |
}
|
|
420 |
}
|
|
1054.2.11
by Monty Taylor
Removed copy_and_convert. |
421 |
name= sql_strmake(str, length); |
1
by brian
clean slate |
422 |
}
|
423 |
||
575.1.2
by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead. |
424 |
bool Item::eq(const Item *item, bool) const |
1
by brian
clean slate |
425 |
{
|
426 |
/*
|
|
56
by brian
Next pass of true/false update. |
427 |
Note, that this is never true if item is a Item_param:
|
1
by brian
clean slate |
428 |
for all basic constants we have special checks, and Item_param's
|
429 |
type() can be only among basic constant types.
|
|
430 |
*/
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
431 |
return type() == item->type() && |
432 |
name && |
|
433 |
item->name && |
|
434 |
! my_strcasecmp(system_charset_info, name, item->name); |
|
1
by brian
clean slate |
435 |
}
|
436 |
||
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
437 |
Item *Item::safe_charset_converter(const CHARSET_INFO * const tocs) |
1
by brian
clean slate |
438 |
{
|
439 |
Item_func_conv_charset *conv= new Item_func_conv_charset(this, tocs, 1); |
|
440 |
return conv->safe ? conv : NULL; |
|
441 |
}
|
|
442 |
||
482
by Brian Aker
Remove uint. |
443 |
bool Item::get_date(DRIZZLE_TIME *ltime,uint32_t fuzzydate) |
1
by brian
clean slate |
444 |
{
|
445 |
if (result_type() == STRING_RESULT) |
|
446 |
{
|
|
447 |
char buff[40]; |
|
448 |
String tmp(buff,sizeof(buff), &my_charset_bin),*res; |
|
449 |
if (!(res=val_str(&tmp)) || |
|
450 |
str_to_datetime_with_warn(res->ptr(), res->length(), |
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
451 |
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR) |
1
by brian
clean slate |
452 |
goto err; |
453 |
}
|
|
454 |
else
|
|
455 |
{
|
|
152
by Brian Aker
longlong replacement |
456 |
int64_t value= val_int(); |
1
by brian
clean slate |
457 |
int was_cut; |
398.1.8
by Monty Taylor
Enabled -Wlong-long. |
458 |
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L) |
1
by brian
clean slate |
459 |
{
|
460 |
char buff[22], *end; |
|
152
by Brian Aker
longlong replacement |
461 |
end= int64_t10_to_str(value, buff, -10); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
462 |
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN, |
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
463 |
buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE, |
461
by Monty Taylor
Removed NullS. bu-bye. |
464 |
NULL); |
1
by brian
clean slate |
465 |
goto err; |
466 |
}
|
|
467 |
}
|
|
681
by Brian Aker
Style cleanup |
468 |
return false; |
1
by brian
clean slate |
469 |
|
470 |
err: |
|
212.6.6
by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove(). |
471 |
memset(ltime, 0, sizeof(*ltime)); |
681
by Brian Aker
Style cleanup |
472 |
return true; |
1
by brian
clean slate |
473 |
}
|
474 |
||
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
475 |
bool Item::get_time(DRIZZLE_TIME *ltime) |
1
by brian
clean slate |
476 |
{
|
477 |
char buff[40]; |
|
478 |
String tmp(buff,sizeof(buff),&my_charset_bin),*res; |
|
479 |
if (!(res=val_str(&tmp)) || |
|
480 |
str_to_time_with_warn(res->ptr(), res->length(), ltime)) |
|
481 |
{
|
|
212.6.6
by Mats Kindahl
Removing redundant use of casts in drizzled/ for memcmp(), memcpy(), memset(), and memmove(). |
482 |
memset(ltime, 0, sizeof(*ltime)); |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
483 |
return true; |
1
by brian
clean slate |
484 |
}
|
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
485 |
return false; |
486 |
}
|
|
487 |
||
488 |
bool Item::get_date_result(DRIZZLE_TIME *ltime,uint32_t fuzzydate) |
|
489 |
{
|
|
490 |
return get_date(ltime,fuzzydate); |
|
491 |
}
|
|
492 |
||
493 |
bool Item::is_null() |
|
494 |
{
|
|
495 |
return false; |
|
496 |
}
|
|
497 |
||
498 |
void Item::update_null_value () |
|
499 |
{
|
|
500 |
(void) val_int(); |
|
501 |
}
|
|
502 |
||
503 |
void Item::top_level_item(void) |
|
504 |
{}
|
|
505 |
||
506 |
void Item::set_result_field(Field *) |
|
507 |
{}
|
|
508 |
||
509 |
bool Item::is_result_field(void) |
|
510 |
{
|
|
681
by Brian Aker
Style cleanup |
511 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
512 |
}
|
513 |
||
514 |
bool Item::is_bool_func(void) |
|
515 |
{
|
|
681
by Brian Aker
Style cleanup |
516 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
517 |
}
|
518 |
||
519 |
void Item::save_in_result_field(bool) |
|
520 |
{}
|
|
521 |
||
522 |
void Item::no_rows_in_result(void) |
|
523 |
{}
|
|
524 |
||
525 |
Item *Item::copy_or_same(Session *) |
|
526 |
{
|
|
527 |
return this; |
|
528 |
}
|
|
529 |
||
530 |
Item *Item::copy_andor_structure(Session *) |
|
531 |
{
|
|
532 |
return this; |
|
533 |
}
|
|
534 |
||
535 |
Item *Item::real_item(void) |
|
536 |
{
|
|
537 |
return this; |
|
538 |
}
|
|
539 |
||
779.3.10
by Monty Taylor
Turned on -Wshadow. |
540 |
const Item *Item::real_item(void) const |
541 |
{
|
|
542 |
return this; |
|
543 |
}
|
|
544 |
||
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
545 |
Item *Item::get_tmp_table_item(Session *session) |
546 |
{
|
|
547 |
return copy_or_same(session); |
|
548 |
}
|
|
549 |
||
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
550 |
const CHARSET_INFO *Item::default_charset() |
1
by brian
clean slate |
551 |
{
|
748
by Brian Aker
Removal of client side collation. |
552 |
return current_session->variables.getCollation(); |
1
by brian
clean slate |
553 |
}
|
554 |
||
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
555 |
const CHARSET_INFO *Item::compare_collation() |
556 |
{
|
|
557 |
return NULL; |
|
558 |
}
|
|
559 |
||
560 |
bool Item::walk(Item_processor processor, bool, unsigned char *arg) |
|
561 |
{
|
|
562 |
return (this->*processor)(arg); |
|
563 |
}
|
|
564 |
||
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
565 |
Item* Item::compile(Item_analyzer analyzer, |
566 |
unsigned char **arg_p, |
|
567 |
Item_transformer transformer, |
|
568 |
unsigned char *arg_t) |
|
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
569 |
{
|
570 |
if ((this->*analyzer) (arg_p)) |
|
571 |
return ((this->*transformer) (arg_t)); |
|
681
by Brian Aker
Style cleanup |
572 |
return NULL; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
573 |
}
|
574 |
||
575 |
void Item::traverse_cond(Cond_traverser traverser, void *arg, traverse_order) |
|
576 |
{
|
|
577 |
(*traverser)(this, arg); |
|
578 |
}
|
|
579 |
||
580 |
bool Item::remove_dependence_processor(unsigned char *) |
|
581 |
{
|
|
681
by Brian Aker
Style cleanup |
582 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
583 |
}
|
584 |
||
585 |
bool Item::remove_fixed(unsigned char *) |
|
586 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
587 |
fixed= false; |
681
by Brian Aker
Style cleanup |
588 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
589 |
}
|
590 |
||
591 |
bool Item::collect_item_field_processor(unsigned char *) |
|
592 |
{
|
|
681
by Brian Aker
Style cleanup |
593 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
594 |
}
|
595 |
||
596 |
bool Item::find_item_in_field_list_processor(unsigned char *) |
|
597 |
{
|
|
681
by Brian Aker
Style cleanup |
598 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
599 |
}
|
600 |
||
601 |
bool Item::change_context_processor(unsigned char *) |
|
602 |
{
|
|
681
by Brian Aker
Style cleanup |
603 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
604 |
}
|
605 |
||
606 |
bool Item::reset_query_id_processor(unsigned char *) |
|
607 |
{
|
|
681
by Brian Aker
Style cleanup |
608 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
609 |
}
|
610 |
||
611 |
bool Item::register_field_in_read_map(unsigned char *) |
|
612 |
{
|
|
681
by Brian Aker
Style cleanup |
613 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
614 |
}
|
615 |
||
616 |
bool Item::subst_argument_checker(unsigned char **arg) |
|
617 |
{
|
|
618 |
if (*arg) |
|
619 |
*arg= NULL; |
|
620 |
return true; |
|
621 |
}
|
|
622 |
||
623 |
Item *Item::equal_fields_propagator(unsigned char *) |
|
624 |
{
|
|
625 |
return this; |
|
626 |
}
|
|
627 |
||
628 |
bool Item::set_no_const_sub(unsigned char *) |
|
629 |
{
|
|
630 |
return false; |
|
631 |
}
|
|
632 |
||
633 |
Item *Item::replace_equal_field(unsigned char *) |
|
634 |
{
|
|
635 |
return this; |
|
636 |
}
|
|
637 |
||
638 |
uint32_t Item::cols() |
|
639 |
{
|
|
640 |
return 1; |
|
641 |
}
|
|
642 |
||
643 |
Item* Item::element_index(uint32_t) |
|
644 |
{
|
|
645 |
return this; |
|
646 |
}
|
|
647 |
||
648 |
Item** Item::addr(uint32_t) |
|
649 |
{
|
|
681
by Brian Aker
Style cleanup |
650 |
return NULL; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
651 |
}
|
652 |
||
653 |
bool Item::null_inside() |
|
654 |
{
|
|
681
by Brian Aker
Style cleanup |
655 |
return false; |
584.4.8
by Monty Taylor
Moved stuff from item.h to item.cc |
656 |
}
|
657 |
||
658 |
void Item::bring_value() |
|
659 |
{}
|
|
660 |
||
661 |
Item *Item::neg_transformer(Session *) |
|
662 |
{
|
|
663 |
return NULL; |
|
664 |
}
|
|
665 |
||
666 |
Item *Item::update_value_transformer(unsigned char *) |
|
667 |
{
|
|
668 |
return this; |
|
669 |
}
|
|
670 |
||
671 |
void Item::delete_self() |
|
672 |
{
|
|
673 |
cleanup(); |
|
674 |
delete this; |
|
675 |
}
|
|
676 |
||
677 |
bool Item::result_as_int64_t() |
|
678 |
{
|
|
679 |
return false; |
|
680 |
}
|
|
681 |
||
682 |
bool Item::is_expensive() |
|
683 |
{
|
|
684 |
if (is_expensive_cache < 0) |
|
685 |
is_expensive_cache= walk(&Item::is_expensive_processor, 0, |
|
686 |
(unsigned char*)0); |
|
687 |
return test(is_expensive_cache); |
|
688 |
}
|
|
689 |
||
1
by brian
clean slate |
690 |
int Item::save_in_field_no_warnings(Field *field, bool no_conversions) |
691 |
{
|
|
692 |
int res; |
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
693 |
Table *table= field->table; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
694 |
Session *session= table->in_use; |
695 |
enum_check_fields tmp= session->count_cuted_fields; |
|
696 |
ulong sql_mode= session->variables.sql_mode; |
|
697 |
session->variables.sql_mode&= ~(MODE_NO_ZERO_DATE); |
|
698 |
session->count_cuted_fields= CHECK_FIELD_IGNORE; |
|
1
by brian
clean slate |
699 |
res= save_in_field(field, no_conversions); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
700 |
session->count_cuted_fields= tmp; |
701 |
session->variables.sql_mode= sql_mode; |
|
1
by brian
clean slate |
702 |
return res; |
703 |
}
|
|
704 |
||
705 |
/*
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
706 |
need a special class to adjust printing : references to aggregate functions
|
1
by brian
clean slate |
707 |
must not be printed as refs because the aggregate functions that are added to
|
708 |
the front of select list are not printed as well.
|
|
709 |
*/
|
|
710 |
class Item_aggregate_ref : public Item_ref |
|
711 |
{
|
|
712 |
public: |
|
713 |
Item_aggregate_ref(Name_resolution_context *context_arg, Item **item, |
|
714 |
const char *table_name_arg, const char *field_name_arg) |
|
715 |
:Item_ref(context_arg, item, table_name_arg, field_name_arg) {} |
|
716 |
||
717 |
virtual inline void print (String *str, enum_query_type query_type) |
|
718 |
{
|
|
719 |
if (ref) |
|
720 |
(*ref)->print(str, query_type); |
|
721 |
else
|
|
722 |
Item_ident::print(str, query_type); |
|
723 |
}
|
|
724 |
};
|
|
725 |
||
584.4.9
by Monty Taylor
Renamed split_sum_func2 to split_sum_func. It's C++. |
726 |
void Item::split_sum_func(Session *session, Item **ref_pointer_array, |
727 |
List<Item> &fields, Item **ref, |
|
728 |
bool skip_registered) |
|
1
by brian
clean slate |
729 |
{
|
584.4.9
by Monty Taylor
Renamed split_sum_func2 to split_sum_func. It's C++. |
730 |
/* An item of type Item_sum is registered <=> ref_by != 0 */
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
731 |
if (type() == SUM_FUNC_ITEM && |
732 |
skip_registered && |
|
1
by brian
clean slate |
733 |
((Item_sum *) this)->ref_by) |
584.4.9
by Monty Taylor
Renamed split_sum_func2 to split_sum_func. It's C++. |
734 |
return; |
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
735 |
|
1
by brian
clean slate |
736 |
if ((type() != SUM_FUNC_ITEM && with_sum_func) || |
737 |
(type() == FUNC_ITEM && |
|
738 |
(((Item_func *) this)->functype() == Item_func::ISNOTNULLTEST_FUNC || |
|
739 |
((Item_func *) this)->functype() == Item_func::TRIG_COND_FUNC))) |
|
740 |
{
|
|
741 |
/* Will split complicated items and ignore simple ones */
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
742 |
split_sum_func(session, ref_pointer_array, fields); |
1
by brian
clean slate |
743 |
}
|
744 |
else if ((type() == SUM_FUNC_ITEM || (used_tables() & ~PARAM_TABLE_BIT)) && |
|
745 |
type() != SUBSELECT_ITEM && |
|
609
by Brian Aker
Dead class removal (more views) |
746 |
type() != REF_ITEM) |
1
by brian
clean slate |
747 |
{
|
748 |
/*
|
|
749 |
Replace item with a reference so that we can easily calculate
|
|
750 |
it (in case of sum functions) or copy it (in case of fields)
|
|
751 |
||
752 |
The test above is to ensure we don't do a reference for things
|
|
753 |
that are constants (PARAM_TABLE_BIT is in effect a constant)
|
|
754 |
or already referenced (for example an item in HAVING)
|
|
755 |
Exception is Item_direct_view_ref which we need to convert to
|
|
756 |
Item_ref to allow fields from view being stored in tmp table.
|
|
757 |
*/
|
|
758 |
Item_aggregate_ref *item_ref; |
|
482
by Brian Aker
Remove uint. |
759 |
uint32_t el= fields.elements; |
1
by brian
clean slate |
760 |
Item *real_itm= real_item(); |
761 |
||
762 |
ref_pointer_array[el]= real_itm; |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
763 |
if (!(item_ref= new Item_aggregate_ref(&session->lex->current_select->context, |
1
by brian
clean slate |
764 |
ref_pointer_array + el, 0, name))) |
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
765 |
return; /* fatal_error is set */ |
1
by brian
clean slate |
766 |
if (type() == SUM_FUNC_ITEM) |
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
767 |
item_ref->depended_from= ((Item_sum *) this)->depended_from(); |
1
by brian
clean slate |
768 |
fields.push_front(real_itm); |
520.1.22
by Brian Aker
Second pass of thd cleanup |
769 |
session->change_item_tree(ref, item_ref); |
1
by brian
clean slate |
770 |
}
|
771 |
}
|
|
772 |
||
773 |
/*
|
|
774 |
Functions to convert item to field (for send_fields)
|
|
775 |
*/
|
|
575.1.2
by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead. |
776 |
bool Item::fix_fields(Session *, Item **) |
1
by brian
clean slate |
777 |
{
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
778 |
/* We do not check fields which are fixed during construction */
|
779 |
assert(! fixed || basic_const_item()); |
|
780 |
fixed= true; |
|
56
by brian
Next pass of true/false update. |
781 |
return false; |
1
by brian
clean slate |
782 |
}
|
783 |
||
846
by Brian Aker
Removing on typedeffed class. |
784 |
void mark_as_dependent(Session *session, Select_Lex *last, Select_Lex *current, |
1
by brian
clean slate |
785 |
Item_ident *resolved_item, |
786 |
Item_ident *mark_item) |
|
787 |
{
|
|
788 |
const char *db_name= (resolved_item->db_name ? |
|
789 |
resolved_item->db_name : ""); |
|
790 |
const char *table_name= (resolved_item->table_name ? |
|
791 |
resolved_item->table_name : ""); |
|
846
by Brian Aker
Removing on typedeffed class. |
792 |
/* store pointer on Select_Lex from which item is dependent */
|
1
by brian
clean slate |
793 |
if (mark_item) |
794 |
mark_item->depended_from= last; |
|
795 |
current->mark_as_dependent(last); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
796 |
if (session->lex->describe & DESCRIBE_EXTENDED) |
1
by brian
clean slate |
797 |
{
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
798 |
char warn_buff[DRIZZLE_ERRMSG_SIZE]; |
1
by brian
clean slate |
799 |
sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED), |
800 |
db_name, (db_name[0] ? "." : ""), |
|
801 |
table_name, (table_name [0] ? "." : ""), |
|
802 |
resolved_item->field_name, |
|
803 |
current->select_number, last->select_number); |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
804 |
push_warning(session, DRIZZLE_ERROR::WARN_LEVEL_NOTE, |
1
by brian
clean slate |
805 |
ER_WARN_FIELD_RESOLVED, warn_buff); |
806 |
}
|
|
807 |
}
|
|
808 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
809 |
void mark_select_range_as_dependent(Session *session, |
846
by Brian Aker
Removing on typedeffed class. |
810 |
Select_Lex *last_select, |
811 |
Select_Lex *current_sel, |
|
1
by brian
clean slate |
812 |
Field *found_field, Item *found_item, |
813 |
Item_ident *resolved_item) |
|
814 |
{
|
|
815 |
/*
|
|
816 |
Go from current SELECT to SELECT where field was resolved (it
|
|
817 |
have to be reachable from current SELECT, because it was already
|
|
818 |
done once when we resolved this field and cached result of
|
|
819 |
resolving)
|
|
820 |
*/
|
|
846
by Brian Aker
Removing on typedeffed class. |
821 |
Select_Lex *previous_select= current_sel; |
1
by brian
clean slate |
822 |
for (; previous_select->outer_select() != last_select; |
823 |
previous_select= previous_select->outer_select()) |
|
824 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
825 |
Item_subselect *prev_subselect_item= previous_select->master_unit()->item; |
1
by brian
clean slate |
826 |
prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT; |
827 |
prev_subselect_item->const_item_cache= 0; |
|
828 |
}
|
|
829 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
830 |
Item_subselect *prev_subselect_item= previous_select->master_unit()->item; |
1
by brian
clean slate |
831 |
Item_ident *dependent= resolved_item; |
832 |
if (found_field == view_ref_found) |
|
833 |
{
|
|
834 |
Item::Type type= found_item->type(); |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
835 |
prev_subselect_item->used_tables_cache|= found_item->used_tables(); |
1
by brian
clean slate |
836 |
dependent= ((type == Item::REF_ITEM || type == Item::FIELD_ITEM) ? |
837 |
(Item_ident*) found_item : |
|
838 |
0); |
|
839 |
}
|
|
840 |
else
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
841 |
prev_subselect_item->used_tables_cache|= found_field->table->map; |
1
by brian
clean slate |
842 |
prev_subselect_item->const_item_cache= 0; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
843 |
mark_as_dependent(session, last_select, current_sel, resolved_item, |
1
by brian
clean slate |
844 |
dependent); |
845 |
}
|
|
846 |
}
|
|
847 |
||
848 |
/**
|
|
849 |
Search a GROUP BY clause for a field with a certain name.
|
|
850 |
||
851 |
Search the GROUP BY list for a column named as find_item. When searching
|
|
852 |
preference is given to columns that are qualified with the same table (and
|
|
853 |
database) name as the one being searched for.
|
|
854 |
||
855 |
@param find_item the item being searched for
|
|
856 |
@param group_list GROUP BY clause
|
|
857 |
||
858 |
@return
|
|
859 |
- the found item on success
|
|
860 |
- NULL if find_item is not in group_list
|
|
861 |
*/
|
|
327.2.3
by Brian Aker
Refactoring of class Table |
862 |
static Item** find_field_in_group_list(Item *find_item, order_st *group_list) |
1
by brian
clean slate |
863 |
{
|
864 |
const char *db_name; |
|
865 |
const char *table_name; |
|
866 |
const char *field_name; |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
867 |
order_st *found_group= NULL; |
868 |
int found_match_degree= 0; |
|
1
by brian
clean slate |
869 |
Item_ident *cur_field; |
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
870 |
int cur_match_degree= 0; |
871 |
char name_buff[NAME_LEN+1]; |
|
1
by brian
clean slate |
872 |
|
873 |
if (find_item->type() == Item::FIELD_ITEM || |
|
874 |
find_item->type() == Item::REF_ITEM) |
|
875 |
{
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
876 |
db_name= ((Item_ident*) find_item)->db_name; |
1
by brian
clean slate |
877 |
table_name= ((Item_ident*) find_item)->table_name; |
878 |
field_name= ((Item_ident*) find_item)->field_name; |
|
879 |
}
|
|
880 |
else
|
|
881 |
return NULL; |
|
882 |
||
1039.1.5
by Brian Aker
Remove lower case filename bits (aka we just lock into the most compatible |
883 |
if (db_name) |
1
by brian
clean slate |
884 |
{
|
885 |
/* Convert database to lower case for comparison */
|
|
629.5.4
by Toru Maesaka
Fourth pass of replacing MySQL's strmake() with libc calls |
886 |
strncpy(name_buff, db_name, sizeof(name_buff)-1); |
1
by brian
clean slate |
887 |
my_casedn_str(files_charset_info, name_buff); |
888 |
db_name= name_buff; |
|
889 |
}
|
|
890 |
||
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
891 |
assert(field_name != 0); |
1
by brian
clean slate |
892 |
|
327.2.3
by Brian Aker
Refactoring of class Table |
893 |
for (order_st *cur_group= group_list ; cur_group ; cur_group= cur_group->next) |
1
by brian
clean slate |
894 |
{
|
895 |
if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM) |
|
896 |
{
|
|
897 |
cur_field= (Item_ident*) *cur_group->item; |
|
898 |
cur_match_degree= 0; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
899 |
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
900 |
assert(cur_field->field_name != 0); |
1
by brian
clean slate |
901 |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
902 |
if (! my_strcasecmp(system_charset_info, cur_field->field_name, field_name)) |
1
by brian
clean slate |
903 |
++cur_match_degree; |
904 |
else
|
|
905 |
continue; |
|
906 |
||
907 |
if (cur_field->table_name && table_name) |
|
908 |
{
|
|
909 |
/* If field_name is qualified by a table name. */
|
|
910 |
if (my_strcasecmp(table_alias_charset, cur_field->table_name, table_name)) |
|
911 |
/* Same field names, different tables. */
|
|
912 |
return NULL; |
|
913 |
||
914 |
++cur_match_degree; |
|
915 |
if (cur_field->db_name && db_name) |
|
916 |
{
|
|
917 |
/* If field_name is also qualified by a database name. */
|
|
918 |
if (strcmp(cur_field->db_name, db_name)) |
|
919 |
/* Same field names, different databases. */
|
|
920 |
return NULL; |
|
921 |
++cur_match_degree; |
|
922 |
}
|
|
923 |
}
|
|
924 |
||
925 |
if (cur_match_degree > found_match_degree) |
|
926 |
{
|
|
927 |
found_match_degree= cur_match_degree; |
|
928 |
found_group= cur_group; |
|
929 |
}
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
930 |
else if (found_group && |
931 |
(cur_match_degree == found_match_degree) && |
|
1
by brian
clean slate |
932 |
! (*(found_group->item))->eq(cur_field, 0)) |
933 |
{
|
|
934 |
/*
|
|
935 |
If the current resolve candidate matches equally well as the current
|
|
936 |
best match, they must reference the same column, otherwise the field
|
|
937 |
is ambiguous.
|
|
938 |
*/
|
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
939 |
my_error(ER_NON_UNIQ_ERROR, MYF(0), find_item->full_name(), current_session->where); |
1
by brian
clean slate |
940 |
return NULL; |
941 |
}
|
|
942 |
}
|
|
943 |
}
|
|
944 |
||
945 |
if (found_group) |
|
946 |
return found_group->item; |
|
947 |
else
|
|
948 |
return NULL; |
|
949 |
}
|
|
950 |
||
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
951 |
Item** resolve_ref_in_select_and_group(Session *session, Item_ident *ref, Select_Lex *select) |
1
by brian
clean slate |
952 |
{
|
953 |
Item **group_by_ref= NULL; |
|
954 |
Item **select_ref= NULL; |
|
327.2.3
by Brian Aker
Refactoring of class Table |
955 |
order_st *group_list= (order_st*) select->group_list.first; |
56
by brian
Next pass of true/false update. |
956 |
bool ambiguous_fields= false; |
482
by Brian Aker
Remove uint. |
957 |
uint32_t counter; |
1
by brian
clean slate |
958 |
enum_resolution_type resolution; |
959 |
||
960 |
/*
|
|
961 |
Search for a column or derived column named as 'ref' in the SELECT
|
|
962 |
clause of the current select.
|
|
963 |
*/
|
|
964 |
if (!(select_ref= find_item_in_list(ref, *(select->get_item_list()), |
|
965 |
&counter, REPORT_EXCEPT_NOT_FOUND, |
|
966 |
&resolution))) |
|
967 |
return NULL; /* Some error occurred. */ |
|
968 |
if (resolution == RESOLVED_AGAINST_ALIAS) |
|
56
by brian
Next pass of true/false update. |
969 |
ref->alias_name_used= true; |
1
by brian
clean slate |
970 |
|
971 |
/* If this is a non-aggregated field inside HAVING, search in GROUP BY. */
|
|
972 |
if (select->having_fix_field && !ref->with_sum_func && group_list) |
|
973 |
{
|
|
974 |
group_by_ref= find_field_in_group_list(ref, group_list); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
975 |
|
1
by brian
clean slate |
976 |
/* Check if the fields found in SELECT and GROUP BY are the same field. */
|
977 |
if (group_by_ref && (select_ref != not_found_item) && |
|
978 |
!((*group_by_ref)->eq(*select_ref, 0))) |
|
979 |
{
|
|
56
by brian
Next pass of true/false update. |
980 |
ambiguous_fields= true; |
520.1.22
by Brian Aker
Second pass of thd cleanup |
981 |
push_warning_printf(session, DRIZZLE_ERROR::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR, |
1
by brian
clean slate |
982 |
ER(ER_NON_UNIQ_ERROR), ref->full_name(), |
520.1.22
by Brian Aker
Second pass of thd cleanup |
983 |
current_session->where); |
1
by brian
clean slate |
984 |
|
985 |
}
|
|
986 |
}
|
|
987 |
||
988 |
if (select_ref != not_found_item || group_by_ref) |
|
989 |
{
|
|
990 |
if (select_ref != not_found_item && !ambiguous_fields) |
|
991 |
{
|
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
992 |
assert(*select_ref != 0); |
1
by brian
clean slate |
993 |
if (!select->ref_pointer_array[counter]) |
994 |
{
|
|
995 |
my_error(ER_ILLEGAL_REFERENCE, MYF(0), |
|
996 |
ref->name, "forward reference in item list"); |
|
997 |
return NULL; |
|
998 |
}
|
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
999 |
assert((*select_ref)->fixed); |
1
by brian
clean slate |
1000 |
return (select->ref_pointer_array + counter); |
1001 |
}
|
|
1002 |
if (group_by_ref) |
|
1003 |
return group_by_ref; |
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
1004 |
assert(false); |
1
by brian
clean slate |
1005 |
return NULL; /* So there is no compiler warning. */ |
1006 |
}
|
|
1007 |
||
1008 |
return (Item**) not_found_item; |
|
1009 |
}
|
|
1010 |
||
1052.2.4
by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards. |
1011 |
void Item::init_make_field(SendField *tmp_field, |
1
by brian
clean slate |
1012 |
enum enum_field_types field_type_arg) |
1013 |
{
|
|
1014 |
char *empty_name= (char*) ""; |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
1015 |
tmp_field->db_name= empty_name; |
1016 |
tmp_field->org_table_name= empty_name; |
|
1017 |
tmp_field->org_col_name= empty_name; |
|
1018 |
tmp_field->table_name= empty_name; |
|
1019 |
tmp_field->col_name= name; |
|
1020 |
tmp_field->charsetnr= collation.collation->number; |
|
1021 |
tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) | |
|
1022 |
(my_binary_compare(collation.collation) ? |
|
1023 |
BINARY_FLAG : 0); |
|
1024 |
tmp_field->type= field_type_arg; |
|
1025 |
tmp_field->length= max_length; |
|
1026 |
tmp_field->decimals= decimals; |
|
1
by brian
clean slate |
1027 |
}
|
1028 |
||
1052.2.4
by Nathan Williams
No actual code changes. Changed Send_field to SendField to be consistent with coding standards. |
1029 |
void Item::make_field(SendField *tmp_field) |
1
by brian
clean slate |
1030 |
{
|
1031 |
init_make_field(tmp_field, field_type()); |
|
1032 |
}
|
|
1033 |
||
1034 |
enum_field_types Item::string_field_type() const |
|
1035 |
{
|
|
240
by Brian Aker
Removed old/dead VARCHAR type from pre-5.0 |
1036 |
enum_field_types f_type= DRIZZLE_TYPE_VARCHAR; |
113
by Brian Aker
First pass on removing blob internals. |
1037 |
if (max_length >= 65536) |
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1038 |
f_type= DRIZZLE_TYPE_BLOB; |
1
by brian
clean slate |
1039 |
return f_type; |
1040 |
}
|
|
1041 |
||
1042 |
enum_field_types Item::field_type() const |
|
1043 |
{
|
|
1044 |
switch (result_type()) { |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
1045 |
case STRING_RESULT: |
1046 |
return string_field_type(); |
|
1047 |
case INT_RESULT: |
|
1048 |
return DRIZZLE_TYPE_LONGLONG; |
|
1049 |
case DECIMAL_RESULT: |
|
1050 |
return DRIZZLE_TYPE_NEWDECIMAL; |
|
1051 |
case REAL_RESULT: |
|
1052 |
return DRIZZLE_TYPE_DOUBLE; |
|
1
by brian
clean slate |
1053 |
case ROW_RESULT: |
1054 |
default: |
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
1055 |
assert(0); |
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1056 |
return DRIZZLE_TYPE_VARCHAR; |
1
by brian
clean slate |
1057 |
}
|
1058 |
}
|
|
1059 |
||
1060 |
bool Item::is_datetime() |
|
1061 |
{
|
|
1062 |
switch (field_type()) |
|
1063 |
{
|
|
575.5.1
by David Axmark
Changed NEWDATE to DATE. One failing test but I think its somewhere else in the code |
1064 |
case DRIZZLE_TYPE_DATE: |
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1065 |
case DRIZZLE_TYPE_DATETIME: |
1066 |
case DRIZZLE_TYPE_TIMESTAMP: |
|
56
by brian
Next pass of true/false update. |
1067 |
return true; |
1
by brian
clean slate |
1068 |
default: |
1069 |
break; |
|
1070 |
}
|
|
56
by brian
Next pass of true/false update. |
1071 |
return false; |
1
by brian
clean slate |
1072 |
}
|
1073 |
||
1074 |
String *Item::check_well_formed_result(String *str, bool send_error) |
|
1075 |
{
|
|
1076 |
/* Check whether we got a well-formed string */
|
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1077 |
const CHARSET_INFO * const cs= str->charset(); |
1
by brian
clean slate |
1078 |
int well_formed_error; |
482
by Brian Aker
Remove uint. |
1079 |
uint32_t wlen= cs->cset->well_formed_len(cs, |
1
by brian
clean slate |
1080 |
str->ptr(), str->ptr() + str->length(), |
1081 |
str->length(), &well_formed_error); |
|
1082 |
if (wlen < str->length()) |
|
1083 |
{
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1084 |
Session *session= current_session; |
1
by brian
clean slate |
1085 |
char hexbuf[7]; |
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
1086 |
enum DRIZZLE_ERROR::enum_warning_level level; |
482
by Brian Aker
Remove uint. |
1087 |
uint32_t diff= str->length() - wlen; |
937.2.6
by Stewart Smith
make set_if_bigger typesafe for C and C++. Fix up everywhere. |
1088 |
set_if_smaller(diff, 3U); |
971.3.9
by Eric Day
Removed dependency for hex convert, fixed a few Protocol class issues for Solaris. |
1089 |
(void) drizzled_string_to_hex(hexbuf, str->ptr() + wlen, diff); |
1
by brian
clean slate |
1090 |
if (send_error) |
1091 |
{
|
|
1092 |
my_error(ER_INVALID_CHARACTER_STRING, MYF(0), |
|
1093 |
cs->csname, hexbuf); |
|
681
by Brian Aker
Style cleanup |
1094 |
return NULL; |
1
by brian
clean slate |
1095 |
}
|
1096 |
{
|
|
261.4.1
by Felipe
- Renamed MYSQL_ERROR to DRIZZLE_ERROR. |
1097 |
level= DRIZZLE_ERROR::WARN_LEVEL_ERROR; |
1
by brian
clean slate |
1098 |
null_value= 1; |
1099 |
str= 0; |
|
1100 |
}
|
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1101 |
push_warning_printf(session, level, ER_INVALID_CHARACTER_STRING, |
1
by brian
clean slate |
1102 |
ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf); |
1103 |
}
|
|
1104 |
return str; |
|
1105 |
}
|
|
1106 |
||
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1107 |
bool Item::eq_by_collation(Item *item, bool binary_cmp, const CHARSET_INFO * const cs) |
1
by brian
clean slate |
1108 |
{
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1109 |
const CHARSET_INFO *save_cs= 0; |
1110 |
const CHARSET_INFO *save_item_cs= 0; |
|
1
by brian
clean slate |
1111 |
if (collation.collation != cs) |
1112 |
{
|
|
1113 |
save_cs= collation.collation; |
|
1114 |
collation.collation= cs; |
|
1115 |
}
|
|
1116 |
if (item->collation.collation != cs) |
|
1117 |
{
|
|
1118 |
save_item_cs= item->collation.collation; |
|
1119 |
item->collation.collation= cs; |
|
1120 |
}
|
|
1121 |
bool res= eq(item, binary_cmp); |
|
1122 |
if (save_cs) |
|
1123 |
collation.collation= save_cs; |
|
1124 |
if (save_item_cs) |
|
1125 |
item->collation.collation= save_item_cs; |
|
1126 |
return res; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1127 |
}
|
1
by brian
clean slate |
1128 |
|
327.1.5
by Brian Aker
Refactor around classes. TABLE_LIST has been factored out of table.h |
1129 |
Field *Item::make_string_field(Table *table) |
1
by brian
clean slate |
1130 |
{
|
1131 |
Field *field; |
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
1132 |
assert(collation.collation); |
1
by brian
clean slate |
1133 |
if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB) |
1134 |
field= new Field_blob(max_length, maybe_null, name, |
|
1135 |
collation.collation); |
|
241
by Brian Aker
First pass of CHAR removal. |
1136 |
else
|
1
by brian
clean slate |
1137 |
field= new Field_varstring(max_length, maybe_null, name, table->s, |
1138 |
collation.collation); |
|
241
by Brian Aker
First pass of CHAR removal. |
1139 |
|
1
by brian
clean slate |
1140 |
if (field) |
1141 |
field->init(table); |
|
1142 |
return field; |
|
1143 |
}
|
|
1144 |
||
575.1.2
by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead. |
1145 |
Field *Item::tmp_table_field_from_field_type(Table *table, bool) |
1
by brian
clean slate |
1146 |
{
|
1147 |
/*
|
|
1148 |
The field functions defines a field to be not null if null_ptr is not 0
|
|
1149 |
*/
|
|
481
by Brian Aker
Remove all of uchar. |
1150 |
unsigned char *null_ptr= maybe_null ? (unsigned char*) "" : 0; |
1
by brian
clean slate |
1151 |
Field *field; |
1152 |
||
1153 |
switch (field_type()) { |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1154 |
case DRIZZLE_TYPE_NEWDECIMAL: |
481
by Brian Aker
Remove all of uchar. |
1155 |
field= new Field_new_decimal((unsigned char*) 0, max_length, null_ptr, 0, |
1
by brian
clean slate |
1156 |
Field::NONE, name, decimals, 0, |
1157 |
unsigned_flag); |
|
1158 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1159 |
case DRIZZLE_TYPE_LONG: |
481
by Brian Aker
Remove all of uchar. |
1160 |
field= new Field_long((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE, |
1
by brian
clean slate |
1161 |
name, 0, unsigned_flag); |
1162 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1163 |
case DRIZZLE_TYPE_LONGLONG: |
481
by Brian Aker
Remove all of uchar. |
1164 |
field= new Field_int64_t((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE, |
1
by brian
clean slate |
1165 |
name, 0, unsigned_flag); |
1166 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1167 |
case DRIZZLE_TYPE_DOUBLE: |
481
by Brian Aker
Remove all of uchar. |
1168 |
field= new Field_double((unsigned char*) 0, max_length, null_ptr, 0, Field::NONE, |
1
by brian
clean slate |
1169 |
name, decimals, 0, unsigned_flag); |
1170 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1171 |
case DRIZZLE_TYPE_NULL: |
481
by Brian Aker
Remove all of uchar. |
1172 |
field= new Field_null((unsigned char*) 0, max_length, Field::NONE, |
1
by brian
clean slate |
1173 |
name, &my_charset_bin); |
1174 |
break; |
|
575.5.1
by David Axmark
Changed NEWDATE to DATE. One failing test but I think its somewhere else in the code |
1175 |
case DRIZZLE_TYPE_DATE: |
1176 |
field= new Field_date(maybe_null, name, &my_charset_bin); |
|
1
by brian
clean slate |
1177 |
break; |
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1178 |
case DRIZZLE_TYPE_TIMESTAMP: |
1
by brian
clean slate |
1179 |
field= new Field_timestamp(maybe_null, name, &my_charset_bin); |
1180 |
break; |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1181 |
case DRIZZLE_TYPE_DATETIME: |
1
by brian
clean slate |
1182 |
field= new Field_datetime(maybe_null, name, &my_charset_bin); |
1183 |
break; |
|
1184 |
default: |
|
1185 |
/* This case should never be chosen */
|
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
1186 |
assert(0); |
1
by brian
clean slate |
1187 |
/* Fall through to make_string_field() */
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1188 |
case DRIZZLE_TYPE_ENUM: |
1189 |
case DRIZZLE_TYPE_VARCHAR: |
|
1
by brian
clean slate |
1190 |
return make_string_field(table); |
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1191 |
case DRIZZLE_TYPE_BLOB: |
1
by brian
clean slate |
1192 |
if (this->type() == Item::TYPE_HOLDER) |
1193 |
field= new Field_blob(max_length, maybe_null, name, collation.collation, |
|
1194 |
1); |
|
1195 |
else
|
|
1196 |
field= new Field_blob(max_length, maybe_null, name, collation.collation); |
|
1197 |
break; // Blob handled outside of case |
|
1198 |
}
|
|
1199 |
if (field) |
|
1200 |
field->init(table); |
|
1201 |
return field; |
|
1202 |
}
|
|
1203 |
||
1204 |
/*
|
|
1205 |
This implementation can lose str_value content, so if the
|
|
1206 |
Item uses str_value to store something, it should
|
|
1207 |
reimplement it's ::save_in_field() as Item_string, for example, does
|
|
1208 |
*/
|
|
1209 |
int Item::save_in_field(Field *field, bool no_conversions) |
|
1210 |
{
|
|
1211 |
int error; |
|
1212 |
if (result_type() == STRING_RESULT) |
|
1213 |
{
|
|
1214 |
String *result; |
|
264.2.6
by Andrey Hristov
Constify the usage of CHARSET_INFO almost to the last place in the code. |
1215 |
const CHARSET_INFO * const cs= collation.collation; |
1
by brian
clean slate |
1216 |
char buff[MAX_FIELD_WIDTH]; // Alloc buffer for small columns |
1217 |
str_value.set_quick(buff, sizeof(buff), cs); |
|
1218 |
result=val_str(&str_value); |
|
1219 |
if (null_value) |
|
1220 |
{
|
|
1221 |
str_value.set_quick(0, 0, cs); |
|
1222 |
return set_field_to_null_with_conversions(field, no_conversions); |
|
1223 |
}
|
|
1224 |
||
56
by brian
Next pass of true/false update. |
1225 |
/* NOTE: If null_value == false, "result" must be not NULL. */
|
1
by brian
clean slate |
1226 |
|
1227 |
field->set_notnull(); |
|
1228 |
error=field->store(result->ptr(),result->length(),cs); |
|
1229 |
str_value.set_quick(0, 0, cs); |
|
1230 |
}
|
|
1231 |
else if (result_type() == REAL_RESULT && |
|
1232 |
field->result_type() == STRING_RESULT) |
|
1233 |
{
|
|
1234 |
double nr= val_real(); |
|
1235 |
if (null_value) |
|
1236 |
return set_field_to_null_with_conversions(field, no_conversions); |
|
1237 |
field->set_notnull(); |
|
1238 |
error= field->store(nr); |
|
1239 |
}
|
|
1240 |
else if (result_type() == REAL_RESULT) |
|
1241 |
{
|
|
1242 |
double nr= val_real(); |
|
1243 |
if (null_value) |
|
1244 |
return set_field_to_null(field); |
|
1245 |
field->set_notnull(); |
|
1246 |
error=field->store(nr); |
|
1247 |
}
|
|
1248 |
else if (result_type() == DECIMAL_RESULT) |
|
1249 |
{
|
|
1250 |
my_decimal decimal_value; |
|
1251 |
my_decimal *value= val_decimal(&decimal_value); |
|
1252 |
if (null_value) |
|
1253 |
return set_field_to_null_with_conversions(field, no_conversions); |
|
1254 |
field->set_notnull(); |
|
1255 |
error=field->store_decimal(value); |
|
1256 |
}
|
|
1257 |
else
|
|
1258 |
{
|
|
152
by Brian Aker
longlong replacement |
1259 |
int64_t nr=val_int(); |
1
by brian
clean slate |
1260 |
if (null_value) |
1261 |
return set_field_to_null_with_conversions(field, no_conversions); |
|
1262 |
field->set_notnull(); |
|
1263 |
error=field->store(nr, unsigned_flag); |
|
1264 |
}
|
|
1265 |
return error; |
|
1266 |
}
|
|
1267 |
||
971.3.65
by Eric Day
Namespace cleanup for Protocol and Listen. |
1268 |
bool Item::send(plugin::Protocol *protocol, String *buffer) |
1
by brian
clean slate |
1269 |
{
|
1270 |
bool result= false; |
|
1271 |
enum_field_types f_type; |
|
1272 |
||
1273 |
switch ((f_type=field_type())) { |
|
1274 |
default: |
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1275 |
case DRIZZLE_TYPE_NULL: |
1276 |
case DRIZZLE_TYPE_ENUM: |
|
1277 |
case DRIZZLE_TYPE_BLOB: |
|
1278 |
case DRIZZLE_TYPE_VARCHAR: |
|
1279 |
case DRIZZLE_TYPE_NEWDECIMAL: |
|
1
by brian
clean slate |
1280 |
{
|
1281 |
String *res; |
|
1282 |
if ((res=val_str(buffer))) |
|
1054.2.9
by Monty Taylor
Removed CHARSET_INFO stuff from protocol plugin interface - it makes no sense. |
1283 |
result= protocol->store(res->ptr(),res->length()); |
1
by brian
clean slate |
1284 |
break; |
1285 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1286 |
case DRIZZLE_TYPE_LONG: |
1
by brian
clean slate |
1287 |
{
|
152
by Brian Aker
longlong replacement |
1288 |
int64_t nr; |
1
by brian
clean slate |
1289 |
nr= val_int(); |
1290 |
if (!null_value) |
|
971.3.17
by Eric Day
Cleaned up int/date related store functions. |
1291 |
result= protocol->store((int32_t)nr); |
1
by brian
clean slate |
1292 |
break; |
1293 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1294 |
case DRIZZLE_TYPE_LONGLONG: |
1
by brian
clean slate |
1295 |
{
|
152
by Brian Aker
longlong replacement |
1296 |
int64_t nr; |
1
by brian
clean slate |
1297 |
nr= val_int(); |
1298 |
if (!null_value) |
|
971.3.17
by Eric Day
Cleaned up int/date related store functions. |
1299 |
{
|
1300 |
if (unsigned_flag) |
|
1301 |
result= protocol->store((uint64_t)nr); |
|
1302 |
else
|
|
1303 |
result= protocol->store((int64_t)nr); |
|
1304 |
}
|
|
1
by brian
clean slate |
1305 |
break; |
1306 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1307 |
case DRIZZLE_TYPE_DOUBLE: |
1
by brian
clean slate |
1308 |
{
|
1309 |
double nr= val_real(); |
|
1310 |
if (!null_value) |
|
1311 |
result= protocol->store(nr, decimals, buffer); |
|
1312 |
break; |
|
1313 |
}
|
|
212.2.2
by Patrick Galbraith
Renamed FIELD_TYPE to DRIZZLE_TYPE |
1314 |
case DRIZZLE_TYPE_DATETIME: |
1315 |
case DRIZZLE_TYPE_TIMESTAMP: |
|
1
by brian
clean slate |
1316 |
{
|
236.1.24
by Monty Taylor
Renamed MYSQL_TIME to DRIZZLE_TIME. |
1317 |
DRIZZLE_TIME tm; |
1
by brian
clean slate |
1318 |
get_date(&tm, TIME_FUZZY_DATE); |
1319 |
if (!null_value) |
|
971.3.17
by Eric Day
Cleaned up int/date related store functions. |
1320 |
result= protocol->store(&tm); |
1
by brian
clean slate |
1321 |
break; |
1322 |
}
|
|
1323 |
}
|
|
1324 |
if (null_value) |
|
971.3.17
by Eric Day
Cleaned up int/date related store functions. |
1325 |
result= protocol->store(); |
1
by brian
clean slate |
1326 |
return result; |
1327 |
}
|
|
1328 |
||
1329 |
Item_result item_cmp_type(Item_result a,Item_result b) |
|
1330 |
{
|
|
1331 |
if (a == STRING_RESULT && b == STRING_RESULT) |
|
1332 |
return STRING_RESULT; |
|
1333 |
if (a == INT_RESULT && b == INT_RESULT) |
|
1334 |
return INT_RESULT; |
|
1335 |
else if (a == ROW_RESULT || b == ROW_RESULT) |
|
1336 |
return ROW_RESULT; |
|
1337 |
if ((a == INT_RESULT || a == DECIMAL_RESULT) && |
|
1338 |
(b == INT_RESULT || b == DECIMAL_RESULT)) |
|
1339 |
return DECIMAL_RESULT; |
|
1340 |
return REAL_RESULT; |
|
1341 |
}
|
|
1342 |
||
520.1.22
by Brian Aker
Second pass of thd cleanup |
1343 |
void resolve_const_item(Session *session, Item **ref, Item *comp_item) |
1
by brian
clean slate |
1344 |
{
|
1345 |
Item *item= *ref; |
|
1346 |
Item *new_item= NULL; |
|
1347 |
if (item->basic_const_item()) |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
1348 |
return; /* Can't be better */ |
1
by brian
clean slate |
1349 |
Item_result res_type=item_cmp_type(comp_item->result_type(), |
1350 |
item->result_type()); |
|
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
1351 |
char *name=item->name; /* Alloced by sql_alloc */ |
1
by brian
clean slate |
1352 |
|
1353 |
switch (res_type) { |
|
1354 |
case STRING_RESULT: |
|
1355 |
{
|
|
1356 |
char buff[MAX_FIELD_WIDTH]; |
|
1357 |
String tmp(buff,sizeof(buff),&my_charset_bin),*result; |
|
1358 |
result=item->val_str(&tmp); |
|
1359 |
if (item->null_value) |
|
1360 |
new_item= new Item_null(name); |
|
1361 |
else
|
|
1362 |
{
|
|
482
by Brian Aker
Remove uint. |
1363 |
uint32_t length= result->length(); |
1
by brian
clean slate |
1364 |
char *tmp_str= sql_strmake(result->ptr(), length); |
1365 |
new_item= new Item_string(name, tmp_str, length, result->charset()); |
|
1366 |
}
|
|
1367 |
break; |
|
1368 |
}
|
|
1369 |
case INT_RESULT: |
|
1370 |
{
|
|
152
by Brian Aker
longlong replacement |
1371 |
int64_t result=item->val_int(); |
482
by Brian Aker
Remove uint. |
1372 |
uint32_t length=item->max_length; |
1
by brian
clean slate |
1373 |
bool null_value=item->null_value; |
1374 |
new_item= (null_value ? (Item*) new Item_null(name) : |
|
1375 |
(Item*) new Item_int(name, result, length)); |
|
1376 |
break; |
|
1377 |
}
|
|
1378 |
case ROW_RESULT: |
|
1379 |
if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM) |
|
1380 |
{
|
|
1381 |
/*
|
|
1382 |
Substitute constants only in Item_rows. Don't affect other Items
|
|
1383 |
with ROW_RESULT (eg Item_singlerow_subselect).
|
|
1384 |
||
1385 |
For such Items more optimal is to detect if it is constant and replace
|
|
1386 |
it with Item_row. This would optimize queries like this:
|
|
1387 |
SELECT * FROM t1 WHERE (a,b) = (SELECT a,b FROM t2 LIMIT 1);
|
|
1388 |
*/
|
|
1389 |
Item_row *item_row= (Item_row*) item; |
|
1390 |
Item_row *comp_item_row= (Item_row*) comp_item; |
|
482
by Brian Aker
Remove uint. |
1391 |
uint32_t col; |
1
by brian
clean slate |
1392 |
new_item= 0; |
1393 |
/*
|
|
1394 |
If item and comp_item are both Item_rows and have same number of cols
|
|
1395 |
then process items in Item_row one by one.
|
|
1396 |
We can't ignore NULL values here as this item may be used with <=>, in
|
|
1397 |
which case NULL's are significant.
|
|
1398 |
*/
|
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
1399 |
assert(item->result_type() == comp_item->result_type()); |
1400 |
assert(item_row->cols() == comp_item_row->cols()); |
|
1
by brian
clean slate |
1401 |
col= item_row->cols(); |
1402 |
while (col-- > 0) |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1403 |
resolve_const_item(session, item_row->addr(col), |
1
by brian
clean slate |
1404 |
comp_item_row->element_index(col)); |
1405 |
break; |
|
1406 |
}
|
|
1407 |
/* Fallthrough */
|
|
1408 |
case REAL_RESULT: |
|
1409 |
{ // It must REAL_RESULT |
|
1410 |
double result= item->val_real(); |
|
482
by Brian Aker
Remove uint. |
1411 |
uint32_t length=item->max_length,decimals=item->decimals; |
1
by brian
clean slate |
1412 |
bool null_value=item->null_value; |
1413 |
new_item= (null_value ? (Item*) new Item_null(name) : (Item*) |
|
1414 |
new Item_float(name, result, decimals, length)); |
|
1415 |
break; |
|
1416 |
}
|
|
1417 |
case DECIMAL_RESULT: |
|
1418 |
{
|
|
1419 |
my_decimal decimal_value; |
|
1420 |
my_decimal *result= item->val_decimal(&decimal_value); |
|
482
by Brian Aker
Remove uint. |
1421 |
uint32_t length= item->max_length, decimals= item->decimals; |
1
by brian
clean slate |
1422 |
bool null_value= item->null_value; |
1423 |
new_item= (null_value ? |
|
1424 |
(Item*) new Item_null(name) : |
|
1425 |
(Item*) new Item_decimal(name, result, length, decimals)); |
|
1426 |
break; |
|
1427 |
}
|
|
1428 |
default: |
|
51.1.55
by Jay Pipes
Removed/replaced DBUG symbols and standardized TRUE/FALSE - 1st clean pass on item.h/cc |
1429 |
assert(0); |
1
by brian
clean slate |
1430 |
}
|
1431 |
if (new_item) |
|
520.1.22
by Brian Aker
Second pass of thd cleanup |
1432 |
session->change_item_tree(ref, new_item); |
1
by brian
clean slate |
1433 |
}
|
1434 |
||
1435 |
bool field_is_equal_to_item(Field *field,Item *item) |
|
1436 |
{
|
|
1437 |
||
1438 |
Item_result res_type=item_cmp_type(field->result_type(), |
|
1439 |
item->result_type()); |
|
1440 |
if (res_type == STRING_RESULT) |
|
1441 |
{
|
|
1442 |
char item_buff[MAX_FIELD_WIDTH]; |
|
1443 |
char field_buff[MAX_FIELD_WIDTH]; |
|
1444 |
String item_tmp(item_buff,sizeof(item_buff),&my_charset_bin),*item_result; |
|
1445 |
String field_tmp(field_buff,sizeof(field_buff),&my_charset_bin); |
|
1446 |
item_result=item->val_str(&item_tmp); |
|
1447 |
if (item->null_value) |
|
1448 |
return 1; // This must be true |
|
1449 |
field->val_str(&field_tmp); |
|
1450 |
return !stringcmp(&field_tmp,item_result); |
|
1451 |
}
|
|
1452 |
if (res_type == INT_RESULT) |
|
1453 |
return 1; // Both where of type int |
|
1454 |
if (res_type == DECIMAL_RESULT) |
|
1455 |
{
|
|
1456 |
my_decimal item_buf, *item_val, |
|
1457 |
field_buf, *field_val; |
|
1458 |
item_val= item->val_decimal(&item_buf); |
|
1459 |
if (item->null_value) |
|
1460 |
return 1; // This must be true |
|
1461 |
field_val= field->val_decimal(&field_buf); |
|
1462 |
return !my_decimal_cmp(item_val, field_val); |
|
1463 |
}
|
|
1464 |
double result= item->val_real(); |
|
1465 |
if (item->null_value) |
|
1466 |
return 1; |
|
1467 |
return result == field->val_real(); |
|
1468 |
}
|
|
1469 |
||
575.1.2
by Monty Taylor
Changed a bunch of __attribute__((unused)) to removing the parameter name instead. |
1470 |
void dummy_error_processor(Session *, void *) |
1
by brian
clean slate |
1471 |
{}
|
1472 |
||
1473 |
/**
|
|
575.4.7
by Monty Taylor
More header cleanup. |
1474 |
Create field for temporary table using type of given item.
|
1475 |
||
1476 |
@param session Thread handler
|
|
1477 |
@param item Item to create a field for
|
|
1478 |
@param table Temporary table
|
|
1479 |
@param copy_func If set and item is a function, store copy of
|
|
1480 |
item in this array
|
|
1481 |
@param modify_item 1 if item->result_field should point to new
|
|
1482 |
item. This is relevent for how fill_record()
|
|
1483 |
is going to work:
|
|
1484 |
If modify_item is 1 then fill_record() will
|
|
1485 |
update the record in the original table.
|
|
1486 |
If modify_item is 0 then fill_record() will
|
|
1487 |
update the temporary table
|
|
1488 |
@param convert_blob_length If >0 create a varstring(convert_blob_length)
|
|
1489 |
field instead of blob.
|
|
1490 |
||
1491 |
@retval
|
|
1492 |
0 on error
|
|
1493 |
@retval
|
|
1494 |
new_created field
|
|
1495 |
*/
|
|
1496 |
static Field *create_tmp_field_from_item(Session *, |
|
1497 |
Item *item, Table *table, |
|
1498 |
Item ***copy_func, bool modify_item, |
|
1499 |
uint32_t convert_blob_length) |
|
1500 |
{
|
|
1501 |
bool maybe_null= item->maybe_null; |
|
1502 |
Field *new_field; |
|
1503 |
||
1504 |
switch (item->result_type()) { |
|
1505 |
case REAL_RESULT: |
|
1506 |
new_field= new Field_double(item->max_length, maybe_null, |
|
1507 |
item->name, item->decimals, true); |
|
1508 |
break; |
|
1509 |
case INT_RESULT: |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1510 |
/*
|
575.4.7
by Monty Taylor
More header cleanup. |
1511 |
Select an integer type with the minimal fit precision.
|
1512 |
MY_INT32_NUM_DECIMAL_DIGITS is sign inclusive, don't consider the sign.
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1513 |
Values with MY_INT32_NUM_DECIMAL_DIGITS digits may or may not fit into
|
1514 |
Field_long : make them Field_int64_t.
|
|
575.4.7
by Monty Taylor
More header cleanup. |
1515 |
*/
|
1516 |
if (item->max_length >= (MY_INT32_NUM_DECIMAL_DIGITS - 1)) |
|
1517 |
new_field=new Field_int64_t(item->max_length, maybe_null, |
|
1518 |
item->name, item->unsigned_flag); |
|
1519 |
else
|
|
1520 |
new_field=new Field_long(item->max_length, maybe_null, |
|
1521 |
item->name, item->unsigned_flag); |
|
1522 |
break; |
|
1523 |
case STRING_RESULT: |
|
1524 |
assert(item->collation.collation); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1525 |
|
575.4.7
by Monty Taylor
More header cleanup. |
1526 |
enum enum_field_types type; |
1527 |
/*
|
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1528 |
DATE/TIME fields have STRING_RESULT result type.
|
575.4.7
by Monty Taylor
More header cleanup. |
1529 |
To preserve type they needed to be handled separately.
|
1530 |
*/
|
|
1531 |
if ((type= item->field_type()) == DRIZZLE_TYPE_DATETIME || |
|
896.5.1
by Jay Pipes
Removes the TIME column type and related time functions. |
1532 |
type == DRIZZLE_TYPE_DATE || |
575.4.7
by Monty Taylor
More header cleanup. |
1533 |
type == DRIZZLE_TYPE_TIMESTAMP) |
1534 |
new_field= item->tmp_table_field_from_field_type(table, 1); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1535 |
/*
|
1536 |
Make sure that the blob fits into a Field_varstring which has
|
|
1537 |
2-byte lenght.
|
|
575.4.7
by Monty Taylor
More header cleanup. |
1538 |
*/
|
1539 |
else if (item->max_length/item->collation.collation->mbmaxlen > 255 && |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1540 |
convert_blob_length <= Field_varstring::MAX_SIZE && |
575.4.7
by Monty Taylor
More header cleanup. |
1541 |
convert_blob_length) |
1542 |
new_field= new Field_varstring(convert_blob_length, maybe_null, |
|
1543 |
item->name, table->s, |
|
1544 |
item->collation.collation); |
|
1545 |
else
|
|
1546 |
new_field= item->make_string_field(table); |
|
1547 |
new_field->set_derivation(item->collation.derivation); |
|
1548 |
break; |
|
1549 |
case DECIMAL_RESULT: |
|
1550 |
{
|
|
1551 |
uint8_t dec= item->decimals; |
|
1552 |
uint8_t intg= ((Item_decimal *) item)->decimal_precision() - dec; |
|
1553 |
uint32_t len= item->max_length; |
|
1554 |
||
1555 |
/*
|
|
1556 |
Trying to put too many digits overall in a DECIMAL(prec,dec)
|
|
1557 |
will always throw a warning. We must limit dec to
|
|
1558 |
DECIMAL_MAX_SCALE however to prevent an assert() later.
|
|
1559 |
*/
|
|
1560 |
||
1561 |
if (dec > 0) |
|
1562 |
{
|
|
1563 |
signed int overflow; |
|
1564 |
||
1067.4.4
by Nathan Williams
The rest of the files in the drizzled directory were purged of the cmin macro and replace with std::min (except for the definition in globals.h and 1 usage in stacktrace.cc). |
1565 |
dec= min(dec, (uint8_t)DECIMAL_MAX_SCALE); |
575.4.7
by Monty Taylor
More header cleanup. |
1566 |
|
1567 |
/*
|
|
1568 |
If the value still overflows the field with the corrected dec,
|
|
1569 |
we'll throw out decimals rather than integers. This is still
|
|
1570 |
bad and of course throws a truncation warning.
|
|
1571 |
+1: for decimal point
|
|
1572 |
*/
|
|
1573 |
||
1574 |
overflow= my_decimal_precision_to_length(intg + dec, dec, |
|
1575 |
item->unsigned_flag) - len; |
|
1576 |
||
1577 |
if (overflow > 0) |
|
1067.4.7
by Nathan Williams
The remaining files using cmax have been converted to std::max. |
1578 |
dec= max(0, dec - overflow); // too long, discard fract |
575.4.7
by Monty Taylor
More header cleanup. |
1579 |
else
|
1067.4.7
by Nathan Williams
The remaining files using cmax have been converted to std::max. |
1580 |
len-= item->decimals - dec; // corrected value fits |
575.4.7
by Monty Taylor
More header cleanup. |
1581 |
}
|
1582 |
||
1583 |
new_field= new Field_new_decimal(len, maybe_null, item->name, |
|
1584 |
dec, item->unsigned_flag); |
|
1585 |
break; |
|
1586 |
}
|
|
1587 |
case ROW_RESULT: |
|
1588 |
default: |
|
1589 |
// This case should never be choosen
|
|
1590 |
assert(0); |
|
1591 |
new_field= 0; |
|
1592 |
break; |
|
1593 |
}
|
|
1594 |
if (new_field) |
|
1595 |
new_field->init(table); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1596 |
|
575.4.7
by Monty Taylor
More header cleanup. |
1597 |
if (copy_func && item->is_result_field()) |
1598 |
*((*copy_func)++) = item; // Save for copy_funcs |
|
1599 |
if (modify_item) |
|
1600 |
item->set_result_field(new_field); |
|
1601 |
if (item->type() == Item::NULL_ITEM) |
|
1602 |
new_field->is_created_from_null_item= true; |
|
1603 |
return new_field; |
|
1604 |
}
|
|
1605 |
||
1055.2.12
by Jay Pipes
Documentation and style cleanup on Item class |
1606 |
Field *create_tmp_field(Session *session, |
1607 |
Table *table, |
|
1608 |
Item *item, |
|
1609 |
Item::Type type, |
|
1610 |
Item ***copy_func, |
|
1611 |
Field **from_field, |
|
1612 |
Field **default_field, |
|
1613 |
bool group, |
|
1614 |
bool modify_item, |
|
1615 |
bool, |
|
1616 |
bool make_copy_field, |
|
575.4.7
by Monty Taylor
More header cleanup. |
1617 |
uint32_t convert_blob_length) |
1618 |
{
|
|
1619 |
Field *result; |
|
1620 |
Item::Type orig_type= type; |
|
1621 |
Item *orig_item= 0; |
|
1622 |
||
1623 |
if (type != Item::FIELD_ITEM && |
|
1624 |
item->real_item()->type() == Item::FIELD_ITEM) |
|
1625 |
{
|
|
1626 |
orig_item= item; |
|
1627 |
item= item->real_item(); |
|
1628 |
type= Item::FIELD_ITEM; |
|
1629 |
}
|
|
1630 |
||
1631 |
switch (type) { |
|
1632 |
case Item::SUM_FUNC_ITEM: |
|
1633 |
{
|
|
1634 |
Item_sum *item_sum=(Item_sum*) item; |
|
1635 |
result= item_sum->create_tmp_field(group, table, convert_blob_length); |
|
1636 |
if (!result) |
|
1637 |
my_error(ER_OUT_OF_RESOURCES, MYF(ME_FATALERROR)); |
|
1638 |
return result; |
|
1639 |
}
|
|
1640 |
case Item::FIELD_ITEM: |
|
1641 |
case Item::DEFAULT_VALUE_ITEM: |
|
1642 |
{
|
|
1643 |
Item_field *field= (Item_field*) item; |
|
1644 |
bool orig_modify= modify_item; |
|
1645 |
if (orig_type == Item::REF_ITEM) |
|
1646 |
modify_item= 0; |
|
1647 |
/*
|
|
1648 |
If item have to be able to store NULLs but underlaid field can't do it,
|
|
1649 |
create_tmp_field_from_field() can't be used for tmp field creation.
|
|
1650 |
*/
|
|
1651 |
if (field->maybe_null && !field->field->maybe_null()) |
|
1652 |
{
|
|
1653 |
result= create_tmp_field_from_item(session, item, table, NULL, |
|
1654 |
modify_item, convert_blob_length); |
|
1655 |
*from_field= field->field; |
|
1656 |
if (result && modify_item) |
|
1657 |
field->result_field= result; |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1658 |
}
|
575.4.7
by Monty Taylor
More header cleanup. |
1659 |
else
|
1660 |
result= create_tmp_field_from_field(session, (*from_field= field->field), |
|
1661 |
orig_item ? orig_item->name : |
|
1662 |
item->name, |
|
1663 |
table, |
|
1664 |
modify_item ? field : |
|
1665 |
NULL, |
|
1666 |
convert_blob_length); |
|
1667 |
if (orig_type == Item::REF_ITEM && orig_modify) |
|
1668 |
((Item_ref*)orig_item)->set_result_field(result); |
|
1669 |
if (field->field->eq_def(result)) |
|
1670 |
*default_field= field->field; |
|
1671 |
return result; |
|
1672 |
}
|
|
1673 |
/* Fall through */
|
|
1674 |
case Item::FUNC_ITEM: |
|
1675 |
/* Fall through */
|
|
1676 |
case Item::COND_ITEM: |
|
1677 |
case Item::FIELD_AVG_ITEM: |
|
1678 |
case Item::FIELD_STD_ITEM: |
|
1679 |
case Item::SUBSELECT_ITEM: |
|
1680 |
/* The following can only happen with 'CREATE TABLE ... SELECT' */
|
|
1681 |
case Item::PROC_ITEM: |
|
1682 |
case Item::INT_ITEM: |
|
1683 |
case Item::REAL_ITEM: |
|
1684 |
case Item::DECIMAL_ITEM: |
|
1685 |
case Item::STRING_ITEM: |
|
1686 |
case Item::REF_ITEM: |
|
1687 |
case Item::NULL_ITEM: |
|
1688 |
case Item::VARBIN_ITEM: |
|
1689 |
if (make_copy_field) |
|
1690 |
{
|
|
1691 |
assert(((Item_result_field*)item)->result_field); |
|
1692 |
*from_field= ((Item_result_field*)item)->result_field; |
|
1693 |
}
|
|
1694 |
return create_tmp_field_from_item(session, item, table, |
|
1695 |
(make_copy_field ? 0 : copy_func), |
|
1696 |
modify_item, convert_blob_length); |
|
660.1.3
by Eric Herman
removed trailing whitespace with simple script: |
1697 |
case Item::TYPE_HOLDER: |
575.4.7
by Monty Taylor
More header cleanup. |
1698 |
result= ((Item_type_holder *)item)->make_field_by_type(table); |
1699 |
result->set_derivation(item->collation.derivation); |
|
1700 |
return result; |
|
1701 |
default: // Dosen't have to be stored |
|
681
by Brian Aker
Style cleanup |
1702 |
return NULL; |
575.4.7
by Monty Taylor
More header cleanup. |
1703 |
}
|
1704 |
}
|
|
1705 |
||
1
by brian
clean slate |
1706 |
#ifdef HAVE_EXPLICIT_TEMPLATE_INSTANTIATION
|
1707 |
template class List<Item>; |
|
1708 |
template class List_iterator<Item>; |
|
1709 |
template class List_iterator_fast<Item>; |
|
1710 |
template class List_iterator_fast<Item_field>; |
|
1711 |
template class List<List_item>; |
|
1712 |
#endif
|