18 #include "my_global.h"
24 #include "sp_rcontext.h"
27 #include "sql_trigger.h"
43 #include "sql_optimizer.h"
48 const String my_null_string(
"NULL", 4, default_charset_info);
54 void Hybrid_type_traits::fix_length_and_dec(
Item *item,
Item *arg)
const
56 item->decimals= NOT_FIXED_DEC;
57 item->max_length= item->float_length(arg->decimals);
64 return &real_traits_instance;
71 double2my_decimal(E_DEC_FATAL_ERROR, val->real, val->dec_buf);
79 to->set_real(val->real, decimals, &my_charset_bin);
88 return &decimal_traits_instance;
93 Hybrid_type_traits_decimal::fix_length_and_dec(
Item *item,
Item *arg)
const
95 item->decimals= arg->decimals;
96 item->max_length= min<uint32>(arg->max_length + DECIMAL_LONGLONG_DIGITS,
101 void Hybrid_type_traits_decimal::set_zero(
Hybrid_type *val)
const
103 my_decimal_set_zero(&val->dec_buf[0]);
104 val->used_dec_buf_no= 0;
110 my_decimal_add(E_DEC_FATAL_ERROR,
111 &val->dec_buf[val->used_dec_buf_no ^ 1],
112 &val->dec_buf[val->used_dec_buf_no],
113 f->val_decimal(&val->dec_buf[2]));
114 val->used_dec_buf_no^= 1;
124 int2my_decimal(E_DEC_FATAL_ERROR, u, TRUE, &val->dec_buf[2]);
126 my_decimal_div(E_DEC_FATAL_ERROR,
127 &val->dec_buf[val->used_dec_buf_no ^ 1],
128 &val->dec_buf[val->used_dec_buf_no],
129 &val->dec_buf[2], 4);
130 val->used_dec_buf_no^= 1;
135 Hybrid_type_traits_decimal::val_int(
Hybrid_type *val,
bool unsigned_flag)
const
138 my_decimal2int(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
139 unsigned_flag, &result);
145 Hybrid_type_traits_decimal::val_real(
Hybrid_type *val)
const
147 my_decimal2double(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
155 uint8 decimals)
const
157 my_decimal_round(E_DEC_FATAL_ERROR, &val->dec_buf[val->used_dec_buf_no],
158 decimals, FALSE, &val->dec_buf[2]);
159 my_decimal2string(E_DEC_FATAL_ERROR, &val->dec_buf[2], 0, 0, 0, to);
168 return &integer_traits_instance;
172 Hybrid_type_traits_integer::fix_length_and_dec(
Item *item,
Item *arg)
const
175 item->max_length= MY_INT64_NUM_DECIMAL_DIGITS;
176 item->unsigned_flag= 0;
189 item_user_lock_init();
201 switch(result_type()) {
203 return val_int() != 0;
209 return !my_decimal_is_zero(val);
214 return val_real() != 0.0;
233 if (!(collation.collation->state & MY_CS_NONASCII))
236 DBUG_ASSERT(str != &str_value);
239 String *res= val_str(&str_value);
243 if ((null_value= str->copy(res->ptr(), res->length(),
244 collation.collation, &my_charset_latin1,
254 double nr= val_real();
257 str->set_real(nr,decimals, &my_charset_bin);
264 longlong nr= val_int();
267 str->set_int(nr, unsigned_flag, &my_charset_bin);
274 my_decimal dec_buf, *dec= val_decimal(&dec_buf);
277 my_decimal_round(E_DEC_FATAL_ERROR, dec, decimals, FALSE, &dec_buf);
278 my_decimal2string(E_DEC_FATAL_ERROR, &dec_buf, 0, 0, 0, str);
285 DBUG_ASSERT(fixed == 1);
287 if (get_date(<ime, TIME_FUZZY_DATE) ||
288 (null_value= str->alloc(MAX_DATE_STRING_REP_LENGTH)))
297 DBUG_ASSERT(fixed == 1);
299 if (get_date(<ime, TIME_FUZZY_DATE) ||
300 (null_value= str->alloc(MAX_DATE_STRING_REP_LENGTH)))
309 DBUG_ASSERT(fixed == 1);
311 if (get_time(<ime) || (null_value= str->alloc(MAX_DATE_STRING_REP_LENGTH)))
320 double nr= val_real();
323 double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
324 return (decimal_value);
330 longlong nr= val_int();
333 int2my_decimal(E_DEC_FATAL_ERROR, nr, unsigned_flag, decimal_value);
334 return decimal_value;
342 if (!(res= val_str(&str_value)))
345 if (str2my_decimal(E_DEC_FATAL_ERROR & ~E_DEC_BAD_NUM,
346 res->ptr(), res->length(), res->charset(),
347 decimal_value) & E_DEC_BAD_NUM)
350 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
351 ER_TRUNCATED_WRONG_VALUE,
352 ER(ER_TRUNCATED_WRONG_VALUE),
"DECIMAL",
355 return decimal_value;
361 DBUG_ASSERT(fixed == 1);
363 if (get_date(<ime, TIME_FUZZY_DATE))
365 my_decimal_set_zero(decimal_value);
369 return date2my_decimal(<ime, decimal_value);
375 DBUG_ASSERT(fixed == 1);
377 if (get_time(<ime))
379 my_decimal_set_zero(decimal_value);
383 return date2my_decimal(<ime, decimal_value);
390 if ((null_value= get_time(<ime)))
392 return TIME_to_longlong_time_packed(<ime);
399 longlong
flags= (TIME_FUZZY_DATE | MODE_INVALID_DATES |
400 (current_thd->variables.sql_mode &
401 (MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE)));
402 if ((null_value= get_date(<ime, flags)))
404 return TIME_to_longlong_datetime_packed(<ime);
412 longlong diff= my_time_fraction_remainder(MY_PACKED_TIME_GET_FRAC_PART(nr),
414 longlong abs_diff= diff > 0 ? diff : - diff;
415 if (abs_diff * 2 >= (
int) log_10_int[DATETIME_MAX_DECIMALS - dec])
420 case MYSQL_TYPE_TIME:
423 TIME_from_longlong_time_packed(<ime, nr);
424 return my_time_round(<ime, dec) ?
425 0 : TIME_to_longlong_time_packed(<ime);
427 case MYSQL_TYPE_TIMESTAMP:
428 case MYSQL_TYPE_DATETIME:
432 TIME_from_longlong_datetime_packed(<ime, nr);
433 return my_datetime_round(<ime, dec, &warnings) ?
434 0 : TIME_to_longlong_datetime_packed(<ime);
448 double Item::val_real_from_decimal()
452 my_decimal value_buff, *dec_val= val_decimal(&value_buff);
455 my_decimal2double(E_DEC_FATAL_ERROR, dec_val, &result);
460 longlong Item::val_int_from_decimal()
464 my_decimal value, *dec_val= val_decimal(&value);
467 my_decimal2int(E_DEC_FATAL_ERROR, dec_val, unsigned_flag, &result);
472 longlong Item::val_int_from_time()
474 DBUG_ASSERT(fixed == 1);
476 return get_time(<ime) ?
477 0LL : (ltime.neg ? -1 : 1) * TIME_to_ulonglong_time_round(<ime);
481 longlong Item::val_int_from_date()
483 DBUG_ASSERT(fixed == 1);
485 return get_date(<ime, TIME_FUZZY_DATE) ?
486 0LL : (longlong) TIME_to_ulonglong_date(<ime);
490 longlong Item::val_int_from_datetime()
492 DBUG_ASSERT(fixed == 1);
494 return get_date(<ime, TIME_FUZZY_DATE) ?
495 0LL: (longlong) TIME_to_ulonglong_datetime_round(<ime);
499 type_conversion_status Item::save_time_in_field(
Field *field)
502 if (get_time(<ime))
504 field->set_notnull();
509 type_conversion_status Item::save_date_in_field(
Field *field)
512 if (get_date(<ime, TIME_FUZZY_DATE))
514 field->set_notnull();
540 type_conversion_status
541 Item::save_str_value_in_field(
Field *field,
String *result)
544 return set_field_to_null(field);
546 field->set_notnull();
547 return field->store(result->ptr(), result->length(), collation.collation);
552 is_expensive_cache(-1), rsize(0),
554 collation(&my_charset_bin, DERIVATION_COERCIBLE), with_subselect(false),
555 with_stored_program(false), tables_locked_cache(false)
557 maybe_null=null_value=with_sum_func=unsigned_flag=0;
558 decimals= 0; max_length= 0;
559 cmp_context= (Item_result)-1;
562 THD *thd= current_thd;
563 next= thd->free_list;
564 thd->free_list=
this;
570 if (thd->lex->current_select)
572 enum_parsing_place place=
573 thd->lex->current_select->parsing_place;
574 if (place == SELECT_LIST ||
576 thd->lex->current_select->select_n_having_items++;
587 Item::Item(THD *thd,
Item *item):
588 is_expensive_cache(-1),
590 str_value(item->str_value),
591 item_name(item->item_name),
592 orig_name(item->orig_name),
593 max_length(item->max_length),
594 marker(item->marker),
595 decimals(item->decimals),
596 maybe_null(item->maybe_null),
597 null_value(item->null_value),
598 unsigned_flag(item->unsigned_flag),
599 with_sum_func(item->with_sum_func),
601 collation(item->collation),
602 cmp_context(item->cmp_context),
603 with_subselect(item->has_subquery()),
604 with_stored_program(item->with_stored_program),
605 tables_locked_cache(item->tables_locked_cache)
607 next= thd->free_list;
608 thd->free_list=
this;
612 uint Item::decimal_precision()
const
614 Item_result restype= result_type();
616 if ((restype == DECIMAL_RESULT) || (restype == INT_RESULT))
619 my_decimal_length_to_precision(max_char_length(), decimals,
623 switch (field_type())
625 case MYSQL_TYPE_TIME:
626 return decimals + TIME_INT_DIGITS;
627 case MYSQL_TYPE_DATETIME:
628 case MYSQL_TYPE_TIMESTAMP:
629 return decimals + DATETIME_INT_DIGITS;
630 case MYSQL_TYPE_DATE:
631 return decimals + DATE_INT_DIGITS;
641 if (const_item() && result_type() == STRING_RESULT && !is_temporal())
648 if ((tmp= val_str(&buf)) &&
649 str_to_time(tmp, <ime, TIME_NO_NSEC_ROUNDING, &status) == 0)
650 return MY_MIN(status.fractional_digits, DATETIME_MAX_DECIMALS);
652 return MY_MIN(decimals, DATETIME_MAX_DECIMALS);
658 if (const_item() && result_type() == STRING_RESULT && !is_temporal())
665 if ((tmp= val_str(&buf)) &&
666 !str_to_datetime(tmp, <ime, TIME_NO_NSEC_ROUNDING | TIME_FUZZY_DATE,
668 return MY_MIN(status.fractional_digits, DATETIME_MAX_DECIMALS);
670 return MY_MIN(decimals, DATETIME_MAX_DECIMALS);
674 void Item::print_item_w_name(
String *str, enum_query_type query_type)
676 print(str, query_type);
680 THD *thd= current_thd;
681 str->append(STRING_WITH_LEN(
" AS "));
682 append_identifier(thd, str, item_name);
699 enum_query_type query_type,
704 DBUG_ASSERT(item_name.
is_set());
706 append_identifier(current_thd, str, item_name);
709 print(str,query_type);
715 DBUG_ENTER(
"Item::cleanup");
720 item_name= orig_name;
751 if (!orig_name.
is_set() && new_name != item_name.
ptr())
752 orig_name= item_name;
753 item_name.
set(new_name);
788 DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
790 return (this->*transformer)(arg);
795 const char *db_name_arg,
const char *table_name_arg,
796 const char *field_name_arg)
797 :orig_db_name(db_name_arg), orig_table_name(table_name_arg),
798 orig_field_name(field_name_arg), context(context_arg),
799 db_name(db_name_arg),
table_name(table_name_arg),
800 field_name(field_name_arg),
801 alias_name_used(FALSE), cached_field_index(NO_CACHED_FIELD_INDEX),
802 cached_table(0), depended_from(0)
804 item_name.
set(field_name_arg);
814 orig_db_name(item->orig_db_name),
815 orig_table_name(item->orig_table_name),
816 orig_field_name(item->orig_field_name),
817 context(item->context),
818 db_name(item->db_name),
820 field_name(item->field_name),
821 alias_name_used(item->alias_name_used),
822 cached_field_index(item->cached_field_index),
823 cached_table(item->cached_table),
824 depended_from(item->depended_from)
827 void Item_ident::cleanup()
829 DBUG_ENTER(
"Item_ident::cleanup");
830 #ifdef CANT_BE_USED_AS_MEMORY_IS_FREED
831 db_name ? db_name :
"(null)",
832 orig_db_name ? orig_db_name :
"(null)",
833 table_name ? table_name :
"(null)",
834 orig_table_name ? orig_table_name :
"(null)",
835 field_name ? field_name :
"(null)",
836 orig_field_name ? orig_field_name :
"(null)"));
839 db_name= orig_db_name;
840 table_name= orig_table_name;
841 field_name= orig_field_name;
845 bool Item_ident::remove_dependence_processor(uchar * arg)
847 DBUG_ENTER(
"Item_ident::remove_dependence_processor");
848 if (depended_from == (st_select_lex *) arg)
850 context= &((st_select_lex *) arg)->context;
875 DBUG_ENTER(
"Item_field::collect_item_field_processor");
876 DBUG_PRINT(
"info", (
"%s", field->field_name ? field->field_name :
"noname"));
880 while ((curr_item= item_list_it++))
882 if (curr_item->
eq(
this, 1))
885 item_list->push_back(
this);
890 bool Item_field::add_field_to_set_processor(uchar *arg)
892 DBUG_ENTER(
"Item_field::add_field_to_set_processor");
893 DBUG_PRINT(
"info", (
"%s", field->field_name ? field->field_name :
"noname"));
895 if (field->table == table)
896 bitmap_set_bit(&table->tmp_set, field->field_index);
904 bitmap_clear_bit(bitmap, field->field_index);
930 for (cur_part= first_non_group_part; cur_part != last_part; cur_part++)
932 if (field->eq(cur_part->field))
947 bool Item_field::register_field_in_read_map(uchar *arg)
950 if (field->table == table || !table)
951 bitmap_set_bit(field->table->read_set, field->field_index);
956 bool Item::check_cols(uint c)
960 my_error(ER_OPERAND_COLUMNS, MYF(0), c);
975 set(str ?
"" : NULL, 0);
984 while (length && !my_isgraph(cs, *str))
990 if (!my_charset_same(cs, system_charset_info))
993 char *tmp= sql_strmake_with_convert(str, length, cs, MAX_ALIAS_NAME,
994 system_charset_info, &res_length);
995 set(tmp, tmp ? res_length : 0);
999 size_t len= min<size_t>(
length, MAX_ALIAS_NAME);
1000 char *tmp= sql_strmake(str, len);
1001 set(tmp, tmp ? len : 0);
1008 bool is_autogenerated_arg)
1010 m_is_autogenerated= is_autogenerated_arg;
1011 copy(str_arg, length_arg, cs_arg);
1014 ErrConvString tmp(str_arg, static_cast<uint>(length_arg), cs_arg);
1016 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
1017 ER_NAME_BECOMES_EMPTY, ER(ER_NAME_BECOMES_EMPTY),
1020 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
1021 ER_REMOVED_SPACES, ER(ER_REMOVED_SPACES),
1042 return type() == item->type() && item_name.eq_safe(item->item_name);
1049 return conv->safe ? conv : NULL;
1071 if (!(tocs->state & MY_CS_NONASCII))
1076 char buf[64], buf2[64];
1077 String tmp(buf,
sizeof(buf), &my_charset_bin);
1078 String cstr(buf2,
sizeof(buf2), &my_charset_bin);
1079 String *ostr= val_str(&tmp);
1081 cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
1082 if (conv_errors || !(conv=
new Item_string(cstr.ptr(), cstr.length(),
1084 collation.derivation)))
1094 if (!(ptr= current_thd->strmake(cstr.ptr(), cstr.length())))
1096 conv->str_value.set(ptr, cstr.length(), cstr.charset());
1098 conv->str_value.mark_as_const();
1099 conv->fix_char_length(max_char_length());
1108 String *s, tmp(buf,
sizeof(buf), &my_charset_bin);
1113 conv->str_value.copy();
1114 conv->str_value.mark_as_const();
1139 String tmp, cstr, *ostr= val_str(&tmp);
1140 cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
1141 conv_errors= lossless && conv_errors;
1142 if (conv_errors || !(conv=
new Item_string(cstr.ptr(), cstr.length(),
1144 collation.derivation)))
1154 if (!(ptr= current_thd->strmake(cstr.ptr(), cstr.length())))
1156 conv->str_value.set(ptr, cstr.length(), cstr.charset());
1158 conv->str_value.mark_as_const();
1168 String *ostr= val_str(&cnvstr);
1169 cnvitem->str_value.copy(ostr->ptr(), ostr->length(),
1170 ostr->charset(), tocs, &cnv_errors);
1173 cnvitem->str_value.mark_as_const();
1174 cnvitem->max_length= cnvitem->str_value.numchars() * tocs->mbmaxlen;
1177 return Item::safe_charset_converter(tocs);
1181 Item *Item_static_string_func::
1186 String tmp, cstr, *ostr= val_str(&tmp);
1187 cstr.copy(ostr->ptr(), ostr->length(), ostr->charset(), tocs, &conv_errors);
1190 cstr.ptr(), cstr.length(),
1192 collation.derivation)))
1202 conv->str_value.copy();
1204 conv->str_value.mark_as_const();
1211 if (type() == item->type() && item->basic_const_item())
1214 return !stringcmp(&str_value, &item->str_value);
1215 return (collation.collation == item->collation.collation &&
1216 !sortcmp(&str_value, &item->str_value, collation.collation));
1224 char buff[MAX_DATE_STRING_REP_LENGTH];
1225 String tmp(buff,
sizeof(buff), &my_charset_bin), *res;
1226 if (!(res= val_str(&tmp)))
1228 set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
1231 return str_to_datetime_with_warn(res, ltime, flags);
1237 double value= val_real();
1240 set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
1243 return my_double_to_datetime_with_warn(value, ltime, flags);
1253 set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
1256 return my_decimal_to_datetime_with_warn(decimal, ltime, flags);
1262 longlong value= val_int();
1265 set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME);
1268 return my_longlong_to_datetime_with_warn(value, ltime, flags);
1277 DBUG_ASSERT(null_value);
1280 time_to_datetime(current_thd, &tm, ltime);
1287 switch (result_type())
1291 case DECIMAL_RESULT:
1299 return (null_value=
true);
1310 DBUG_ASSERT(!is_temporal());
1311 switch (result_type())
1317 case DECIMAL_RESULT:
1324 return (null_value=
true);
1330 char buff[MAX_DATE_STRING_REP_LENGTH];
1331 String tmp(buff,
sizeof(buff), &my_charset_bin), *res;
1332 if (!(res= val_str(&tmp)))
1334 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
1337 return str_to_time_with_warn(res, ltime);
1343 double value= val_real();
1346 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
1349 return my_double_to_time_with_warn(value, ltime);
1358 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
1361 return my_decimal_to_time_with_warn(decimal, ltime);
1367 DBUG_ASSERT(!is_temporal());
1368 longlong value= val_int();
1371 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
1374 return my_longlong_to_time_with_warn(value, ltime);
1380 DBUG_ASSERT(fixed == 1);
1381 if (get_date(ltime, TIME_FUZZY_DATE))
1383 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
1390 DBUG_ASSERT(fixed == 1);
1391 if (get_date(ltime, TIME_FUZZY_DATE))
1393 datetime_to_time(ltime);
1400 DBUG_ASSERT(!is_temporal());
1401 switch (result_type())
1405 case DECIMAL_RESULT:
1413 return (null_value=
true);
1427 DBUG_ASSERT(!is_temporal());
1428 switch (result_type())
1434 case DECIMAL_RESULT:
1441 return (null_value=
true);
1454 if (get_date(<ime, TIME_FUZZY_DATE))
1460 if (datetime_to_timeval(current_thd, <ime, tm, warnings))
1464 tm->tv_sec= tm->tv_usec= 0;
1471 return current_thd->variables.collation_connection;
1483 type_conversion_status
1484 Item::save_in_field_no_warnings(
Field *field,
bool no_conversions)
1486 DBUG_ENTER(
"Item::save_in_field_no_warnings");
1487 TABLE *table= field->table;
1488 THD *thd= table->in_use;
1489 enum_check_fields tmp= thd->count_cuted_fields;
1490 my_bitmap_map *old_map= dbug_tmp_use_all_columns(table, table->write_set);
1491 sql_mode_t sql_mode= thd->variables.sql_mode;
1492 thd->variables.sql_mode&= ~(MODE_NO_ZERO_IN_DATE | MODE_NO_ZERO_DATE);
1493 thd->count_cuted_fields= CHECK_FIELD_IGNORE;
1495 const type_conversion_status res=
save_in_field(field, no_conversions);
1497 thd->count_cuted_fields= tmp;
1498 dbug_tmp_restore_column_map(table->write_set, old_map);
1499 thd->variables.sql_mode= sql_mode;
1508 enum_field_types type= field_type();
1509 return (type == MYSQL_TYPE_BLOB || type == MYSQL_TYPE_GEOMETRY ||
1510 max_length > CONVERT_IF_BIGGER_TO_BLOB);
1518 Item_sp_variable::Item_sp_variable(
const Name_string sp_var_name)
1519 :m_thd(0), m_name(sp_var_name)
1527 bool Item_sp_variable::fix_fields(THD *thd,
Item **)
1534 DBUG_ASSERT(it->fixed);
1536 max_length= it->max_length;
1537 decimals= it->decimals;
1538 unsigned_flag= it->unsigned_flag;
1540 collation.set(it->collation);
1546 double Item_sp_variable::val_real()
1549 Item *it= this_item();
1550 double ret= it->val_real();
1551 null_value= it->null_value;
1556 longlong Item_sp_variable::val_int()
1559 Item *it= this_item();
1560 longlong ret= it->val_int();
1561 null_value= it->null_value;
1569 Item *it= this_item();
1570 String *res= it->val_str(sp);
1572 null_value= it->null_value;
1593 if (res != &str_value)
1594 str_value.set(res->ptr(), res->length(), res->charset());
1596 res->mark_as_const();
1605 Item *it= this_item();
1606 my_decimal *val= it->val_decimal(decimal_value);
1607 null_value= it->null_value;
1612 bool Item_sp_variable::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
1615 Item *it= this_item();
1616 return (null_value= it->get_date(ltime, fuzzydate));
1620 bool Item_sp_variable::get_time(
MYSQL_TIME *ltime)
1623 Item *it= this_item();
1624 return (null_value= it->get_time(ltime));
1628 bool Item_sp_variable::is_null()
1630 return this_item()->is_null();
1638 Item_splocal::Item_splocal(
const Name_string sp_var_name,
1640 enum_field_types sp_var_type,
1641 uint pos_in_q, uint len_in_q)
1643 m_var_idx(sp_var_idx),
1644 limit_clause_param(FALSE),
1645 pos_in_query(pos_in_q), len_in_query(len_in_q)
1649 sp_var_type= real_type_to_type(sp_var_type);
1650 m_type= sp_map_item_type(sp_var_type);
1651 m_field_type= sp_var_type;
1652 m_result_type= sp_map_result_type(sp_var_type);
1657 Item_splocal::this_item()
1659 DBUG_ASSERT(m_sp == m_thd->sp_runtime_ctx->sp);
1661 return m_thd->sp_runtime_ctx->get_item(m_var_idx);
1665 Item_splocal::this_item()
const
1667 DBUG_ASSERT(m_sp == m_thd->sp_runtime_ctx->sp);
1669 return m_thd->sp_runtime_ctx->get_item(m_var_idx);
1674 Item_splocal::this_item_addr(THD *thd,
Item **)
1676 DBUG_ASSERT(m_sp == thd->sp_runtime_ctx->sp);
1678 return thd->sp_runtime_ctx->get_item_addr(m_var_idx);
1682 void Item_splocal::print(
String *str, enum_query_type)
1684 str->reserve(m_name.
length() + 8);
1685 str->append(m_name);
1687 str->qs_append(m_var_idx);
1693 return ctx->set_variable(thd, get_var_idx(), it);
1701 Item_case_expr::Item_case_expr(uint case_expr_id)
1703 m_case_expr_id(case_expr_id)
1709 Item_case_expr::this_item()
1711 DBUG_ASSERT(m_sp == m_thd->sp_runtime_ctx->sp);
1713 return m_thd->sp_runtime_ctx->get_case_expr(m_case_expr_id);
1719 Item_case_expr::this_item()
const
1721 DBUG_ASSERT(m_sp == m_thd->sp_runtime_ctx->sp);
1723 return m_thd->sp_runtime_ctx->get_case_expr(m_case_expr_id);
1728 Item_case_expr::this_item_addr(THD *thd,
Item **)
1730 DBUG_ASSERT(m_sp == thd->sp_runtime_ctx->sp);
1732 return thd->sp_runtime_ctx->get_case_expr_addr(m_case_expr_id);
1738 if (str->reserve(MAX_INT_WIDTH +
sizeof(
"case_expr@")))
1740 (void) str->append(STRING_WITH_LEN(
"case_expr@"));
1741 str->qs_append(m_case_expr_id);
1749 double Item_name_const::val_real()
1752 double ret= value_item->val_real();
1753 null_value= value_item->null_value;
1758 longlong Item_name_const::val_int()
1761 longlong ret= value_item->val_int();
1762 null_value= value_item->null_value;
1770 String *ret= value_item->val_str(sp);
1771 null_value= value_item->null_value;
1779 my_decimal *val= value_item->val_decimal(decimal_value);
1780 null_value= value_item->null_value;
1785 bool Item_name_const::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
1788 return (null_value= value_item->get_date(ltime, fuzzydate));
1792 bool Item_name_const::get_time(
MYSQL_TIME *ltime)
1795 return (null_value= value_item->get_time(ltime));
1799 bool Item_name_const::is_null()
1801 return value_item->is_null();
1805 Item_name_const::Item_name_const(
Item *name_arg,
Item *val):
1806 value_item(val), name_item(name_arg)
1814 if (!(valid_args= name_item->basic_const_item() &&
1815 (value_item->basic_const_item() ||
1816 ((value_item->type() == FUNC_ITEM) &&
1817 ((((
Item_func *) value_item)->functype() ==
1818 Item_func::COLLATE_FUNC) ||
1819 ((((
Item_func *) value_item)->functype() ==
1820 Item_func::NEG_FUNC) &&
1821 (((
Item_func *) value_item)->key_item()->basic_const_item())))))))
1822 my_error(ER_WRONG_ARGUMENTS, MYF(0),
"NAME_CONST");
1823 Item::maybe_null= TRUE;
1827 Item::Type Item_name_const::type()
const
1848 Item::Type value_type= value_item->type();
1849 if (value_type == FUNC_ITEM)
1855 DBUG_ASSERT(((
Item_func *) value_item)->functype() ==
1856 Item_func::NEG_FUNC ||
1857 ((
Item_func *) value_item)->functype() ==
1858 Item_func::COLLATE_FUNC);
1859 return ((
Item_func *) value_item)->key_item()->type();
1865 bool Item_name_const::fix_fields(THD *thd,
Item **ref)
1869 String s(buf,
sizeof(buf), &my_charset_bin);
1872 if (value_item->fix_fields(thd, &value_item) ||
1873 name_item->fix_fields(thd, &name_item) ||
1874 !value_item->const_item() ||
1875 !name_item->const_item() ||
1876 !(tmp= name_item->val_str(&s)))
1878 my_error(ER_RESERVED_SYNTAX, MYF(0),
"NAME_CONST");
1883 item_name.
copy(tmp->ptr(), (uint) tmp->length(), system_charset_info);
1885 collation.set(value_item->collation.collation, DERIVATION_IMPLICIT,
1886 value_item->collation.repertoire);
1887 max_length= value_item->max_length;
1888 decimals= value_item->decimals;
1896 str->append(STRING_WITH_LEN(
"NAME_CONST("));
1897 name_item->
print(str, query_type);
1899 value_item->print(str, query_type);
1913 const char *table_name_arg,
const char *field_name_arg)
1914 :
Item_ref(context_arg, item, table_name_arg, field_name_arg) {}
1919 (*ref)->print(str, query_type);
1923 virtual Ref_Type ref_type() {
return AGGREGATE_REF; }
1948 bool skip_registered)
1951 if (type() == SUM_FUNC_ITEM && skip_registered &&
1954 if ((type() != SUM_FUNC_ITEM && with_sum_func) ||
1955 (type() == FUNC_ITEM &&
1956 (((
Item_func *)
this)->functype() == Item_func::ISNOTNULLTEST_FUNC ||
1957 ((
Item_func *)
this)->functype() == Item_func::TRIG_COND_FUNC)))
1960 split_sum_func(thd, ref_pointer_array, fields);
1962 else if ((type() == SUM_FUNC_ITEM || (used_tables() & ~PARAM_TABLE_BIT)) &&
1963 type() != SUBSELECT_ITEM &&
1964 (type() != REF_ITEM ||
1965 ((
Item_ref*)
this)->ref_type() == Item_ref::VIEW_REF))
1978 uint el= fields.elements;
1979 Item *real_itm= real_item();
1981 ref_pointer_array[el]= real_itm;
1983 &ref_pointer_array[el], 0,
1986 if (type() == SUM_FUNC_ITEM)
1987 item_ref->depended_from= ((
Item_sum *)
this)->depended_from();
1988 fields.push_front(real_itm);
1989 thd->change_item_tree(ref, item_ref);
1998 if (left->collation->state & MY_CS_UNICODE &&
1999 (left->derivation < right->derivation ||
2000 (left->derivation == right->derivation &&
2001 (!(right->collation->state & MY_CS_UNICODE) ||
2003 (left->collation->state & MY_CS_UNICODE_SUPPLEMENT &&
2004 !(right->collation->state & MY_CS_UNICODE_SUPPLEMENT) &&
2005 left->collation->mbmaxlen > right->collation->mbmaxlen &&
2006 left->collation->mbminlen == right->collation->mbminlen)))))
2009 if (right->repertoire == MY_REPERTOIRE_ASCII &&
2010 (left->derivation < right->derivation ||
2011 (left->derivation == right->derivation &&
2012 !(left->repertoire == MY_REPERTOIRE_ASCII))))
2056 if (!my_charset_same(collation, dt.collation))
2064 if (collation == &my_charset_bin)
2066 if (derivation <= dt.derivation)
2073 else if (dt.collation == &my_charset_bin)
2075 if (dt.derivation <= derivation)
2080 else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
2081 left_is_superset(
this, &dt))
2085 else if ((flags & MY_COLL_ALLOW_SUPERSET_CONV) &&
2086 left_is_superset(&dt,
this))
2090 else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) &&
2091 derivation < dt.derivation &&
2092 dt.derivation >= DERIVATION_SYSCONST)
2096 else if ((flags & MY_COLL_ALLOW_COERCIBLE_CONV) &&
2097 dt.derivation < derivation &&
2098 derivation >= DERIVATION_SYSCONST)
2105 set(&my_charset_bin, DERIVATION_NONE,
2106 (dt.repertoire|repertoire));
2110 else if (derivation < dt.derivation)
2114 else if (dt.derivation < derivation)
2120 if (collation == dt.collation)
2126 if (derivation == DERIVATION_EXPLICIT)
2128 set(0, DERIVATION_NONE, 0);
2131 if (collation->state & MY_CS_BINSORT)
2133 if (dt.collation->state & MY_CS_BINSORT)
2138 const CHARSET_INFO *bin= get_charset_by_csname(collation->csname,
2139 MY_CS_BINSORT,MYF(0));
2140 set(bin, DERIVATION_NONE);
2143 repertoire|= dt.repertoire;
2151 my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0),
2152 c1.collation->name,c1.derivation_name(),
2153 c2.collation->name,c2.derivation_name(),
2162 my_error(ER_CANT_AGGREGATE_3COLLATIONS,MYF(0),
2163 c1.collation->name,c1.derivation_name(),
2164 c2.collation->name,c2.derivation_name(),
2165 c3.collation->name,c3.derivation_name(),
2171 void my_coll_agg_error(
Item** args, uint count,
const char *fname,
2175 my_coll_agg_error(args[0]->collation, args[item_sep]->collation, fname);
2176 else if (count == 3)
2177 my_coll_agg_error(args[0]->collation, args[item_sep]->collation,
2178 args[2*item_sep]->collation, fname);
2180 my_error(ER_CANT_AGGREGATE_NCOLLATIONS,MYF(0),fname);
2184 bool agg_item_collations(
DTCollation &c,
const char *fname,
2185 Item **av, uint count, uint
flags,
int item_sep)
2191 c.set(av[0]->collation);
2192 for (i= 1, arg= &av[item_sep]; i < count; i++, arg++)
2194 if (c.
aggregate((*arg)->collation, flags))
2196 if (c.derivation == DERIVATION_NONE &&
2197 c.collation == &my_charset_bin)
2202 my_coll_agg_error(av, count, fname, item_sep);
2208 c.derivation != DERIVATION_EXPLICIT)
2210 my_coll_agg_error(av, count, fname, item_sep);
2214 if ((flags & MY_COLL_DISALLOW_NONE) &&
2215 c.derivation == DERIVATION_NONE)
2217 my_coll_agg_error(av, count, fname, item_sep);
2222 if (flags & MY_COLL_ALLOW_NUMERIC_CONV &&
2223 c.derivation == DERIVATION_NUMERIC)
2224 c.set(Item::default_charset(), DERIVATION_COERCIBLE, MY_REPERTOIRE_NUMERIC);
2230 bool agg_item_collations_for_comparison(
DTCollation &c,
const char *fname,
2231 Item **av, uint count, uint flags)
2233 return (agg_item_collations(c, fname, av, count,
2234 flags | MY_COLL_DISALLOW_NONE, 1));
2238 bool agg_item_set_converter(
DTCollation &coll,
const char *fname,
2239 Item **args, uint nargs, uint flags,
int item_sep)
2241 Item **arg, *safe_args[2]= {NULL, NULL};
2250 if (nargs >=2 && nargs <= 3)
2252 safe_args[0]= args[0];
2253 safe_args[1]= args[item_sep];
2256 THD *thd= current_thd;
2264 Prepared_stmt_arena_holder ps_arena_holder(
2265 thd, thd->stmt_arena->is_stmt_prepare());
2267 for (i= 0, arg= args; i < nargs; i++, arg+= item_sep)
2270 uint32 dummy_offset;
2271 if (!String::needs_conversion(1, (*arg)->collation.collation,
2288 if ((*arg)->collation.derivation == DERIVATION_NUMERIC &&
2289 (*arg)->collation.repertoire == MY_REPERTOIRE_ASCII &&
2290 !((*arg)->collation.collation->state & MY_CS_NONASCII) &&
2291 !(coll.collation->state & MY_CS_NONASCII))
2294 if (!(conv= (*arg)->safe_charset_converter(coll.collation)) &&
2295 ((*arg)->collation.repertoire == MY_REPERTOIRE_ASCII))
2300 if (nargs >=2 && nargs <= 3)
2303 args[0]= safe_args[0];
2304 args[item_sep]= safe_args[1];
2306 my_coll_agg_error(args, nargs, fname, item_sep);
2310 if ((*arg)->type() == Item::FIELD_ITEM)
2322 if (thd->stmt_arena->is_stmt_prepare())
2325 thd->change_item_tree(arg, conv);
2327 if (conv->fix_fields(thd, arg))
2368 bool agg_item_charsets(
DTCollation &coll,
const char *fname,
2369 Item **args, uint nargs, uint flags,
int item_sep)
2371 if (agg_item_collations(coll, fname, args, nargs, flags, item_sep))
2374 return agg_item_set_converter(coll, fname, args, nargs, flags, item_sep);
2378 void Item_ident_for_show::make_field(
Send_field *tmp_field)
2380 tmp_field->table_name= tmp_field->org_table_name= table_name;
2381 tmp_field->db_name= db_name;
2382 tmp_field->col_name= tmp_field->org_col_name= field->field_name;
2383 tmp_field->charsetnr= field->charset()->number;
2384 tmp_field->length=field->field_length;
2385 tmp_field->type=field->type();
2386 tmp_field->flags= field->table->maybe_null ?
2387 (field->flags & ~NOT_NULL_FLAG) : field->flags;
2388 tmp_field->decimals= field->decimals();
2393 Item_field::Item_field(
Field *f)
2395 item_equal(0), no_const_subst(0),
2396 have_privileges(0), any_privileges(0)
2403 orig_table_name= orig_field_name=
"";
2417 item_equal(0), no_const_subst(0),
2418 have_privileges(0), any_privileges(0)
2439 orig_db_name= thd->strdup(db_name);
2441 orig_table_name= thd->strdup(table_name);
2443 orig_field_name= thd->strdup(field_name);
2449 item_name.
set(orig_field_name);
2456 const char *db_arg,
const char *table_name_arg,
2457 const char *field_name_arg)
2458 :
Item_ident(context_arg, db_arg,table_name_arg,field_name_arg),
2459 field(0), result_field(0), item_equal(0), no_const_subst(0),
2460 have_privileges(0), any_privileges(0)
2462 SELECT_LEX *select= current_thd->lex->current_select;
2463 collation.set(DERIVATION_IMPLICIT);
2464 if (select && select->parsing_place != IN_HAVING)
2465 select->select_n_where_fields++;
2475 result_field(item->result_field),
2476 item_equal(item->item_equal),
2477 no_const_subst(item->no_const_subst),
2478 have_privileges(item->have_privileges),
2479 any_privileges(item->any_privileges)
2481 collation.set(DERIVATION_IMPLICIT);
2503 inline static uint32
2504 adjust_max_effective_column_length(
Field *field_par, uint32 max_length)
2506 uint32 new_max_length= field_par->max_display_length();
2507 uint32 sign_length= (field_par->flags & UNSIGNED_FLAG) ? 0 : 1;
2509 switch (field_par->type())
2511 case MYSQL_TYPE_INT24:
2519 case MYSQL_TYPE_LONG:
2520 case MYSQL_TYPE_TINY:
2521 case MYSQL_TYPE_SHORT:
2524 new_max_length= new_max_length - 1 + sign_length;
2528 case MYSQL_TYPE_LONGLONG:
2535 return new_max_length > max_length ? new_max_length : max_length;
2539 void Item_field::set_field(
Field *field_par)
2541 field=result_field=field_par;
2542 maybe_null=field->maybe_null();
2543 decimals= field->decimals();
2544 table_name= *field_par->table_name;
2545 field_name= field_par->field_name;
2546 db_name= field_par->table->s->db.str;
2547 alias_name_used= field_par->table->alias_name_used;
2548 unsigned_flag=
test(field_par->flags & UNSIGNED_FLAG);
2549 collation.set(field_par->charset(), field_par->derivation(),
2550 field_par->repertoire());
2551 fix_char_length(field_par->char_length());
2553 max_length= adjust_max_effective_column_length(field_par, max_length);
2556 if (field->table->s->tmp_table == SYSTEM_TMP_TABLE)
2571 item_name.
set(f->field_name);
2574 const char *Item_ident::full_name()
const
2577 if (!table_name || !field_name)
2578 return field_name ? field_name : item_name.
is_set() ? item_name.
ptr() :
"tmp_field";
2579 if (db_name && db_name[0])
2581 tmp=(
char*) sql_alloc((uint) strlen(db_name)+(uint) strlen(table_name)+
2582 (uint) strlen(field_name)+3);
2583 strxmov(tmp,db_name,
".",table_name,
".",field_name,NullS);
2589 tmp= (
char*) sql_alloc((uint) strlen(table_name) +
2590 (uint) strlen(field_name) + 2);
2591 strxmov(tmp, table_name,
".", field_name, NullS);
2594 tmp= (
char*) field_name;
2601 THD *thd= current_thd;
2602 char d_name_buff[MAX_ALIAS_NAME], t_name_buff[MAX_ALIAS_NAME];
2603 const char *d_name= db_name, *t_name= table_name;
2604 if (lower_case_table_names== 1 ||
2605 (lower_case_table_names == 2 && !alias_name_used))
2607 if (table_name && table_name[0])
2609 strmov(t_name_buff, table_name);
2610 my_casedn_str(files_charset_info, t_name_buff);
2611 t_name= t_name_buff;
2613 if (db_name && db_name[0])
2615 strmov(d_name_buff, db_name);
2616 my_casedn_str(files_charset_info, d_name_buff);
2617 d_name= d_name_buff;
2621 if (!table_name || !field_name || !field_name[0])
2623 const char *nm= (field_name && field_name[0]) ?
2624 field_name : item_name.
is_set() ? item_name.
ptr() :
"tmp_field";
2625 append_identifier(thd, str, nm, (uint) strlen(nm));
2628 if (db_name && db_name[0] && !alias_name_used)
2630 if (!(cached_table && cached_table->belong_to_view &&
2631 cached_table->belong_to_view->compact_view_format))
2633 const size_t d_name_len= strlen(d_name);
2634 if (!((query_type & QT_NO_DEFAULT_DB) &&
2635 db_is_default_db(d_name, d_name_len, thd)))
2637 append_identifier(thd, str, d_name, (uint)d_name_len);
2641 append_identifier(thd, str, t_name, (uint)strlen(t_name));
2643 append_identifier(thd, str, field_name, (uint)strlen(field_name));
2649 append_identifier(thd, str, t_name, (uint) strlen(t_name));
2651 append_identifier(thd, str, field_name, (uint) strlen(field_name));
2654 append_identifier(thd, str, field_name, (uint) strlen(field_name));
2661 DBUG_ASSERT(fixed == 1);
2662 if ((null_value=field->is_null()))
2664 str->set_charset(str_value.charset());
2665 return field->val_str(str,&str_value);
2669 double Item_field::val_real()
2671 DBUG_ASSERT(fixed == 1);
2672 if ((null_value=field->is_null()))
2674 return field->val_real();
2678 longlong Item_field::val_int()
2680 DBUG_ASSERT(fixed == 1);
2681 if ((null_value=field->is_null()))
2683 return field->val_int();
2689 DBUG_ASSERT(fixed == 1);
2690 if ((null_value= field->is_null()))
2698 DBUG_ASSERT(fixed == 1);
2699 if ((null_value= field->is_null()))
2707 if ((null_value= field->is_null()))
2709 return field->val_decimal(decimal_value);
2715 if ((null_value=result_field->is_null()))
2717 str->set_charset(str_value.charset());
2718 return result_field->val_str(str,&str_value);
2721 bool Item_field::get_date(
MYSQL_TIME *ltime,uint fuzzydate)
2723 if ((null_value=field->is_null()) || field->get_date(ltime,fuzzydate))
2725 memset(ltime, 0,
sizeof(*ltime));
2731 bool Item_field::get_date_result(
MYSQL_TIME *ltime,uint fuzzydate)
2733 if ((null_value=result_field->is_null()) ||
2734 result_field->get_date(ltime,fuzzydate))
2736 memset(ltime, 0,
sizeof(*ltime));
2744 if ((null_value= field->is_null()) || field->get_time(ltime))
2746 memset(ltime, 0,
sizeof(*ltime));
2754 if ((null_value= field->is_null()))
2757 tm->tv_sec= tm->tv_usec= 0;
2761 double Item_field::val_result()
2763 if ((null_value=result_field->is_null()))
2765 return result_field->val_real();
2768 longlong Item_field::val_int_result()
2770 if ((null_value=result_field->is_null()))
2772 return result_field->val_int();
2777 if ((null_value= result_field->is_null()))
2784 if ((null_value= result_field->is_null()))
2791 if ((null_value= result_field->is_null()))
2793 return result_field->val_decimal(decimal_value);
2797 bool Item_field::val_bool_result()
2799 if ((null_value= result_field->is_null()))
2801 switch (result_field->result_type()) {
2803 return result_field->val_int() != 0;
2804 case DECIMAL_RESULT:
2807 my_decimal *val= result_field->val_decimal(&decimal_value);
2809 return !my_decimal_is_zero(val);
2814 return result_field->val_real() != 0.0;
2823 bool Item_field::is_null_result()
2825 return (null_value=result_field->is_null());
2831 Item *real_item= ((
Item *) item)->real_item();
2832 if (real_item->type() != FIELD_ITEM)
2836 if (item_field->field && field)
2837 return item_field->field == field;
2848 return (item_field->item_name.eq_safe(field_name) &&
2849 (!item_field->table_name || !table_name ||
2850 (!my_strcasecmp(table_alias_charset, item_field->table_name,
2852 (!item_field->db_name || !db_name ||
2853 (item_field->db_name && !strcmp(item_field->db_name,
2858 table_map Item_field::used_tables()
const
2860 if (field->table->const_table)
2862 return (depended_from ? OUTER_REF_TABLE_BIT : field->table->map);
2868 if (field->table->const_table)
2870 return field->table->map;
2874 st_select_lex *removed_select)
2885 if (context == NULL)
2887 DBUG_ASSERT(type() == FIELD_ITEM);
2891 if (context->select_lex == removed_select ||
2892 context->select_lex == parent_select)
2894 if (parent_select == depended_from)
2895 depended_from= NULL;
2897 ctx->outer_context= NULL;
2898 ctx->table_list= NULL;
2899 ctx->select_lex= parent_select;
2900 ctx->first_name_resolution_table= context->first_name_resolution_table;
2901 ctx->last_name_resolution_table= context->last_name_resolution_table;
2902 ctx->error_processor= context->error_processor;
2903 ctx->error_processor_data= context->error_processor_data;
2905 ctx->security_ctx= context->security_ctx;
2915 if (removed_select == depended_from)
2916 depended_from= parent_select;
2925 st_select_lex *child_select= context->select_lex;
2927 while (child_select->outer_select() != depended_from)
2932 Item_subselect *subq_predicate= child_select->master_unit()->item;
2934 subq_predicate->used_tables_cache|= OUTER_REF_TABLE_BIT;
2935 child_select= child_select->outer_select();
2943 Item_subselect *subq_predicate= child_select->master_unit()->item;
2946 subq_predicate->const_item_cache&= this->const_item();
2951 Item *Item_field::get_tmp_table_item(THD *thd)
2955 new_item->field= new_item->result_field;
2959 longlong Item_field::val_int_endpoint(
bool left_endp,
bool *incl_endp)
2961 longlong res= val_int();
2962 return null_value? LONGLONG_MIN : res;
2970 Item_int::Item_int(
const char *str_arg, uint length)
2972 char *end_ptr= (
char*) str_arg + length;
2974 value= my_strtoll10(str_arg, &end_ptr, &error);
2975 max_length= (uint) (end_ptr - str_arg);
2976 item_name.
copy(str_arg, max_length);
2983 int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_value);
2984 return decimal_value;
2990 DBUG_ASSERT(fixed == 1);
2991 str->set_int(value, unsigned_flag, collation.collation);
2998 str_value.set_int(value, unsigned_flag, &my_charset_bin);
2999 str->append(str_value);
3006 DBUG_ASSERT(fixed == 1);
3007 str->set((ulonglong) value, collation.collation);
3015 str_value.set((ulonglong) value, default_charset());
3016 str->append(str_value);
3020 Item_decimal::Item_decimal(
const char *str_arg, uint length,
3023 str2my_decimal(E_DEC_FATAL_ERROR, str_arg, length, charset, &decimal_value);
3024 item_name.
set(str_arg);
3025 decimals= (uint8) decimal_value.frac;
3027 max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
3033 Item_decimal::Item_decimal(longlong val,
bool unsig)
3035 int2my_decimal(E_DEC_FATAL_ERROR, val, unsig, &decimal_value);
3036 decimals= (uint8) decimal_value.frac;
3038 max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
3045 Item_decimal::Item_decimal(
double val,
int precision,
int scale)
3047 double2my_decimal(E_DEC_FATAL_ERROR, val, &decimal_value);
3048 decimals= (uint8) decimal_value.frac;
3050 max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
3057 Item_decimal::Item_decimal(
const Name_string &name_arg,
3059 uint decimal_par, uint length)
3061 my_decimal2decimal(val_arg, &decimal_value);
3062 item_name= name_arg;
3063 decimals= (uint8) decimal_par;
3069 Item_decimal::Item_decimal(
my_decimal *value_par)
3071 my_decimal2decimal(value_par, &decimal_value);
3072 decimals= (uint8) decimal_value.frac;
3074 max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
3081 Item_decimal::Item_decimal(
const uchar *bin,
int precision,
int scale)
3083 binary2my_decimal(E_DEC_FATAL_ERROR, bin,
3084 &decimal_value, precision, scale);
3085 decimals= (uint8) decimal_value.frac;
3087 max_length= my_decimal_precision_to_length_no_truncation(precision, decimals,
3092 longlong Item_decimal::val_int()
3095 my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &result);
3099 double Item_decimal::val_real()
3102 my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
3108 result->set_charset(&my_charset_numeric);
3109 my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, result);
3115 my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, &str_value);
3116 str->append(str_value);
3122 if (type() == item->type() && item->basic_const_item())
3138 void Item_decimal::set_decimal_value(
my_decimal *value_par)
3140 my_decimal2decimal(value_par, &decimal_value);
3141 decimals= (uint8) decimal_value.frac;
3142 unsigned_flag= !decimal_value.sign();
3143 max_length= my_decimal_precision_to_length_no_truncation(decimal_value.intg +
3153 DBUG_ASSERT(fixed == 1);
3154 str->set_real(value,decimals,&my_charset_bin);
3162 DBUG_ASSERT(fixed == 1);
3163 double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_value);
3164 return (decimal_value);
3179 const bool print_introducer=
3181 if (print_introducer)
3184 str->append(collation.collation->csname);
3189 if (query_type & QT_TO_SYSTEM_CHARSET)
3191 if (print_introducer)
3205 ErrConvString tmp(str_value.ptr(), str_value.length(), &my_charset_bin);
3206 str->append(tmp.ptr());
3210 if (my_charset_same(str_value.charset(), system_charset_info))
3211 str_value.print(str);
3214 THD *thd= current_thd;
3217 thd->convert_string(&utf8_lex_str,
3218 system_charset_info,
3221 str_value.charset());
3223 String utf8_str(utf8_lex_str.str,
3224 utf8_lex_str.length,
3225 system_charset_info);
3227 utf8_str.print(str);
3234 str_value.print(str);
3243 const char *cptr,
char *end)
3250 tmp= my_strntod(cs, (
char*) cptr, end - cptr, &end, &error);
3251 if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end)))
3254 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
3255 ER_TRUNCATED_WRONG_VALUE,
3256 ER(ER_TRUNCATED_WRONG_VALUE),
"DOUBLE",
3263 double Item_string::val_real()
3265 DBUG_ASSERT(fixed == 1);
3266 return double_from_string_with_check (str_value.charset(), str_value.ptr(),
3267 (
char *) str_value.ptr() + str_value.length());
3272 longlong_from_string_with_check (
const CHARSET_INFO *cs,
3273 const char *cptr,
char *end)
3279 tmp= (*(cs->cset->strtoll10))(cs, cptr, &end, &err);
3284 if (!current_thd->no_errors &&
3286 (end != org_end && !check_if_only_end_space(cs, end, org_end))))
3289 push_warning_printf(current_thd, Sql_condition::WARN_LEVEL_WARN,
3290 ER_TRUNCATED_WRONG_VALUE,
3291 ER(ER_TRUNCATED_WRONG_VALUE),
"INTEGER",
3304 DBUG_ASSERT(fixed == 1);
3305 return longlong_from_string_with_check(str_value.charset(), str_value.ptr(),
3306 (
char *) str_value.ptr()+ str_value.length());
3312 return val_decimal_from_string(decimal_value);
3317 {
return item->type() == type(); }
3320 double Item_null::val_real()
3323 DBUG_ASSERT(fixed == 1);
3327 longlong Item_null::val_int()
3330 DBUG_ASSERT(fixed == 1);
3338 DBUG_ASSERT(fixed == 1);
3351 collation.set(tocs);
3364 uchar **pos __attribute__((unused)),
3365 ulong len __attribute__((unused)))
3371 Item_param::Item_param(uint pos_in_query_arg) :
3373 item_result_type(STRING_RESULT),
3375 item_type(PARAM_ITEM),
3376 param_type(MYSQL_TYPE_VARCHAR),
3377 pos_in_query(pos_in_query_arg),
3378 set_param_func(default_set_param_func),
3379 limit_clause_param(FALSE),
3380 m_out_param_info(NULL)
3389 cnvitem=
new Item_string(
"", 0, &my_charset_bin, DERIVATION_COERCIBLE);
3390 cnvstr.set(cnvbuf,
sizeof(cnvbuf), &my_charset_bin);
3394 void Item_param::set_null()
3396 DBUG_ENTER(
"Item_param::set_null");
3407 item_type= Item::NULL_ITEM;
3411 void Item_param::set_int(longlong i, uint32 max_length_arg)
3413 DBUG_ENTER(
"Item_param::set_int");
3414 value.integer= (longlong) i;
3416 max_length= max_length_arg;
3422 void Item_param::set_double(
double d)
3424 DBUG_ENTER(
"Item_param::set_double");
3427 max_length= DBL_DIG + 8;
3428 decimals= NOT_FIXED_DEC;
3449 DBUG_ENTER(
"Item_param::set_decimal");
3451 end= (
char*) str+length;
3452 str2my_decimal(E_DEC_FATAL_ERROR, str, &decimal_value, &end);
3453 state= DECIMAL_VALUE;
3454 decimals= decimal_value.frac;
3456 my_decimal_precision_to_length_no_truncation(decimal_value.precision(),
3457 decimals, unsigned_flag);
3464 state= DECIMAL_VALUE;
3466 my_decimal2decimal(dv, &decimal_value);
3468 decimals= (uint8) decimal_value.frac;
3469 unsigned_flag= !decimal_value.sign();
3470 max_length= my_decimal_precision_to_length(decimal_value.intg + decimals,
3471 decimals, unsigned_flag);
3488 uint32 max_length_arg)
3490 DBUG_ENTER(
"Item_param::set_time");
3493 value.time.time_type= time_type;
3495 if (check_datetime_range(&value.time))
3499 DATETIME_MAX_DECIMALS)),
3501 set_zero_time(&value.time, MYSQL_TIMESTAMP_ERROR);
3506 max_length= max_length_arg;
3512 bool Item_param::set_str(
const char *str, ulong length)
3514 DBUG_ENTER(
"Item_param::set_str");
3520 if (str_value.copy(str, length, &my_charset_bin, &my_charset_bin,
3523 state= STRING_VALUE;
3532 bool Item_param::set_longdata(
const char *str, ulong length)
3534 DBUG_ENTER(
"Item_param::set_longdata");
3545 if (str_value.length() + length > current_thd->variables.max_allowed_packet)
3547 my_message(ER_UNKNOWN_ERROR,
3548 "Parameter of prepared statement which is set through "
3549 "mysql_send_long_data() is longer than "
3550 "'max_allowed_packet' bytes",
3555 if (str_value.append(str, length, &my_charset_bin))
3557 state= LONG_DATA_VALUE;
3578 DBUG_ENTER(
"Item_param::set_from_user_var");
3579 if (entry && entry->ptr())
3581 item_result_type= entry->type();
3582 unsigned_flag= entry->unsigned_flag;
3586 set_int(entry->val_int(&unused), MY_INT64_NUM_DECIMAL_DIGITS);
3587 item_type= Item::INT_ITEM;
3588 DBUG_RETURN(!unsigned_flag && value.integer < 0 ? 1 : 0);
3590 switch (item_result_type) {
3592 set_double(*(
double*) entry->ptr());
3593 item_type= Item::REAL_ITEM;
3596 set_int(*(longlong*) entry->ptr(), MY_INT64_NUM_DECIMAL_DIGITS);
3597 item_type= Item::INT_ITEM;
3601 const CHARSET_INFO *fromcs= entry->collation.collation;
3602 const CHARSET_INFO *tocs= thd->variables.collation_connection;
3603 uint32 dummy_offset;
3605 value.cs_info.character_set_of_placeholder= fromcs;
3606 value.cs_info.character_set_client= thd->variables.character_set_client;
3612 value.cs_info.final_character_set_of_str_value=
3613 String::needs_conversion(0, fromcs, tocs, &dummy_offset) ?
3619 item_type= Item::STRING_ITEM;
3621 if (set_str((
const char *) entry->ptr(), entry->length()))
3625 case DECIMAL_RESULT:
3628 my_decimal2decimal(ent_value, &decimal_value);
3629 state= DECIMAL_VALUE;
3630 decimals= ent_value->frac;
3632 my_decimal_precision_to_length_no_truncation(ent_value->precision(),
3633 decimals, unsigned_flag);
3634 item_type= Item::DECIMAL_ITEM;
3658 DBUG_ENTER(
"Item_param::reset");
3660 if (str_value.alloced_length() > MAX_CHAR_WIDTH)
3663 str_value.length(0);
3664 str_value_ptr.length(0);
3669 str_value.set_charset(&my_charset_bin);
3670 collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
3687 type_conversion_status
3688 Item_param::save_in_field(
Field *field,
bool no_conversions)
3690 field->set_notnull();
3694 return field->store(value.integer, unsigned_flag);
3696 return field->store(value.real);
3698 return field->store_decimal(&decimal_value);
3703 case LONG_DATA_VALUE:
3704 return field->store(str_value.ptr(), str_value.length(),
3705 str_value.charset());
3712 return TYPE_ERR_BAD_VALUE;
3718 if (state == TIME_VALUE)
3732 bool Item_param::get_date(
MYSQL_TIME *res, uint fuzzydate)
3734 if (state == TIME_VALUE)
3744 double Item_param::val_real()
3750 return (
double) value.integer;
3754 my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &result);
3758 case LONG_DATA_VALUE:
3762 return my_strntod(str_value.charset(), (
char*) str_value.ptr(),
3763 str_value.length(), &end_not_used, &dummy_err);
3770 return TIME_to_double(&value.time);
3780 longlong Item_param::val_int()
3784 return (longlong) rint(value.real);
3786 return value.integer;
3790 my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &i);
3794 case LONG_DATA_VALUE:
3797 return my_strntoll(str_value.charset(), str_value.ptr(),
3798 str_value.length(), 10, (
char**) 0, &dummy_err);
3801 return (longlong) TIME_to_ulonglong_round(&value.time);
3815 return &decimal_value;
3817 double2my_decimal(E_DEC_FATAL_ERROR, value.real, dec);
3820 int2my_decimal(E_DEC_FATAL_ERROR, value.integer, unsigned_flag, dec);
3823 case LONG_DATA_VALUE:
3824 string2my_decimal(E_DEC_FATAL_ERROR, &str_value, dec);
3827 return date2my_decimal(&value.time, dec);
3841 case LONG_DATA_VALUE:
3842 return &str_value_ptr;
3844 str->set_real(value.real, NOT_FIXED_DEC, &my_charset_bin);
3847 str->set(value.integer, &my_charset_bin);
3850 if (my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value,
3856 if (str->reserve(MAX_DATE_STRING_REP_LENGTH))
3858 str->length((uint) my_TIME_to_str(&value.time, (
char *) str->ptr(),
3859 MY_MIN(decimals, DATETIME_MAX_DECIMALS)));
3860 str->set_charset(&my_charset_bin);
3886 str->set_int(value.integer, unsigned_flag, &my_charset_bin);
3889 str->set_real(value.real, NOT_FIXED_DEC, &my_charset_bin);
3892 if (my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value,
3894 return &my_null_string;
3904 if (str->reserve(MAX_DATE_STRING_REP_LENGTH+3))
3908 buf= str->c_ptr_quick();
3911 ptr+= (uint) my_TIME_to_str(&value.time, ptr,
3912 MY_MIN(decimals, DATETIME_MAX_DECIMALS));
3914 str->length((uint32) (ptr - buf));
3918 case LONG_DATA_VALUE:
3926 return &my_null_string;
3942 if (state == STRING_VALUE || state == LONG_DATA_VALUE)
3950 if (value.cs_info.final_character_set_of_str_value !=
3951 value.cs_info.character_set_of_placeholder)
3953 rc= thd->convert_string(&str_value,
3954 value.cs_info.character_set_of_placeholder,
3955 value.cs_info.final_character_set_of_str_value);
3958 str_value.set_charset(value.cs_info.final_character_set_of_str_value);
3961 max_length= str_value.numchars() * str_value.charset()->mbmaxlen;
3964 decimals= NOT_FIXED_DEC;
3969 str_value_ptr.set(str_value.ptr(), str_value.length(),
3970 str_value.charset());
3972 collation.set(str_value.charset(), DERIVATION_COERCIBLE);
3978 bool Item_param::basic_const_item()
const
3980 if (state == NO_VALUE || state == TIME_VALUE)
3987 Item_param::clone_item()
3994 return (unsigned_flag ?
3995 new Item_uint(item_name, value.integer, max_length) :
3996 new Item_int(item_name, value.integer, max_length));
3998 return new Item_float(item_name, value.real, decimals, max_length);
4000 case LONG_DATA_VALUE:
4001 return new Item_string(item_name, str_value.c_ptr_quick(), str_value.length(),
4002 str_value.charset());
4014 Item_param::eq(
const Item *arg,
bool binary_cmp)
const
4017 if (!basic_const_item() || !arg->basic_const_item() || arg->type() != type())
4029 return value.integer == item->val_int() &&
4030 unsigned_flag == item->unsigned_flag;
4032 return value.real == item->val_real();
4034 case LONG_DATA_VALUE:
4036 return !stringcmp(&str_value, &item->str_value);
4037 return !sortcmp(&str_value, &item->str_value, collation.collation);
4046 void Item_param::print(
String *str, enum_query_type query_type)
4048 if (state == NO_VALUE)
4054 char buffer[STRING_BUFFER_USUAL_SIZE];
4055 String tmp(buffer,
sizeof(buffer), &my_charset_bin);
4087 unsigned_flag= src->unsigned_flag;
4088 param_type= src->param_type;
4089 set_param_func= src->set_param_func;
4090 item_type= src->item_type;
4091 item_result_type= src->item_result_type;
4093 collation.set(src->collation);
4094 maybe_null= src->maybe_null;
4095 null_value= src->null_value;
4096 max_length= src->max_length;
4097 decimals= src->decimals;
4101 decimal_value.
swap(src->decimal_value);
4102 str_value.swap(src->str_value);
4103 str_value_ptr.swap(src->str_value_ptr);
4133 switch (arg->result_type()) {
4136 char str_buffer[STRING_BUFFER_USUAL_SIZE];
4137 String sv_buffer(str_buffer,
sizeof(str_buffer), &my_charset_bin);
4138 String *sv= arg->val_str(&sv_buffer);
4143 set_str(sv->c_ptr_safe(), sv->length());
4144 str_value_ptr.set(str_value.ptr(),
4146 str_value.charset());
4147 collation.set(str_value.charset(), DERIVATION_COERCIBLE);
4149 item_type= Item::STRING_ITEM;
4154 set_double(arg->val_real());
4155 item_type= Item::REAL_ITEM;
4159 set_int(arg->val_int(), arg->max_length);
4160 item_type= Item::INT_ITEM;
4163 case DECIMAL_RESULT:
4172 item_type= Item::DECIMAL_ITEM;
4182 item_type= Item::NULL_ITEM;
4186 item_result_type= arg->result_type();
4201 Item_param::set_out_param_info(
Send_field *info)
4203 m_out_param_info= info;
4204 param_type= m_out_param_info->type;
4221 return m_out_param_info;
4237 if (!m_out_param_info)
4245 field->db_name= m_out_param_info->db_name;
4246 field->table_name= m_out_param_info->table_name;
4247 field->org_table_name= m_out_param_info->org_table_name;
4248 field->col_name= m_out_param_info->col_name;
4249 field->org_col_name= m_out_param_info->org_col_name;
4251 field->length= m_out_param_info->length;
4252 field->charsetnr= m_out_param_info->charsetnr;
4253 field->flags= m_out_param_info->flags;
4254 field->decimals= m_out_param_info->decimals;
4255 field->type= m_out_param_info->type;
4263 switch (item->result_type())
4270 return item->unsigned_flag ?
4272 case DECIMAL_RESULT:
4285 double Item_copy_string::val_real()
4289 return (null_value ? 0.0 :
4290 my_strntod(str_value.charset(), (
char*) str_value.ptr(),
4291 str_value.length(), &end_not_used, &err_not_used));
4294 longlong Item_copy_string::val_int()
4297 return null_value ? LL(0) : my_strntoll(str_value.charset(),str_value.ptr(),
4298 str_value.length(),10, (char**) 0,
4303 type_conversion_status
4306 return save_str_value_in_field(field, &str_value);
4312 String *res=item->val_str(&str_value);
4313 if (res && res != &str_value)
4314 str_value.copy(*res);
4315 null_value=item->null_value;
4333 string2my_decimal(E_DEC_FATAL_ERROR, &str_value, decimal_value);
4334 return (decimal_value);
4338 bool Item_copy_string::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
4343 bool Item_copy_string::get_time(
MYSQL_TIME *ltime)
4354 cached_value= item->val_int();
4355 null_value=item->null_value;
4358 static type_conversion_status
4359 save_int_value_in_field (
Field *field, longlong nr,
4360 bool null_value,
bool unsigned_flag);
4362 type_conversion_status
4365 return save_int_value_in_field(field, cached_value,
4366 null_value, unsigned_flag);
4375 str->set(cached_value, &my_charset_bin);
4385 int2my_decimal(E_DEC_FATAL_ERROR, cached_value, unsigned_flag, decimal_value);
4386 return decimal_value;
4399 str->set((ulonglong) cached_value, &my_charset_bin);
4414 double nr= val_real();
4415 str->set_real(nr,decimals, &my_charset_bin);
4427 double nr= val_real();
4428 double2my_decimal(E_DEC_FATAL_ERROR, nr, decimal_value);
4429 return decimal_value;
4434 type_conversion_status
4439 return set_field_to_null(field);
4441 field->set_notnull();
4442 return field->store(cached_value);
4450 type_conversion_status
4455 return set_field_to_null(field);
4456 field->set_notnull();
4457 return field->store_decimal(&cached_value);
4465 result->set_charset(&my_charset_bin);
4466 my_decimal2string(E_DEC_FATAL_ERROR, &cached_value, 0, 0, 0, result);
4471 double Item_copy_decimal::val_real()
4478 my_decimal2double(E_DEC_FATAL_ERROR, &cached_value, &result);
4484 longlong Item_copy_decimal::val_int()
4491 my_decimal2int(E_DEC_FATAL_ERROR, &cached_value, unsigned_flag, &result);
4499 my_decimal *nr= item->val_decimal(&cached_value);
4500 if (nr && nr != &cached_value)
4501 my_decimal2decimal (nr, &cached_value);
4502 null_value= item->null_value;
4511 bool Item::fix_fields(THD *thd,
Item **ref)
4515 DBUG_ASSERT(fixed == 0 || basic_const_item());
4520 double Item_ref_null_helper::val_real()
4522 DBUG_ASSERT(fixed == 1);
4523 double tmp= (*ref)->val_result();
4524 owner->was_null|= null_value= (*ref)->null_value;
4529 longlong Item_ref_null_helper::val_int()
4531 DBUG_ASSERT(fixed == 1);
4532 longlong tmp= (*ref)->val_int_result();
4533 owner->was_null|= null_value= (*ref)->null_value;
4540 DBUG_ASSERT(fixed == 1);
4541 DBUG_ASSERT((*ref)->is_temporal());
4542 longlong tmp= (*ref)->val_time_temporal_result();
4543 owner->was_null|= null_value= (*ref)->null_value;
4550 DBUG_ASSERT(fixed == 1);
4551 DBUG_ASSERT((*ref)->is_temporal());
4552 longlong tmp= (*ref)->val_date_temporal_result();
4553 owner->was_null|= null_value= (*ref)->null_value;
4560 DBUG_ASSERT(fixed == 1);
4561 my_decimal *val= (*ref)->val_decimal_result(decimal_value);
4562 owner->was_null|= null_value= (*ref)->null_value;
4569 DBUG_ASSERT(fixed == 1);
4570 bool val= (*ref)->val_bool_result();
4571 owner->was_null|= null_value= (*ref)->null_value;
4578 DBUG_ASSERT(fixed == 1);
4579 String* tmp= (*ref)->str_result(s);
4580 owner->was_null|= null_value= (*ref)->null_value;
4585 bool Item_ref_null_helper::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
4587 return (owner->was_null|= null_value= (*ref)->get_date(ltime, fuzzydate));
4603 static void mark_as_dependent(THD *thd, SELECT_LEX *last, SELECT_LEX *current,
4607 const char *db_name= (resolved_item->db_name ?
4608 resolved_item->db_name :
"");
4609 const char *
table_name= (resolved_item->table_name ?
4610 resolved_item->table_name :
"");
4613 mark_item->depended_from= last;
4614 current->mark_as_dependent(last);
4615 if (thd->lex->describe & DESCRIBE_EXTENDED)
4617 push_warning_printf(thd, Sql_condition::WARN_LEVEL_NOTE,
4618 ER_WARN_FIELD_RESOLVED, ER(ER_WARN_FIELD_RESOLVED),
4619 db_name, (db_name[0] ?
"." :
""),
4620 table_name, (table_name [0] ?
"." :
""),
4621 resolved_item->field_name,
4622 current->select_number, last->select_number);
4647 void mark_select_range_as_dependent(THD *thd,
4648 SELECT_LEX *last_select,
4649 SELECT_LEX *current_sel,
4659 SELECT_LEX *previous_select= current_sel;
4660 for (; previous_select->outer_select() != last_select;
4661 previous_select= previous_select->outer_select())
4664 previous_select->master_unit()->item;
4665 prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
4666 prev_subselect_item->const_item_cache= 0;
4670 previous_select->master_unit()->item;
4672 if (found_field == view_ref_found)
4674 Item::Type
type= found_item->type();
4675 prev_subselect_item->used_tables_cache|=
4676 found_item->used_tables();
4677 dependent= ((type == Item::REF_ITEM || type == Item::FIELD_ITEM) ?
4682 prev_subselect_item->used_tables_cache|=
4683 found_field->table->map;
4684 prev_subselect_item->const_item_cache= 0;
4685 mark_as_dependent(thd, last_select, current_sel, resolved_item,
4701 static bool find_item_in_item_list (
Item *item,
List<Item> *list)
4707 if (it->walk(&Item::find_item_processor,
true,
4730 static Item** find_field_in_group_list(
Item *find_item,
ORDER *group_list)
4732 const char *db_name;
4734 const char *field_name;
4735 ORDER *found_group= NULL;
4736 int found_match_degree= 0;
4738 int cur_match_degree= 0;
4739 char name_buff[NAME_LEN+1];
4741 if (find_item->type() == Item::FIELD_ITEM ||
4742 find_item->type() == Item::REF_ITEM)
4745 table_name= ((
Item_ident*) find_item)->table_name;
4746 field_name= ((
Item_ident*) find_item)->field_name;
4751 if (db_name && lower_case_table_names)
4754 strmake(name_buff, db_name,
sizeof(name_buff)-1);
4755 my_casedn_str(files_charset_info, name_buff);
4759 DBUG_ASSERT(field_name != 0);
4761 for (
ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next)
4763 if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM)
4766 cur_match_degree= 0;
4768 DBUG_ASSERT(cur_field->field_name != 0);
4770 if (!my_strcasecmp(system_charset_info,
4771 cur_field->field_name, field_name))
4776 if (cur_field->table_name && table_name)
4779 if (my_strcasecmp(table_alias_charset, cur_field->table_name, table_name))
4784 if (cur_field->db_name && db_name)
4787 if (strcmp(cur_field->db_name, db_name))
4794 if (cur_match_degree > found_match_degree)
4796 found_match_degree= cur_match_degree;
4797 found_group= cur_group;
4799 else if (found_group && (cur_match_degree == found_match_degree) &&
4800 ! (*(found_group->item))->eq(cur_field, 0))
4807 my_error(ER_NON_UNIQ_ERROR, MYF(0),
4808 find_item->full_name(), current_thd->where);
4815 return found_group->item;
4832 static bool is_fixed_or_outer_ref(
Item *ref)
4840 return (ref != NULL &&
4842 (ref->type() == Item::REF_ITEM &&
4843 static_cast<Item_ref *
>(ref)->ref_type() == Item_ref::OUTER_REF)));
4885 resolve_ref_in_select_and_group(THD *thd,
Item_ident *ref, SELECT_LEX *select)
4887 Item **group_by_ref= NULL;
4888 Item **select_ref= NULL;
4889 ORDER *group_list= select->group_list.first;
4890 bool ambiguous_fields= FALSE;
4892 enum_resolution_type resolution;
4898 if (!(select_ref= find_item_in_list(ref, *(select->get_item_list()),
4899 &counter, REPORT_EXCEPT_NOT_FOUND,
4902 if (resolution == RESOLVED_AGAINST_ALIAS)
4903 ref->alias_name_used= TRUE;
4906 if (select->having_fix_field && !ref->with_sum_func && group_list)
4908 group_by_ref= find_field_in_group_list(ref, group_list);
4911 if (group_by_ref && (select_ref != not_found_item) &&
4912 !((*group_by_ref)->eq(*select_ref, 0)))
4914 ambiguous_fields= TRUE;
4915 push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_NON_UNIQ_ERROR,
4916 ER(ER_NON_UNIQ_ERROR), ref->full_name(),
4917 current_thd->where);
4922 if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
4923 select->having_fix_field &&
4924 select_ref != not_found_item && !group_by_ref)
4930 my_error(ER_NON_GROUPING_FIELD_USED, MYF(0),
4931 ref->item_name.
ptr(),
"HAVING");
4934 if (select_ref != not_found_item || group_by_ref)
4936 if (select_ref != not_found_item && !ambiguous_fields)
4938 DBUG_ASSERT(*select_ref != 0);
4939 if (!select->ref_pointer_array[counter])
4941 my_error(ER_ILLEGAL_REFERENCE, MYF(0),
4942 ref->item_name.
ptr(),
"forward reference in item list");
4949 DBUG_ASSERT(is_fixed_or_outer_ref(*select_ref));
4951 return &select->ref_pointer_array[counter];
4954 return group_by_ref;
4959 return (
Item**) not_found_item;
5005 enum_parsing_place place= NO_MATTER;
5006 bool field_found= (*from_field != not_found_field);
5007 bool upward_lookup= FALSE;
5019 Item **ref= (
Item **) not_found_item;
5020 SELECT_LEX *current_sel= (SELECT_LEX *) thd->lex->current_select;
5022 SELECT_LEX *select= 0;
5024 if (current_sel->master_unit()->first_select()->linkage !=
5026 outer_context= context->outer_context;
5029 outer_context= outer_context->outer_context)
5031 select= outer_context->select_lex;
5033 last_checked_context->select_lex->master_unit()->item;
5034 last_checked_context= outer_context;
5035 upward_lookup= TRUE;
5037 place= prev_subselect_item->parsing_place;
5042 if (field_found && outer_context->select_lex !=
5043 cached_table->select_lex)
5050 if (field_found || (*from_field= find_field_in_tables(thd,
this,
5052 first_name_resolution_table,
5054 last_name_resolution_table,
5056 IGNORE_EXCEPT_NON_UNIQUE,
5062 if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY &&
5063 select->cur_pos_in_all_fields != SELECT_LEX::ALL_FIELDS_UNDEF_POS)
5071 if (*from_field != view_ref_found)
5073 prev_subselect_item->used_tables_cache|= (*from_field)->table->map;
5074 prev_subselect_item->const_item_cache= 0;
5075 set_field(*from_field);
5076 if (!last_checked_context->select_lex->having_fix_field &&
5077 select->group_list.elements &&
5078 (place == SELECT_LIST || place == IN_HAVING))
5093 thd->change_item_tree(reference, rf);
5094 select->inner_refs_list.push_back(rf);
5095 rf->in_sum_func= thd->lex->in_sum_func;
5102 if (thd->lex->in_sum_func &&
5103 thd->lex->in_sum_func->nest_level >= select->nest_level)
5105 Item::Type ref_type= (*reference)->type();
5106 set_if_bigger(thd->lex->in_sum_func->max_arg_level,
5107 select->nest_level);
5108 set_field(*from_field);
5110 mark_as_dependent(thd, last_checked_context->select_lex,
5111 context->select_lex,
this,
5112 ((ref_type == REF_ITEM ||
5113 ref_type == FIELD_ITEM) ?
5120 Item::Type ref_type= (*reference)->type();
5121 prev_subselect_item->used_tables_cache|=
5122 (*reference)->used_tables();
5123 prev_subselect_item->const_item_cache&=
5124 (*reference)->const_item();
5125 mark_as_dependent(thd, last_checked_context->select_lex,
5126 context->select_lex,
this,
5127 ((ref_type == REF_ITEM || ref_type == FIELD_ITEM) ?
5143 if (place != IN_WHERE && place != IN_ON &&
5144 outer_context->resolve_in_select_list)
5146 if (!(ref= resolve_ref_in_select_and_group(thd,
this, select)))
5148 if (ref != not_found_item)
5154 DBUG_ASSERT(is_fixed_or_outer_ref(*ref));
5155 prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
5156 prev_subselect_item->const_item_cache&= (*ref)->const_item();
5166 prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
5167 prev_subselect_item->const_item_cache= 0;
5170 DBUG_ASSERT(ref != 0);
5173 if (ref == not_found_item && *from_field == not_found_field)
5178 my_error(ER_BAD_FIELD_ERROR, MYF(0), full_name(), thd->where);
5183 find_field_in_tables(thd,
this,
5184 context->first_name_resolution_table,
5185 context->last_name_resolution_table,
5186 reference, REPORT_ALL_ERRORS,
5187 !any_privileges, TRUE);
5191 else if (ref != not_found_item)
5197 DBUG_ASSERT(is_fixed_or_outer_ref(*ref));
5206 rf= (place == IN_HAVING ?
5207 new Item_ref(context, ref, (
char*) table_name,
5208 (
char*) field_name, alias_name_used) :
5209 (!select->group_list.elements ?
5211 (
char*) field_name, alias_name_used) :
5213 (
char*) field_name, alias_name_used)));
5218 if (place != IN_HAVING && select->group_list.elements)
5220 outer_context->select_lex->inner_refs_list.push_back((
Item_outer_ref*)rf);
5223 thd->change_item_tree(reference, rf);
5228 DBUG_ASSERT(!rf->fixed);
5229 if (rf->
fix_fields(thd, reference) || rf->check_cols(1))
5232 mark_as_dependent(thd, last_checked_context->select_lex,
5233 context->select_lex,
this,
5239 mark_as_dependent(thd, last_checked_context->select_lex,
5240 context->select_lex,
5242 if (last_checked_context->select_lex->having_fix_field)
5246 (cached_table->db[0] ? cached_table->db : 0),
5247 (
char*) cached_table->alias, (
char*) field_name);
5250 thd->change_item_tree(reference, rf);
5255 DBUG_ASSERT(!rf->fixed);
5256 if (rf->
fix_fields(thd, reference) || rf->check_cols(1))
5267 marker= select_lex->cur_pos_in_all_fields;
5275 select_lex->non_agg_fields.push_front(
this) :
5276 select_lex->non_agg_fields.push_back(
this);
5327 DBUG_ASSERT(fixed == 0);
5329 bool outer_fixed=
false;
5338 from_field= find_field_in_tables(thd,
this,
5339 context->first_name_resolution_table,
5340 context->last_name_resolution_table,
5342 thd->lex->use_only_table_context ?
5344 IGNORE_EXCEPT_NON_UNIQUE,
5345 !any_privileges, TRUE);
5346 if (thd->is_error())
5348 if (from_field == not_found_field)
5352 if (thd->lex->current_select->is_item_list_lookup)
5355 enum_resolution_type resolution;
5356 Item** res= find_item_in_list(
this, thd->lex->current_select->item_list,
5357 &counter, REPORT_EXCEPT_NOT_FOUND,
5361 if (resolution == RESOLVED_AGAINST_ALIAS)
5362 alias_name_used= TRUE;
5363 if (res != (
Item **)not_found_item)
5365 if ((*res)->type() == Item::FIELD_ITEM)
5376 if (new_field == NULL)
5379 my_error(ER_BAD_FIELD_ERROR, MYF(0), (*res)->item_name.ptr(),
5380 current_thd->where);
5384 set_field(new_field);
5403 bool save_group_fix_field= thd->lex->current_select->group_fix_field;
5407 thd->lex->current_select->group_fix_field= 0;
5409 bool ret= rf->
fix_fields(thd, (
Item **) &rf) || rf->check_cols(1);
5410 thd->lex->current_select->group_fix_field= save_group_fix_field;
5414 if (save_group_fix_field && alias_name_used)
5415 thd->change_item_tree(reference, *rf->ref);
5417 thd->change_item_tree(reference, rf);
5427 goto mark_non_agg_field;
5429 else if (!from_field)
5440 cached_table && cached_table->select_lex && context->select_lex &&
5441 cached_table->select_lex != context->select_lex)
5448 goto mark_non_agg_field;
5463 if (from_field == view_ref_found)
5466 set_field(from_field);
5467 if (thd->lex->in_sum_func &&
5468 thd->lex->in_sum_func->nest_level ==
5469 thd->lex->current_select->nest_level)
5470 set_if_bigger(thd->lex->in_sum_func->max_arg_level,
5471 thd->lex->current_select->nest_level);
5473 else if (thd->mark_used_columns != MARK_COLUMNS_NONE)
5475 TABLE *table= field->table;
5476 MY_BITMAP *current_bitmap, *other_bitmap;
5477 if (thd->mark_used_columns == MARK_COLUMNS_READ)
5479 current_bitmap= table->read_set;
5480 other_bitmap= table->write_set;
5484 current_bitmap= table->write_set;
5485 other_bitmap= table->read_set;
5487 if (!bitmap_fast_test_and_set(current_bitmap, field->field_index))
5489 if (!bitmap_is_set(other_bitmap, field->field_index))
5492 table->used_fields++;
5494 table->covering_keys.intersect(field->part_of_key);
5499 #ifndef NO_EMBEDDED_ACCESS_CHECKS
5505 if (!(have_privileges= (get_column_grant(thd, &field->table->grant,
5506 db, tab, field_name) &
5509 my_error(ER_COLUMNACCESS_DENIED_ERROR, MYF(0),
5510 "ANY", thd->security_ctx->priv_user,
5511 thd->security_ctx->host_or_ip, field_name, tab);
5517 if (!outer_fixed && !thd->lex->in_sum_func &&
5518 thd->lex->current_select->cur_pos_in_all_fields !=
5519 SELECT_LEX::ALL_FIELDS_UNDEF_POS)
5522 if (thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY)
5530 if (thd->lex->current_select->with_sum_func &&
5531 !thd->lex->current_select->group_list.elements)
5536 if (fixed && thd->variables.sql_mode & MODE_ONLY_FULL_GROUP_BY)
5548 SELECT_LEX *select_lex= cached_table ?
5549 cached_table->select_lex : context->select_lex;
5550 if (!thd->lex->in_sum_func)
5551 select_lex->set_non_agg_field_used(
true);
5555 thd->lex->in_sum_func->outer_fields.push_back(
this);
5556 else if (thd->lex->in_sum_func->nest_level !=
5557 thd->lex->current_select->nest_level)
5558 select_lex->set_non_agg_field_used(
true);
5564 context->process_error(thd);
5571 return Item::safe_charset_converter(tocs);
5575 void Item_field::cleanup()
5577 DBUG_ENTER(
"Item_field::cleanup");
5578 Item_ident::cleanup();
5584 field= result_field= 0;
5614 while ((item= li++))
5623 cond_equal= cond_equal->upper_levels;
5661 return (result_type() != STRING_RESULT) || (*arg);
5677 static void convert_zerofill_number_to_string(
Item **item,
Field_num *field)
5679 char buff[MAX_FIELD_WIDTH],*pos;
5680 String tmp(buff,
sizeof(buff), field->charset()), *res;
5682 res= (*item)->val_str(&tmp);
5683 if ((*item)->is_null())
5687 field->prepend_zeros(res);
5688 pos= (
char *) sql_strmake (res->ptr(), res->length());
5689 *item=
new Item_string(pos, res->length(), field->charset());
5725 item= item_equal->get_const();
5737 else if (field && (field->flags & ZEROFILL_FLAG) && IS_NUM(field->type()))
5744 if (item && field->type() != FIELD_TYPE_TIMESTAMP && cmp_context != INT_RESULT)
5745 convert_zerofill_number_to_string(&item, (
Field_num *)field);
5761 if (field->charset() != &my_charset_bin)
5796 Item *const_item= item_equal->get_const();
5805 if (field->table != subst->field->table && !field->eq(subst->field))
5812 void Item::init_make_field(
Send_field *tmp_field,
5813 enum enum_field_types field_type_arg)
5815 char *empty_name= (
char*)
"";
5816 tmp_field->db_name= empty_name;
5817 tmp_field->org_table_name= empty_name;
5818 tmp_field->org_col_name= empty_name;
5819 tmp_field->table_name= empty_name;
5820 tmp_field->col_name= item_name.
ptr();
5821 tmp_field->charsetnr= collation.collation->number;
5822 tmp_field->flags= (maybe_null ? 0 : NOT_NULL_FLAG) |
5823 (my_binary_compare(charset_for_protocol()) ?
5825 tmp_field->type= field_type_arg;
5826 tmp_field->length=max_length;
5827 tmp_field->decimals=decimals;
5829 tmp_field->flags |= UNSIGNED_FLAG;
5834 init_make_field(tmp_field, field_type());
5838 enum_field_types Item::string_field_type()
const
5840 enum_field_types f_type= MYSQL_TYPE_VAR_STRING;
5841 if (max_length >= 16777216)
5842 f_type= MYSQL_TYPE_LONG_BLOB;
5843 else if (max_length >= 65536)
5844 f_type= MYSQL_TYPE_MEDIUM_BLOB;
5849 void Item_empty_string::make_field(
Send_field *tmp_field)
5851 init_make_field(tmp_field, string_field_type());
5855 enum_field_types Item::field_type()
const
5857 switch (result_type()) {
5858 case STRING_RESULT:
return string_field_type();
5859 case INT_RESULT:
return MYSQL_TYPE_LONGLONG;
5860 case DECIMAL_RESULT:
return MYSQL_TYPE_NEWDECIMAL;
5861 case REAL_RESULT:
return MYSQL_TYPE_DOUBLE;
5865 return MYSQL_TYPE_VARCHAR;
5870 String *Item::check_well_formed_result(
String *str,
bool send_error)
5874 int well_formed_error;
5875 uint wlen= cs->cset->well_formed_len(cs,
5876 str->ptr(), str->ptr() + str->length(),
5877 str->length(), &well_formed_error);
5878 if (wlen < str->length())
5880 THD *thd= current_thd;
5882 uint diff= str->length() - wlen;
5883 set_if_smaller(diff, 3);
5884 octet2hex(hexbuf, str->ptr() + wlen, diff);
5887 my_error(ER_INVALID_CHARACTER_STRING, MYF(0),
5888 cs->csname, hexbuf);
5891 if (thd->is_strict_mode())
5900 push_warning_printf(thd, Sql_condition::WARN_LEVEL_WARN, ER_INVALID_CHARACTER_STRING,
5901 ER(ER_INVALID_CHARACTER_STRING), cs->csname, hexbuf);
5927 bool Item::eq_by_collation(
Item *item,
bool binary_cmp,
5932 if (collation.collation != cs)
5934 save_cs= collation.collation;
5935 collation.collation= cs;
5937 if (item->collation.collation != cs)
5939 save_item_cs= item->collation.collation;
5940 item->collation.collation= cs;
5942 bool res=
eq(item, binary_cmp);
5944 collation.collation= save_cs;
5946 item->collation.collation= save_item_cs;
5964 DBUG_ENTER(
"Item::can_be_evaluated_now");
5971 current_thd->lex->is_query_tables_locked();
5992 DBUG_ASSERT(collation.collation);
5993 if (max_length/collation.collation->mbmaxlen > CONVERT_IF_BIGGER_TO_BLOB)
5994 field=
new Field_blob(max_length, maybe_null, item_name.
ptr(),
5995 collation.collation, TRUE);
5997 else if (max_length > 0 &&
5998 (type() != Item::TYPE_HOLDER || field_type() != MYSQL_TYPE_STRING))
6000 table->s, collation.collation);
6003 collation.collation);
6027 uchar *null_ptr= maybe_null ? (uchar*)
"" : 0;
6030 switch (field_type()) {
6031 case MYSQL_TYPE_DECIMAL:
6032 case MYSQL_TYPE_NEWDECIMAL:
6033 field= Field_new_decimal::create_from_item(
this);
6035 case MYSQL_TYPE_TINY:
6036 field=
new Field_tiny((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
6037 item_name.
ptr(), 0, unsigned_flag);
6039 case MYSQL_TYPE_SHORT:
6040 field=
new Field_short((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
6041 item_name.
ptr(), 0, unsigned_flag);
6043 case MYSQL_TYPE_LONG:
6044 field=
new Field_long((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
6045 item_name.
ptr(), 0, unsigned_flag);
6047 #ifdef HAVE_LONG_LONG
6048 case MYSQL_TYPE_LONGLONG:
6049 field=
new Field_longlong((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
6050 item_name.
ptr(), 0, unsigned_flag);
6053 case MYSQL_TYPE_FLOAT:
6054 field=
new Field_float((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
6055 item_name.
ptr(), decimals, 0, unsigned_flag);
6057 case MYSQL_TYPE_DOUBLE:
6058 field=
new Field_double((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
6059 item_name.
ptr(), decimals, 0, unsigned_flag);
6061 case MYSQL_TYPE_INT24:
6062 field=
new Field_medium((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
6063 item_name.
ptr(), 0, unsigned_flag);
6065 case MYSQL_TYPE_DATE:
6066 case MYSQL_TYPE_NEWDATE:
6069 case MYSQL_TYPE_TIME:
6072 case MYSQL_TYPE_TIMESTAMP:
6075 case MYSQL_TYPE_DATETIME:
6078 case MYSQL_TYPE_YEAR:
6079 field=
new Field_year((uchar*) 0, max_length, null_ptr, 0, Field::NONE,
6082 case MYSQL_TYPE_BIT:
6084 Field::NONE, item_name.
ptr());
6090 case MYSQL_TYPE_STRING:
6091 case MYSQL_TYPE_NULL:
6092 if (fixed_length && max_length < CONVERT_IF_BIGGER_TO_BLOB)
6095 collation.collation);
6099 case MYSQL_TYPE_ENUM:
6100 case MYSQL_TYPE_SET:
6101 case MYSQL_TYPE_VAR_STRING:
6102 case MYSQL_TYPE_VARCHAR:
6104 case MYSQL_TYPE_TINY_BLOB:
6105 case MYSQL_TYPE_MEDIUM_BLOB:
6106 case MYSQL_TYPE_LONG_BLOB:
6107 case MYSQL_TYPE_BLOB:
6108 if (this->type() == Item::TYPE_HOLDER)
6109 field=
new Field_blob(max_length, maybe_null, item_name.
ptr(), collation.collation,
6112 field=
new Field_blob(max_length, maybe_null, item_name.
ptr(), collation.collation);
6115 case MYSQL_TYPE_GEOMETRY:
6116 field=
new Field_geom(max_length, maybe_null,
6117 item_name.
ptr(), table->s, get_geometry_type());
6127 void Item_field::make_field(
Send_field *tmp_field)
6129 field->make_field(tmp_field);
6130 DBUG_ASSERT(tmp_field->table_name != 0);
6132 tmp_field->col_name= item_name.
ptr();
6134 tmp_field->table_name= table_name;
6136 tmp_field->db_name= db_name;
6146 if (field->is_null())
6159 type_conversion_status
6162 type_conversion_status res;
6163 DBUG_ENTER(
"Item_field::save_in_field");
6164 if (result_field->is_null())
6175 if (to == result_field)
6178 DBUG_RETURN(TYPE_OK);
6201 type_conversion_status
6221 return set_field_to_null(field);
6234 type_conversion_status
6237 type_conversion_status error;
6238 if (result_type() == STRING_RESULT)
6242 char buff[MAX_FIELD_WIDTH];
6243 str_value.set_quick(buff,
sizeof(buff), cs);
6244 result=val_str(&str_value);
6247 str_value.set_quick(0, 0, cs);
6253 field->set_notnull();
6254 error=field->store(result->ptr(),result->length(),cs);
6255 str_value.set_quick(0, 0, cs);
6257 else if (result_type() == REAL_RESULT &&
6258 field->result_type() == STRING_RESULT)
6260 double nr= val_real();
6263 field->set_notnull();
6264 error= field->store(nr);
6266 else if (result_type() == REAL_RESULT)
6268 double nr= val_real();
6271 field->set_notnull();
6272 error=field->store(nr);
6274 else if (result_type() == DECIMAL_RESULT)
6277 my_decimal *value= val_decimal(&decimal_value);
6280 field->set_notnull();
6281 error=field->store_decimal(value);
6285 longlong nr=val_int();
6288 field->set_notnull();
6289 error=field->store(nr, unsigned_flag);
6291 return error ? error : (field->table->in_use->is_error() ?
6292 TYPE_ERR_BAD_VALUE : TYPE_OK);
6296 type_conversion_status
6300 result=val_str(&str_value);
6301 return save_str_value_in_field(field, result);
6305 type_conversion_status
6324 static type_conversion_status
6325 save_int_value_in_field (
Field *field, longlong nr,
6326 bool null_value,
bool unsigned_flag)
6330 return set_field_to_null(field);
6331 field->set_notnull();
6332 return field->store(nr, unsigned_flag);
6353 type_conversion_status
6356 return save_int_value_in_field (field, val_int(), null_value,
6361 type_conversion_status
6364 longlong nr= field->is_temporal_with_time() ?
6369 return set_field_to_null(field);
6370 field->set_notnull();
6375 type_conversion_status
6378 field->set_notnull();
6379 return field->store_decimal(&decimal_value);
6386 if (arg->basic_const_item() && arg->type() == type())
6393 return item->val_int() == value && item->unsigned_flag == unsigned_flag;
6399 Item *Item_int_with_ref::clone_item()
6401 DBUG_ASSERT(ref->const_item());
6406 return (ref->unsigned_flag ?
6407 new Item_uint(ref->item_name, ref->val_int(), ref->max_length) :
6408 new Item_int(ref->item_name, ref->val_int(), ref->max_length));
6412 Item *Item_time_with_ref::clone_item()
6414 DBUG_ASSERT(ref->const_item());
6424 Item *Item_datetime_with_ref::clone_item()
6426 DBUG_ASSERT(ref->const_item());
6431 return new Item_temporal(MYSQL_TYPE_DATETIME, ref->item_name,
6438 char buff[MAX_DATE_STRING_REP_LENGTH];
6440 TIME_from_longlong_packed(<ime, field_type(), value);
6442 my_TIME_to_str(<ime, buff, decimals);
6455 static uint nr_of_decimals(
const char *str,
const char *end)
6457 const char *decimal_point;
6464 if (*str ==
'e' || *str ==
'E')
6465 return NOT_FIXED_DEC;
6470 for ( ; str < end && my_isdigit(system_charset_info, *str) ; str++)
6472 if (str < end && (*str ==
'e' || *str ==
'E'))
6473 return NOT_FIXED_DEC;
6491 return (uint) (str - decimal_point);
6510 value= my_strntod(&my_charset_bin, (
char*) str_arg, length, &end_not_used,
6514 char tmp[NAME_LEN + 1];
6515 my_snprintf(tmp,
sizeof(tmp),
"%.*s", length, str_arg);
6516 my_error(ER_ILLEGAL_VALUE_FOR_TYPE, MYF(0),
"double", tmp);
6518 presentation.
copy(str_arg, length);
6519 item_name.
copy(str_arg, length);
6520 decimals=(uint8) nr_of_decimals(str_arg, str_arg+length);
6526 type_conversion_status
6529 double nr= val_real();
6532 return set_field_to_null(field);
6533 field->set_notnull();
6534 return field->store(nr);
6540 if (presentation.
ptr())
6542 str->append(presentation.
ptr());
6546 String num(buffer,
sizeof(buffer), &my_charset_bin);
6547 num.set_real(value, decimals, &my_charset_bin);
6560 if (arg->basic_const_item() && arg->type() == type())
6567 return item->val_real() == value;
6573 inline uint char_val(
char X)
6575 return (uint) (X >=
'0' && X <=
'9' ? X-
'0' :
6576 X >=
'A' && X <=
'Z' ? X-
'A'+10 :
6580 Item_hex_string::Item_hex_string()
6582 hex_string_init(
"", 0);
6585 Item_hex_string::Item_hex_string(
const char *str, uint str_length)
6587 hex_string_init(str, str_length);
6590 void Item_hex_string::hex_string_init(
const char *str, uint str_length)
6592 max_length=(str_length+1)/2;
6593 char *ptr=(
char*) sql_alloc(max_length+1);
6596 str_value.set(
"", 0, &my_charset_bin);
6599 str_value.set(ptr,max_length,&my_charset_bin);
6600 char *end=ptr+max_length;
6601 if (max_length*2 != str_length)
6602 *ptr++=char_val(*str++);
6605 *ptr++= (char) (char_val(str[0])*16+char_val(str[1]));
6609 collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
6614 longlong Item_hex_string::val_int()
6617 DBUG_ASSERT(fixed == 1);
6618 char *end=(
char*) str_value.ptr()+str_value.length(),
6619 *ptr= end - min<size_t>(str_value.length(),
sizeof(longlong));
6622 for (; ptr != end ; ptr++)
6623 value=(value << 8)+ (ulonglong) (uchar) *ptr;
6624 return (longlong) value;
6631 DBUG_ASSERT(fixed == 1);
6632 ulonglong value= (ulonglong)val_int();
6633 int2my_decimal(E_DEC_FATAL_ERROR, value, TRUE, decimal_value);
6634 return (decimal_value);
6638 type_conversion_status
6641 field->set_notnull();
6642 if (field->result_type() == STRING_RESULT)
6643 return field->store(str_value.ptr(), str_value.length(),
6644 collation.collation);
6647 uint32 length= str_value.length();
6651 return TYPE_WARN_OUT_OF_RANGE;
6655 nr= field->flags & UNSIGNED_FLAG ? ULONGLONG_MAX : LONGLONG_MAX;
6658 nr= (ulonglong) val_int();
6659 if ((length == 8) && !(field->flags & UNSIGNED_FLAG) && (nr > LONGLONG_MAX))
6664 return field->store((longlong) nr, TRUE);
6667 const type_conversion_status res= field->store((longlong) nr, TRUE);
6669 field->
set_warning(Sql_condition::WARN_LEVEL_WARN,
6670 ER_WARN_DATA_OUT_OF_RANGE, 1);
6677 char *end= (
char*) str_value.ptr() + str_value.length(),
6678 *ptr= end - min<size_t>(str_value.length(),
sizeof(longlong));
6680 for (; ptr != end ; ptr++)
6682 str->append(_dig_vec_lower[((uchar) *ptr) >> 4]);
6683 str->append(_dig_vec_lower[((uchar) *ptr) & 0x0F]);
6690 if (arg->basic_const_item() && arg->type() == type())
6693 return !stringcmp(&str_value, &arg->str_value);
6694 return !sortcmp(&str_value, &arg->str_value, collation.collation);
6703 String tmp, *str= val_str(&tmp);
6705 if (!(conv=
new Item_string(str->ptr(), str->length(), tocs)))
6707 conv->str_value.copy();
6708 conv->str_value.mark_as_const();
6719 Item_bin_string::Item_bin_string(
const char *str, uint str_length)
6721 const char *end= str + str_length - 1;
6725 max_length= (str_length + 7) >> 3;
6726 char *ptr= (
char*) sql_alloc(max_length + 1);
6729 str_value.set(ptr, max_length, &my_charset_bin);
6733 ptr+= max_length - 1;
6735 for (; end >= str; end--)
6752 collation.set(&my_charset_bin, DERIVATION_COERCIBLE);
6763 return protocol->store_null();
6772 bool UNINIT_VAR(result);
6773 enum_field_types f_type;
6775 switch ((f_type=field_type())) {
6777 case MYSQL_TYPE_NULL:
6778 case MYSQL_TYPE_DECIMAL:
6779 case MYSQL_TYPE_ENUM:
6780 case MYSQL_TYPE_SET:
6781 case MYSQL_TYPE_TINY_BLOB:
6782 case MYSQL_TYPE_MEDIUM_BLOB:
6783 case MYSQL_TYPE_LONG_BLOB:
6784 case MYSQL_TYPE_BLOB:
6785 case MYSQL_TYPE_GEOMETRY:
6786 case MYSQL_TYPE_STRING:
6787 case MYSQL_TYPE_VAR_STRING:
6788 case MYSQL_TYPE_VARCHAR:
6789 case MYSQL_TYPE_BIT:
6790 case MYSQL_TYPE_NEWDECIMAL:
6793 if ((res=val_str(buffer)))
6794 result= protocol->
store(res->ptr(),res->length(),res->charset());
6797 DBUG_ASSERT(null_value);
6801 case MYSQL_TYPE_TINY:
6806 result= protocol->store_tiny(nr);
6809 case MYSQL_TYPE_SHORT:
6810 case MYSQL_TYPE_YEAR:
6815 result= protocol->store_short(nr);
6818 case MYSQL_TYPE_INT24:
6819 case MYSQL_TYPE_LONG:
6824 result= protocol->store_long(nr);
6827 case MYSQL_TYPE_LONGLONG:
6832 result= protocol->store_longlong(nr, unsigned_flag);
6835 case MYSQL_TYPE_FLOAT:
6838 nr= (float) val_real();
6840 result= protocol->
store(nr, decimals, buffer);
6843 case MYSQL_TYPE_DOUBLE:
6845 double nr= val_real();
6847 result= protocol->
store(nr, decimals, buffer);
6850 case MYSQL_TYPE_DATETIME:
6851 case MYSQL_TYPE_DATE:
6852 case MYSQL_TYPE_TIMESTAMP:
6855 get_date(&tm, TIME_FUZZY_DATE);
6857 result= (f_type == MYSQL_TYPE_DATE) ? protocol->store_date(&tm) :
6858 protocol->
store(&tm, decimals);
6861 case MYSQL_TYPE_TIME:
6866 result= protocol->store_time(&tm, decimals);
6871 result= protocol->store_null();
6890 Item *item= real_item();
6896 !(basic_const_item() || item->basic_const_item() ||
6897 item->type() == Item::FIELD_ITEM ||
6898 item->type() == SUBSELECT_ITEM ||
6899 item->type() == CACHE_ITEM ||
6905 (item->type() == Item::FUNC_ITEM &&
6906 ((
Item_func*)item)->functype() == Item_func::GUSERVAR_FUNC)))
6943 DBUG_ASSERT(*item ==
this);
6948 *((
Item **)arg)= NULL;
6949 Item_cache *cache= Item_cache::get_cache(
this);
6962 const char *
name=
reinterpret_cast<char*
>(*arg);
6964 if (strcmp(field_name, name) == 0)
6973 Item *item=
reinterpret_cast<Item*
>(arg);
6974 item->item_name= item_name;
6981 return protocol->
store(result_field);
6985 void Item_field::update_null_value()
6991 THD *thd= field->table->in_use;
6994 no_errors= thd->no_errors;
6996 Item::update_null_value();
6997 thd->no_errors= no_errors;
7023 Item *Item_field::update_value_transformer(uchar *select_arg)
7025 SELECT_LEX *select= (SELECT_LEX*)select_arg;
7028 if (field->table != select->context.table_list->table &&
7029 type() != Item::TRIGGER_FIELD_ITEM)
7031 List<Item> *all_fields= &select->join->all_fields;
7032 Ref_ptr_array &ref_pointer_array= select->ref_pointer_array;
7033 int el= all_fields->elements;
7036 ref_pointer_array[el]= (
Item*)
this;
7037 all_fields->push_front((
Item*)
this);
7038 ref=
new Item_ref(&select->context, &ref_pointer_array[el],
7039 table_name, field_name);
7048 if (field && field->table->const_table)
7050 char buff[MAX_FIELD_WIDTH];
7051 String tmp(buff,
sizeof(buff),str->charset());
7052 field->val_str(&tmp);
7053 if (field->is_null())
7054 str->append(
"NULL");
7068 Item **item,
const char *table_name_arg,
7069 const char *field_name_arg,
7070 bool alias_name_used_arg)
7071 :
Item_ident(context_arg, NullS, table_name_arg, field_name_arg),
7072 result_field(0), ref(item)
7074 alias_name_used= alias_name_used_arg;
7078 if (ref && *ref && (*ref)->fixed)
7149 enum_parsing_place place= NO_MATTER;
7150 DBUG_ASSERT(fixed == 0);
7151 SELECT_LEX *current_sel= thd->lex->current_select;
7153 if (!ref || ref == not_found_item)
7155 if (!(ref= resolve_ref_in_select_and_group(thd,
this,
7156 context->select_lex)))
7159 if (ref == not_found_item)
7169 my_error(ER_BAD_FIELD_ERROR,MYF(0),
7170 this->full_name(), current_thd->where);
7183 from_field= (
Field*) not_found_field;
7187 SELECT_LEX *select= outer_context->select_lex;
7189 last_checked_context->select_lex->master_unit()->item;
7190 last_checked_context= outer_context;
7195 if (!(ref= resolve_ref_in_select_and_group(thd,
this, select)))
7197 if (ref != not_found_item)
7199 DBUG_ASSERT(is_fixed_or_outer_ref(*ref));
7200 prev_subselect_item->used_tables_cache|= (*ref)->used_tables();
7201 prev_subselect_item->const_item_cache&= (*ref)->const_item();
7212 place= prev_subselect_item->parsing_place;
7223 if ((place != IN_HAVING ||
7224 (!select->with_sum_func &&
7225 select->group_list.elements == 0)))
7232 from_field= find_field_in_tables(thd,
this,
7234 first_name_resolution_table,
7236 last_name_resolution_table,
7238 IGNORE_EXCEPT_NON_UNIQUE,
7242 if (from_field == view_ref_found)
7244 Item::Type refer_type= (*reference)->type();
7245 prev_subselect_item->used_tables_cache|=
7246 (*reference)->used_tables();
7247 prev_subselect_item->const_item_cache&=
7248 (*reference)->const_item();
7249 DBUG_ASSERT((*reference)->type() == REF_ITEM);
7250 mark_as_dependent(thd, last_checked_context->select_lex,
7251 context->select_lex,
this,
7252 ((refer_type == REF_ITEM ||
7253 refer_type == FIELD_ITEM) ?
7262 if (from_field != not_found_field)
7264 if (cached_table && cached_table->select_lex &&
7265 outer_context->select_lex &&
7266 cached_table->select_lex != outer_context->select_lex)
7275 outer_context= outer_context->outer_context;
7276 select= outer_context->select_lex;
7277 prev_subselect_item=
7278 last_checked_context->select_lex->master_unit()->item;
7279 last_checked_context= outer_context;
7280 }
while (outer_context && outer_context->select_lex &&
7281 cached_table->select_lex != outer_context->select_lex);
7283 prev_subselect_item->used_tables_cache|= from_field->table->map;
7284 prev_subselect_item->const_item_cache= 0;
7288 DBUG_ASSERT(from_field == not_found_field);
7291 prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT;
7292 prev_subselect_item->const_item_cache= 0;
7294 outer_context= outer_context->outer_context;
7295 }
while (outer_context);
7297 DBUG_ASSERT(from_field != 0 && from_field != view_ref_found);
7298 if (from_field != not_found_field)
7303 Prepared_stmt_arena_holder ps_arena_holder(thd);
7304 fld=
new Item_field(thd, last_checked_context, from_field);
7310 thd->change_item_tree(reference, fld);
7311 mark_as_dependent(thd, last_checked_context->select_lex,
7312 thd->lex->current_select,
this, fld);
7318 if (thd->lex->in_sum_func &&
7319 thd->lex->in_sum_func->nest_level >=
7320 last_checked_context->select_lex->nest_level)
7321 set_if_bigger(thd->lex->in_sum_func->max_arg_level,
7322 last_checked_context->select_lex->nest_level);
7328 my_error(ER_BAD_FIELD_ERROR, MYF(0),
7329 this->full_name(), current_thd->where);
7333 DBUG_ASSERT(is_fixed_or_outer_ref(*ref));
7334 mark_as_dependent(thd, last_checked_context->select_lex,
7335 context->select_lex,
this,
this);
7341 if (thd->lex->in_sum_func &&
7342 thd->lex->in_sum_func->nest_level >=
7343 last_checked_context->select_lex->nest_level)
7344 set_if_bigger(thd->lex->in_sum_func->max_arg_level,
7345 last_checked_context->select_lex->nest_level);
7356 if (!((*ref)->type() == REF_ITEM &&
7357 ((
Item_ref *)(*ref))->ref_type() == OUTER_REF) &&
7358 (((*ref)->with_sum_func && item_name.
ptr() &&
7359 !(current_sel->linkage != GLOBAL_OPTIONS_TYPE &&
7360 current_sel->having_fix_field)) ||
7363 my_error(ER_ILLEGAL_REFERENCE, MYF(0),
7364 item_name.
ptr(), ((*ref)->with_sum_func?
7365 "reference to group function":
7366 "forward reference in item list"));
7372 if ((*ref)->check_cols(1))
7377 context->process_error(thd);
7382 void Item_ref::set_properties()
7384 max_length= (*ref)->max_length;
7385 maybe_null= (*ref)->maybe_null;
7386 decimals= (*ref)->decimals;
7387 collation.set((*ref)->collation);
7392 with_sum_func= (*ref)->with_sum_func;
7393 unsigned_flag= (*ref)->unsigned_flag;
7395 if (alias_name_used)
7397 if ((*ref)->type() == FIELD_ITEM)
7398 alias_name_used= ((
Item_ident *) (*ref))->alias_name_used;
7400 alias_name_used= TRUE;
7404 void Item_ref::cleanup()
7406 DBUG_ENTER(
"Item_ref::cleanup");
7407 Item_ident::cleanup();
7433 DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
7434 DBUG_ASSERT((*ref) != NULL);
7445 if (new_item != *ref)
7449 Item *transformed_item= (this->*transformer)(arg);
7450 DBUG_ASSERT(transformed_item ==
this);
7451 return transformed_item;
7477 Item_transformer transformer, uchar *arg_t)
7479 if (!(this->*analyzer)(arg_p))
7482 DBUG_ASSERT((*ref) != NULL);
7483 Item *new_item= (*ref)->compile(analyzer, arg_p, transformer, arg_t);
7484 if (new_item == NULL)
7491 if (new_item != *ref)
7494 return (this->*transformer)(arg_t);
7502 if ((*ref)->type() != Item::CACHE_ITEM && ref_type() != VIEW_REF &&
7503 !table_name && item_name.
ptr() && alias_name_used)
7505 THD *thd= current_thd;
7506 append_identifier(thd, str, (*ref)->real_item()->item_name);
7509 (*ref)->print(str, query_type);
7519 return prot->
store(result_field);
7520 return (*ref)->send(prot, tmp);
7524 double Item_ref::val_result()
7528 if ((null_value= result_field->is_null()))
7530 return result_field->val_real();
7536 bool Item_ref::is_null_result()
7539 return (null_value=result_field->is_null());
7545 longlong Item_ref::val_int_result()
7549 if ((null_value= result_field->is_null()))
7551 return result_field->val_int();
7561 if ((null_value= result_field->is_null()))
7563 str->set_charset(str_value.charset());
7564 return result_field->val_str(str, &str_value);
7566 return val_str(str);
7574 if ((null_value= result_field->is_null()))
7576 return result_field->val_decimal(decimal_value);
7578 return val_decimal(decimal_value);
7582 bool Item_ref::val_bool_result()
7586 if ((null_value= result_field->is_null()))
7588 switch (result_field->result_type()) {
7590 return result_field->val_int() != 0;
7591 case DECIMAL_RESULT:
7594 my_decimal *val= result_field->val_decimal(&decimal_value);
7596 return !my_decimal_is_zero(val);
7601 return result_field->val_real() != 0.0;
7611 double Item_ref::val_real()
7614 double tmp=(*ref)->val_result();
7615 null_value=(*ref)->null_value;
7620 longlong Item_ref::val_int()
7623 longlong tmp=(*ref)->val_int_result();
7624 null_value=(*ref)->null_value;
7632 DBUG_ASSERT((*ref)->is_temporal());
7633 longlong tmp= (*ref)->val_time_temporal_result();
7634 null_value= (*ref)->null_value;
7642 DBUG_ASSERT((*ref)->is_temporal());
7643 longlong tmp= (*ref)->val_date_temporal_result();
7644 null_value= (*ref)->null_value;
7652 bool tmp= (*ref)->val_bool_result();
7653 null_value= (*ref)->null_value;
7661 tmp=(*ref)->str_result(tmp);
7662 null_value=(*ref)->null_value;
7667 bool Item_ref::is_null()
7670 bool tmp=(*ref)->is_null_result();
7671 null_value=(*ref)->null_value;
7676 bool Item_ref::get_date(
MYSQL_TIME *ltime,uint fuzzydate)
7678 return (null_value=(*ref)->get_date_result(ltime,fuzzydate));
7684 my_decimal *val= (*ref)->val_decimal_result(decimal_value);
7685 null_value= (*ref)->null_value;
7689 type_conversion_status
7692 type_conversion_status res;
7695 if (result_field->is_null())
7706 res= (*ref)->save_in_field(to, no_conversions);
7707 null_value= (*ref)->null_value;
7712 void Item_ref::save_org_in_field(
Field *field)
7714 (*ref)->save_org_in_field(field);
7720 (*ref)->make_field(field);
7723 field->col_name= item_name.
ptr();
7725 field->table_name= table_name;
7727 field->db_name= db_name;
7728 if (orig_field_name)
7729 field->org_col_name= orig_field_name;
7730 if (orig_table_name)
7731 field->org_table_name= orig_table_name;
7735 Item *Item_ref::get_tmp_table_item(THD *thd)
7738 return (*ref)->get_tmp_table_item(thd);
7743 item->table_name= table_name;
7744 item->db_name= db_name;
7752 str->append(STRING_WITH_LEN(
"<ref_null_helper>("));
7754 (*ref)->print(str, query_type);
7761 double Item_direct_ref::val_real()
7763 double tmp=(*ref)->val_real();
7764 null_value=(*ref)->null_value;
7769 longlong Item_direct_ref::val_int()
7771 longlong tmp=(*ref)->val_int();
7772 null_value=(*ref)->null_value;
7779 DBUG_ASSERT((*ref)->is_temporal());
7780 longlong tmp= (*ref)->val_time_temporal();
7781 null_value= (*ref)->null_value;
7788 DBUG_ASSERT((*ref)->is_temporal());
7789 longlong tmp= (*ref)->val_date_temporal();
7790 null_value= (*ref)->null_value;
7797 tmp=(*ref)->val_str(tmp);
7798 null_value=(*ref)->null_value;
7805 my_decimal *tmp= (*ref)->val_decimal(decimal_value);
7806 null_value=(*ref)->null_value;
7813 bool tmp= (*ref)->val_bool();
7814 null_value=(*ref)->null_value;
7819 bool Item_direct_ref::is_null()
7821 return (*ref)->is_null();
7825 bool Item_direct_ref::get_date(
MYSQL_TIME *ltime,uint fuzzydate)
7827 bool tmp= (*ref)->get_date(ltime, fuzzydate);
7828 null_value= (*ref)->null_value;
7852 Item *ref_item= (*ref)->real_item();
7853 if (ref_item->type() == Item::FIELD_ITEM)
7861 DBUG_ASSERT(fld && fld->table);
7862 if (thd->mark_used_columns == MARK_COLUMNS_READ)
7863 bitmap_set_bit(fld->table->read_set, fld->field_index);
7866 else if (!(*ref)->fixed &&
7867 ((*ref)->fix_fields(thd, ref)))
7890 if ((*ref) && !(*ref)->fixed && ((*ref)->fix_fields(thd, reference)))
7895 if ((*ref)->type() == Item::FIELD_ITEM)
7896 table_name= ((
Item_field*)outer_ref)->table_name;
7901 st_select_lex *removed_select)
7907 DBUG_ASSERT(*ref == outer_ref);
7913 st_select_lex *removed_select)
7915 (*ref)->fix_after_pullout(parent_select, removed_select);
7940 if (item->type() == REF_ITEM)
7943 if (item_ref->ref_type() == VIEW_REF)
7945 Item *item_ref_ref= *(item_ref->ref);
7946 return ((*ref)->real_item() == item_ref_ref->real_item());
7954 return item->type() == DEFAULT_VALUE_ITEM &&
7964 DBUG_ASSERT(fixed == 0);
7971 if (!arg->fixed && arg->fix_fields(thd, &arg))
7975 real_arg= arg->real_item();
7976 if (real_arg->type() != FIELD_ITEM)
7978 my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), arg->item_name.
ptr());
7983 if (field_arg->field->flags & NO_DEFAULT_VALUE_FLAG)
7985 my_error(ER_NO_DEFAULT_FOR_FIELD, MYF(0), field_arg->field->field_name);
7989 def_field= field_arg->field->
clone();
7990 if (def_field == NULL)
7993 def_field->move_field_offset((my_ptrdiff_t)
7994 (def_field->table->s->default_values -
7995 def_field->table->record[0]));
7996 set_field(def_field);
8000 context->process_error(thd);
8009 str->append(STRING_WITH_LEN(
"default"));
8012 str->append(STRING_WITH_LEN(
"default("));
8013 arg->
print(str, query_type);
8018 type_conversion_status
8023 if (field_arg->flags & NO_DEFAULT_VALUE_FLAG &&
8024 field_arg->real_type() != MYSQL_TYPE_ENUM)
8026 if (field_arg->reset())
8028 my_message(ER_CANT_CREATE_GEOMETRY_OBJECT,
8029 ER(ER_CANT_CREATE_GEOMETRY_OBJECT), MYF(0));
8030 return TYPE_ERR_BAD_VALUE;
8033 if (context->error_processor == &view_error_processor)
8036 push_warning_printf(field_arg->table->in_use,
8037 Sql_condition::WARN_LEVEL_WARN,
8038 ER_NO_DEFAULT_FOR_VIEW_FIELD,
8039 ER(ER_NO_DEFAULT_FOR_VIEW_FIELD),
8041 view->view_name.str);
8045 push_warning_printf(field_arg->table->in_use,
8046 Sql_condition::WARN_LEVEL_WARN,
8047 ER_NO_DEFAULT_FOR_FIELD,
8048 ER(ER_NO_DEFAULT_FOR_FIELD),
8049 field_arg->field_name);
8051 return TYPE_ERR_BAD_VALUE;
8053 field_arg->set_default();
8054 return field_arg->validate_stored_val(current_thd);
8067 DBUG_ASSERT(!current_thd->stmt_arena->is_stmt_prepare());
8086 if (arg != new_item)
8087 current_thd->change_item_tree(&arg, new_item);
8088 return (this->*transformer)(args);
8094 return item->type() == INSERT_VALUE_ITEM &&
8101 DBUG_ASSERT(fixed == 0);
8106 TABLE_LIST *orig_next_table= context->last_name_resolution_table;
8107 context->last_name_resolution_table= context->first_name_resolution_table;
8108 res= arg->fix_fields(thd, &arg);
8109 context->last_name_resolution_table= orig_next_table;
8114 if (arg->type() == REF_ITEM)
8115 arg= static_cast<Item_ref *>(arg)->ref[0];
8116 if (arg->type() != FIELD_ITEM)
8118 my_error(ER_BAD_FIELD_ERROR, MYF(0),
"",
"VALUES() function");
8124 if (field_arg->field->table->insert_values &&
8125 find_item_in_item_list(
this, &thd->lex->value_list))
8131 def_field->move_field_offset((my_ptrdiff_t)
8132 (def_field->table->insert_values -
8133 def_field->table->record[0]));
8134 set_field(def_field);
8139 Prepared_stmt_arena_holder ps_arena_holder(thd);
8150 str->append(STRING_WITH_LEN(
"values("));
8151 arg->
print(str, query_type);
8186 enum_mark_columns save_mark_used_columns= thd->mark_used_columns;
8187 thd->mark_used_columns= MARK_COLUMNS_NONE;
8192 (void)find_field_in_table(thd, table, field_name, (uint) strlen(field_name),
8194 thd->mark_used_columns= save_mark_used_columns;
8195 triggers= table->triggers;
8196 table_grants= table_grant_info;
8200 bool Item_trigger_field::eq(
const Item *item,
bool binary_cmp)
const
8202 return item->type() == TRIGGER_FIELD_ITEM &&
8204 !my_strcasecmp(system_charset_info, field_name,
8209 void Item_trigger_field::set_required_privilege(
bool rw)
8215 want_privilege= (rw ? SELECT_ACL | UPDATE_ACL : UPDATE_ACL);
8219 bool Item_trigger_field::set_value(THD *thd,
sp_rcontext * ,
Item **it)
8221 Item *item= sp_prepare_func_item(thd, it);
8228 if (fix_fields(thd, NULL))
8234 bool copy_blobs_saved= field->table->copy_blobs;
8236 field->table->copy_blobs=
true;
8240 field->table->copy_blobs= copy_blobs_saved;
8242 return err_code < 0;
8246 bool Item_trigger_field::fix_fields(THD *thd,
Item **
items)
8254 DBUG_ASSERT(fixed == 0);
8258 if (field_idx != (uint)-1)
8260 #ifndef NO_EMBEDDED_ACCESS_CHECKS
8270 if (check_grant_column(thd, table_grants, triggers->
trigger_table->s->db.str,
8272 strlen(field_name), thd->security_ctx))
8275 #endif // NO_EMBEDDED_ACCESS_CHECKS
8277 field= (row_version == OLD_ROW) ? triggers->old_field[field_idx] :
8278 triggers->new_field[field_idx];
8284 my_error(ER_BAD_FIELD_ERROR, MYF(0), field_name,
8285 (row_version == NEW_ROW) ?
"NEW" :
"OLD");
8290 void Item_trigger_field::print(
String *str, enum_query_type query_type)
8292 str->append((row_version == NEW_ROW) ?
"NEW" :
"OLD", 3);
8294 str->append(field_name);
8298 void Item_trigger_field::cleanup()
8300 want_privilege= original_privilege;
8309 Item_result item_cmp_type(Item_result a,Item_result b)
8311 if (a == STRING_RESULT && b == STRING_RESULT)
8312 return STRING_RESULT;
8313 if (a == INT_RESULT && b == INT_RESULT)
8315 else if (a == ROW_RESULT || b == ROW_RESULT)
8317 if ((a == INT_RESULT || a == DECIMAL_RESULT) &&
8318 (b == INT_RESULT || b == DECIMAL_RESULT))
8319 return DECIMAL_RESULT;
8324 void resolve_const_item(THD *thd,
Item **ref,
Item *comp_item)
8327 Item *new_item= NULL;
8328 if (item->basic_const_item())
8330 Item_result res_type=item_cmp_type(comp_item->result_type(),
8331 item->result_type());
8335 char buff[MAX_FIELD_WIDTH];
8336 String tmp(buff,
sizeof(buff),&my_charset_bin),*result;
8337 result=item->val_str(&tmp);
8338 if (item->null_value)
8339 new_item=
new Item_null(item->item_name);
8340 else if (item->is_temporal())
8342 enum_field_types type= item->field_type() == MYSQL_TYPE_TIMESTAMP ?
8343 MYSQL_TYPE_DATETIME : item->field_type();
8345 result->charset(),
type,
true);
8349 uint length= result->length();
8350 char *tmp_str= sql_strmake(result->ptr(), length);
8351 new_item=
new Item_string(item->item_name, tmp_str, length, result->charset());
8357 longlong result=item->val_int();
8358 uint length=item->max_length;
8359 bool null_value=item->null_value;
8360 new_item= (null_value ? (
Item*)
new Item_null(item->item_name) :
8361 (
Item*) new
Item_int(item->item_name, result, length));
8365 if (item->type() == Item::ROW_ITEM && comp_item->type() == Item::ROW_ITEM)
8385 DBUG_ASSERT(item->result_type() == comp_item->result_type());
8386 DBUG_ASSERT(item_row->cols() == comp_item_row->cols());
8387 col= item_row->cols();
8389 resolve_const_item(thd, item_row->addr(col),
8390 comp_item_row->element_index(col));
8396 double result= item->val_real();
8397 uint length=item->max_length,decimals=item->decimals;
8398 bool null_value=item->null_value;
8400 new
Item_float(item->item_name, result, decimals, length));
8403 case DECIMAL_RESULT:
8406 my_decimal *result= item->val_decimal(&decimal_value);
8407 bool null_value= item->null_value;
8408 new_item= (null_value ?
8411 item->max_length, item->decimals));
8418 thd->change_item_tree(ref, new_item);
8441 int stored_field_cmp_to_item(THD *thd,
Field *field,
Item *item)
8443 Item_result res_type=item_cmp_type(field->result_type(),
8444 item->result_type());
8445 if (field->type() == MYSQL_TYPE_TIME &&
8446 item->field_type() == MYSQL_TYPE_TIME)
8450 return field_value < item_value ? -1 : field_value > item_value ? 1 : 0;
8452 if (field->is_temporal_with_date() && item->is_temporal())
8463 return field_value < item_value ? -1 : field_value > item_value ? 1 : 0;
8465 if (res_type == STRING_RESULT)
8467 char item_buff[MAX_FIELD_WIDTH];
8468 char field_buff[MAX_FIELD_WIDTH];
8470 String item_tmp(item_buff,
sizeof(item_buff),&my_charset_bin);
8471 String field_tmp(field_buff,
sizeof(field_buff),&my_charset_bin);
8472 String *item_result= item->val_str(&item_tmp);
8477 if (item->null_value)
8479 String *field_result= field->val_str(&field_tmp);
8481 if (field->is_temporal_with_date())
8483 enum_mysql_timestamp_type type=
8484 field_type_to_timestamp_type(field->type());
8485 const char *field_name= field->field_name;
8490 return my_time_compare(&field_time, &item_time);
8492 return sortcmp(field_result, item_result, field->charset());
8494 if (res_type == INT_RESULT)
8496 if (res_type == DECIMAL_RESULT)
8499 field_buf, *field_val;
8500 item_val= item->val_decimal(&item_buf);
8501 if (item->null_value)
8503 field_val= field->val_decimal(&field_buf);
8511 volatile double result= item->val_real();
8512 if (item->null_value)
8514 volatile double field_result= field->val_real();
8515 if (field_result < result)
8517 else if (field_result > result)
8524 return get_cache(item, item->result_type());
8544 case DECIMAL_RESULT:
8548 if (item->is_temporal())
8560 void Item_cache::store(
Item *item)
8565 value_cached= FALSE;
8570 str->append(STRING_WITH_LEN(
"<cache>("));
8572 example->
print(str, query_type);
8578 bool Item_cache::walk (Item_processor processor,
bool walk_subquery,
8581 if (example && example->walk(processor, walk_subquery, argument))
8583 return (this->*processor)(argument);
8586 bool Item_cache_int::cache_value()
8591 value= example->val_int_result();
8592 null_value= example->null_value;
8593 unsigned_flag= example->unsigned_flag;
8598 void Item_cache_int::store(
Item *item, longlong val_arg)
8603 null_value= item->null_value;
8604 unsigned_flag= item->unsigned_flag;
8610 DBUG_ASSERT(fixed == 1);
8613 str->set_int(value, unsigned_flag, default_charset());
8620 DBUG_ASSERT(fixed == 1);
8623 int2my_decimal(E_DEC_FATAL_ERROR, value, unsigned_flag, decimal_val);
8627 double Item_cache_int::val_real()
8629 DBUG_ASSERT(fixed == 1);
8632 return (
double) value;
8635 longlong Item_cache_int::val_int()
8637 DBUG_ASSERT(fixed == 1);
8643 bool Item_cache_datetime::cache_value_int()
8650 str_value_cached=
false;
8652 DBUG_ASSERT(field_type() == example->field_type());
8654 null_value= example->null_value;
8655 unsigned_flag= example->unsigned_flag;
8661 bool Item_cache_datetime::cache_value()
8666 if (cmp_context == INT_RESULT)
8667 return cache_value_int();
8669 str_value_cached= TRUE;
8671 value_cached= FALSE;
8673 String *res= example->str_result(&str_value);
8674 if (res && res != &str_value)
8675 str_value.copy(*res);
8676 null_value= example->null_value;
8677 unsigned_flag= example->unsigned_flag;
8682 void Item_cache_datetime::store(
Item *item, longlong val_arg)
8687 null_value= item->null_value;
8688 unsigned_flag= item->unsigned_flag;
8692 void Item_cache_datetime::store(
Item *item)
8694 Item_cache::store(item);
8695 str_value_cached= FALSE;
8700 DBUG_ASSERT(fixed == 1);
8702 if ((value_cached || str_value_cached) && null_value)
8705 if (!str_value_cached)
8718 TIME_from_longlong_packed(<ime, cached_field_type, int_value);
8719 if ((null_value= my_TIME_to_str(<ime, &str_value,
8720 MY_MIN(decimals, DATETIME_MAX_DECIMALS))))
8722 str_value_cached= TRUE;
8724 else if (!cache_value())
8733 DBUG_ASSERT(fixed == 1);
8735 if (str_value_cached)
8737 switch (cached_field_type)
8739 case MYSQL_TYPE_TIME:
8740 return val_decimal_from_time(decimal_val);
8741 case MYSQL_TYPE_DATETIME:
8742 case MYSQL_TYPE_TIMESTAMP:
8743 case MYSQL_TYPE_DATE:
8744 return val_decimal_from_date(decimal_val);
8751 if ((!value_cached && !cache_value_int()) || null_value)
8753 return my_decimal_from_datetime_packed(decimal_val, field_type(), int_value);
8757 bool Item_cache_datetime::get_date(
MYSQL_TIME *ltime, uint fuzzydate)
8759 if ((value_cached || str_value_cached) && null_value)
8762 if (str_value_cached)
8765 if ((!value_cached && !cache_value_int()) || null_value)
8766 return (null_value=
true);
8769 switch (cached_field_type)
8771 case MYSQL_TYPE_TIME:
8774 TIME_from_longlong_time_packed(&tm, int_value);
8775 time_to_datetime(current_thd, &tm, ltime);
8778 case MYSQL_TYPE_DATE:
8781 TIME_from_longlong_date_packed(ltime, int_value);
8782 return check_date(ltime, non_zero_date(ltime), fuzzydate, &warnings);
8784 case MYSQL_TYPE_DATETIME:
8785 case MYSQL_TYPE_TIMESTAMP:
8788 TIME_from_longlong_datetime_packed(ltime, int_value);
8789 return check_date(ltime, non_zero_date(ltime), fuzzydate, &warnings);
8798 bool Item_cache_datetime::get_time(
MYSQL_TIME *ltime)
8800 if ((value_cached || str_value_cached) && null_value)
8803 if (str_value_cached)
8806 if ((!value_cached && !cache_value_int()) || null_value)
8809 switch (cached_field_type)
8811 case MYSQL_TYPE_TIME:
8812 TIME_from_longlong_time_packed(ltime, int_value);
8814 case MYSQL_TYPE_DATE:
8815 set_zero_time(ltime, MYSQL_TIMESTAMP_TIME);
8817 case MYSQL_TYPE_DATETIME:
8818 case MYSQL_TYPE_TIMESTAMP:
8819 TIME_from_longlong_datetime_packed(ltime, int_value);
8820 datetime_to_time(ltime);
8829 double Item_cache_datetime::val_real()
8831 return val_real_from_decimal();
8836 DBUG_ASSERT(fixed == 1);
8837 if ((!value_cached && !cache_value_int()) || null_value)
8839 if (is_temporal_with_date())
8844 TIME_to_longlong_packed(<ime, field_type());
8851 DBUG_ASSERT(fixed == 1);
8852 if ((!value_cached && !cache_value_int()) || null_value)
8854 if (cached_field_type == MYSQL_TYPE_TIME)
8859 TIME_to_longlong_datetime_packed(<ime);
8865 longlong Item_cache_datetime::val_int()
8867 return val_int_from_decimal();
8870 bool Item_cache_real::cache_value()
8875 value= example->val_result();
8876 null_value= example->null_value;
8881 double Item_cache_real::val_real()
8883 DBUG_ASSERT(fixed == 1);
8889 longlong Item_cache_real::val_int()
8891 DBUG_ASSERT(fixed == 1);
8894 return (longlong) rint(value);
8900 DBUG_ASSERT(fixed == 1);
8903 str->set_real(value, decimals, default_charset());
8910 DBUG_ASSERT(fixed == 1);
8913 double2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
8918 bool Item_cache_decimal::cache_value()
8923 my_decimal *val= example->val_decimal_result(&decimal_value);
8924 if (!(null_value= example->null_value) && val != &decimal_value)
8925 my_decimal2decimal(val, &decimal_value);
8929 double Item_cache_decimal::val_real()
8935 my_decimal2double(E_DEC_FATAL_ERROR, &decimal_value, &res);
8939 longlong Item_cache_decimal::val_int()
8945 my_decimal2int(E_DEC_FATAL_ERROR, &decimal_value, unsigned_flag, &res);
8954 my_decimal_round(E_DEC_FATAL_ERROR, &decimal_value, decimals, FALSE,
8956 my_decimal2string(E_DEC_FATAL_ERROR, &decimal_value, 0, 0, 0, str);
8965 return &decimal_value;
8969 bool Item_cache_str::cache_value()
8974 value_buff.set(buffer,
sizeof(buffer), example->collation.collation);
8975 value= example->str_result(&value_buff);
8976 if ((null_value= example->null_value))
8978 else if (value != &value_buff)
8988 value_buff.copy(*value);
8994 double Item_cache_str::val_real()
8996 DBUG_ASSERT(fixed == 1);
9002 return my_strntod(value->charset(), (
char*) value->ptr(),
9003 value->length(), &end_not_used, &err_not_used);
9008 longlong Item_cache_str::val_int()
9010 DBUG_ASSERT(fixed == 1);
9015 return my_strntoll(value->charset(), value->ptr(),
9016 value->length(), 10, (
char**) 0, &err);
9024 DBUG_ASSERT(fixed == 1);
9033 DBUG_ASSERT(fixed == 1);
9037 string2my_decimal(E_DEC_FATAL_ERROR, value, decimal_val);
9044 type_conversion_status
9047 if (!value_cached && !cache_value())
9048 return TYPE_ERR_BAD_VALUE;
9053 if (is_varbinary && field->type() == MYSQL_TYPE_STRING && value != NULL &&
9054 value->length() < field->field_length)
9055 return TYPE_WARN_OUT_OF_RANGE;
9061 bool Item_cache_row::allocate(uint num)
9064 THD *thd= current_thd;
9070 bool Item_cache_row::setup(
Item * item)
9073 if (!values && allocate(item->cols()))
9075 for (uint i= 0; i < item_count; i++)
9077 Item *el= item->element_index(i);
9079 if (!(tmp= values[i]= Item_cache::get_cache(el)))
9087 void Item_cache_row::store(
Item * item)
9095 for (uint i= 0; i < item_count; i++)
9096 values[i]->store(item->element_index(i));
9100 bool Item_cache_row::cache_value()
9106 example->bring_value();
9107 for (uint i= 0; i < item_count; i++)
9109 values[
i]->cache_value();
9110 null_value|= values[
i]->null_value;
9116 void Item_cache_row::illegal_method_call(
const char *method)
9118 DBUG_ENTER(
"Item_cache_row::illegal_method_call");
9119 DBUG_PRINT(
"error", (
"!!! %s method was called for row item", method));
9121 my_error(ER_OPERAND_COLUMNS, MYF(0), 1);
9126 bool Item_cache_row::check_cols(uint c)
9128 if (c != item_count)
9130 my_error(ER_OPERAND_COLUMNS, MYF(0), c);
9137 bool Item_cache_row::null_inside()
9139 for (uint i= 0; i < item_count; i++)
9141 if (values[i]->cols() > 1)
9143 if (values[i]->null_inside())
9148 values[
i]->update_null_value();
9149 if (values[i]->null_value)
9157 void Item_cache_row::bring_value()
9161 example->bring_value();
9162 null_value= example->null_value;
9163 for (uint i= 0; i < item_count; i++)
9164 values[i]->bring_value();
9168 Item_type_holder::Item_type_holder(THD *thd,
Item *item)
9169 :
Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item))
9171 DBUG_ASSERT(item->fixed);
9172 maybe_null= item->maybe_null;
9173 collation.set(item->collation);
9174 get_full_info(item);
9178 prev_decimal_int_part= item->decimal_int_part();
9180 if (item->field_type() == MYSQL_TYPE_GEOMETRY)
9181 geometry_type= item->get_geometry_type();
9208 switch(item->type())
9217 enum_field_types type= field->real_type();
9219 return MYSQL_TYPE_NULL;
9221 if (type == MYSQL_TYPE_STRING && field->type() == MYSQL_TYPE_VAR_STRING)
9222 return MYSQL_TYPE_VAR_STRING;
9232 if (item_sum->keep_field_type())
9237 if (((
Item_func *) item)->functype() == Item_func::GUSERVAR_FUNC)
9245 switch (item->result_type()) {
9247 return MYSQL_TYPE_VAR_STRING;
9249 return MYSQL_TYPE_LONGLONG;
9251 return MYSQL_TYPE_DOUBLE;
9252 case DECIMAL_RESULT:
9253 return MYSQL_TYPE_NEWDECIMAL;
9257 return MYSQL_TYPE_VAR_STRING;
9264 return item->field_type();
9282 uint max_length_orig= max_length;
9283 uint decimals_orig= decimals;
9284 DBUG_ENTER(
"Item_type_holder::join_types");
9285 DBUG_PRINT(
"info:", (
"was type %d len %d, dec %d name %s",
9286 fld_type, max_length, decimals,
9287 (item_name.
is_set() ? item_name.
ptr() :
"<NULL>")));
9288 DBUG_PRINT(
"info:", (
"in type %d len %d, dec %d",
9290 item->max_length, item->decimals));
9293 int item_decimals= item->decimals;
9297 decimals= max<int>(decimals, item_decimals);
9301 decimals= min<int>(max(decimals, item->decimals), DECIMAL_MAX_SCALE);
9302 int item_int_part= item->decimal_int_part();
9303 int item_prec = max(prev_decimal_int_part, item_int_part) + decimals;
9305 unsigned_flag&= item->unsigned_flag;
9306 max_length= my_decimal_precision_to_length_no_truncation(precision,
9315 const char *old_cs, *old_derivation;
9316 uint32 old_max_chars= max_length / collation.collation->mbmaxlen;
9317 old_cs= collation.collation->name;
9318 old_derivation= collation.derivation_name();
9319 if (collation.
aggregate(item->collation, MY_COLL_ALLOW_CONV))
9321 my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0),
9322 old_cs, old_derivation,
9323 item->collation.collation->name,
9324 item->collation.derivation_name(),
9333 if (collation.collation != &my_charset_bin)
9335 max_length= max(old_max_chars * collation.collation->mbmaxlen,
9337 item->collation.collation->mbmaxlen *
9338 collation.collation->mbmaxlen);
9346 if (decimals != NOT_FIXED_DEC)
9352 if (item->max_length != max_length_orig ||
9353 item->decimals != decimals_orig)
9355 int delta1= max_length_orig - decimals_orig;
9356 int delta2= item->max_length - item->decimals;
9357 max_length= max(delta1, delta2) + decimals;
9358 if (fld_type == MYSQL_TYPE_FLOAT && max_length > FLT_DIG + 2)
9360 max_length= MAX_FLOAT_STR_LENGTH;
9361 decimals= NOT_FIXED_DEC;
9363 else if (fld_type == MYSQL_TYPE_DOUBLE && max_length > DBL_DIG + 2)
9365 max_length= MAX_DOUBLE_STR_LENGTH;
9366 decimals= NOT_FIXED_DEC;
9371 max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7;
9377 maybe_null|= item->maybe_null;
9381 prev_decimal_int_part= decimal_int_part();
9382 DBUG_PRINT(
"info", (
"become type: %d len: %u dec: %u",
9383 (
int) fld_type, max_length, (uint) decimals));
9398 if (item->type() == Item::FIELD_ITEM)
9399 return ((
Item_field *)item)->max_disp_length();
9401 switch (item->field_type())
9403 case MYSQL_TYPE_DECIMAL:
9404 case MYSQL_TYPE_TIMESTAMP:
9405 case MYSQL_TYPE_DATE:
9406 case MYSQL_TYPE_TIME:
9407 case MYSQL_TYPE_DATETIME:
9408 case MYSQL_TYPE_YEAR:
9409 case MYSQL_TYPE_NEWDATE:
9410 case MYSQL_TYPE_VARCHAR:
9411 case MYSQL_TYPE_BIT:
9412 case MYSQL_TYPE_NEWDECIMAL:
9413 case MYSQL_TYPE_ENUM:
9414 case MYSQL_TYPE_SET:
9415 case MYSQL_TYPE_TINY_BLOB:
9416 case MYSQL_TYPE_MEDIUM_BLOB:
9417 case MYSQL_TYPE_LONG_BLOB:
9418 case MYSQL_TYPE_BLOB:
9419 case MYSQL_TYPE_VAR_STRING:
9420 case MYSQL_TYPE_STRING:
9421 case MYSQL_TYPE_GEOMETRY:
9422 return item->max_length;
9423 case MYSQL_TYPE_TINY:
9425 case MYSQL_TYPE_SHORT:
9427 case MYSQL_TYPE_LONG:
9428 return MY_INT32_NUM_DECIMAL_DIGITS;
9429 case MYSQL_TYPE_FLOAT:
9431 case MYSQL_TYPE_DOUBLE:
9433 case MYSQL_TYPE_NULL:
9435 case MYSQL_TYPE_LONGLONG:
9437 case MYSQL_TYPE_INT24:
9461 uchar *null_ptr= maybe_null ? (uchar*)
"" : 0;
9465 case MYSQL_TYPE_ENUM:
9466 DBUG_ASSERT(enum_set_typelib);
9467 field=
new Field_enum((uchar *) 0, max_length, null_ptr, 0,
9468 Field::NONE, item_name.
ptr(),
9469 get_enum_pack_length(enum_set_typelib->count),
9470 enum_set_typelib, collation.collation);
9474 case MYSQL_TYPE_SET:
9475 DBUG_ASSERT(enum_set_typelib);
9476 field=
new Field_set((uchar *) 0, max_length, null_ptr, 0,
9477 Field::NONE, item_name.
ptr(),
9478 get_set_pack_length(enum_set_typelib->count),
9479 enum_set_typelib, collation.collation);
9483 case MYSQL_TYPE_NULL:
9500 if (fld_type == MYSQL_TYPE_ENUM ||
9501 fld_type == MYSQL_TYPE_SET)
9503 if (item->type() == Item::SUM_FUNC_ITEM &&
9504 (((
Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC ||
9505 ((
Item_sum*)item)->sum_func() == Item_sum::MIN_FUNC))
9506 item = ((
Item_sum*)item)->get_arg(0);
9511 DBUG_ASSERT((enum_set_typelib &&
9513 (!enum_set_typelib &&
9514 item->type() == Item::FIELD_ITEM &&
9518 if (!enum_set_typelib)
9526 double Item_type_holder::val_real()
9533 longlong Item_type_holder::val_int()
9551 void Item_result_field::cleanup()
9553 DBUG_ENTER(
"Item_result_field::cleanup()");
9566 void dummy_error_processor(THD *thd,
void *data)
9577 void view_error_processor(THD *thd,
void *data)