The world's most popular open source database
#include "mysql_priv.h"#include <m_ctype.h>#include "my_dir.h"#include "sp_rcontext.h"#include "sp_head.h"#include "sql_trigger.h"#include "sql_select.h"Include dependency graph for item.cc:

Go to the source code of this file.
Functions | |
| static void | mark_as_dependent (THD *thd, SELECT_LEX *last, SELECT_LEX *current, Item_ident *item) |
| void | item_init (void) |
| static void | my_coll_agg_error (DTCollation &c1, DTCollation &c2, const char *fname) |
| static void | my_coll_agg_error (DTCollation &c1, DTCollation &c2, DTCollation &c3, const char *fname) |
| static void | my_coll_agg_error (Item **args, uint count, const char *fname, int item_sep) |
| bool | agg_item_collations (DTCollation &c, const char *fname, Item **av, uint count, uint flags, int item_sep) |
| bool | agg_item_collations_for_comparison (DTCollation &c, const char *fname, Item **av, uint count, uint flags) |
| bool | agg_item_charsets (DTCollation &coll, const char *fname, Item **args, uint nargs, uint flags, int item_sep) |
| bool | check_if_only_end_space (CHARSET_INFO *cs, char *str, char *end) |
| static void | default_set_param_func (Item_param *param, uchar **pos __attribute__((unused)), ulong len __attribute__((unused))) |
| static void | mark_as_dependent (THD *thd, SELECT_LEX *last, SELECT_LEX *current, Item_ident *resolved_item, Item_ident *mark_item) |
| void | mark_select_range_as_dependent (THD *thd, SELECT_LEX *last_select, SELECT_LEX *current_sel, Field *found_field, Item *found_item, Item_ident *resolved_item) |
| static Item ** | find_field_in_group_list (Item *find_item, ORDER *group_list) |
| static Item ** | resolve_ref_in_select_and_group (THD *thd, Item_ident *ref, SELECT_LEX *select) |
| static uint | nr_of_decimals (const char *str, const char *end) |
| uint | char_val (char X) |
| Item_result | item_cmp_type (Item_result a, Item_result b) |
| void | resolve_const_item (THD *thd, Item **ref, Item *comp_item) |
| bool | field_is_equal_to_item (Field *field, Item *item) |
| void | dummy_error_processor (THD *thd, void *data) |
| void | view_error_processor (THD *thd, void *data) |
Variables | |
| const String | my_null_string ("NULL", 4, default_charset_info) |
| static const Hybrid_type_traits | real_traits_instance |
| static const Hybrid_type_traits_decimal | decimal_traits_instance |
| static const Hybrid_type_traits_integer | integer_traits_instance |
| bool agg_item_charsets | ( | DTCollation & | coll, | |
| const char * | fname, | |||
| Item ** | args, | |||
| uint | nargs, | |||
| uint | flags, | |||
| int | item_sep | |||
| ) |
Definition at line 1427 of file item.cc.
References agg_item_collations(), args, backup, DTCollation::collation, current_thd, FALSE, Item::FIELD_ITEM, Item_field::fix_fields(), LINT_INIT, my_coll_agg_error(), String::needs_conversion(), NULL, and TRUE.
Referenced by Item_func::agg_arg_charsets(), and Item_func_group_concat::fix_fields().
01429 { 01430 Item **arg, **last, *safe_args[2]; 01431 01432 LINT_INIT(safe_args[0]); 01433 LINT_INIT(safe_args[1]); 01434 01435 if (agg_item_collations(coll, fname, args, nargs, flags, item_sep)) 01436 return TRUE; 01437 01438 /* 01439 For better error reporting: save the first and the second argument. 01440 We need this only if the the number of args is 3 or 2: 01441 - for a longer argument list, "Illegal mix of collations" 01442 doesn't display each argument's characteristics. 01443 - if nargs is 1, then this error cannot happen. 01444 */ 01445 if (nargs >=2 && nargs <= 3) 01446 { 01447 safe_args[0]= args[0]; 01448 safe_args[1]= args[item_sep]; 01449 } 01450 01451 THD *thd= current_thd; 01452 Query_arena *arena, backup; 01453 bool res= FALSE; 01454 uint i; 01455 /* 01456 In case we're in statement prepare, create conversion item 01457 in its memory: it will be reused on each execute. 01458 */ 01459 arena= thd->is_stmt_prepare() ? thd->activate_stmt_arena_if_needed(&backup) 01460 : NULL; 01461 01462 for (i= 0, arg= args; i < nargs; i++, arg+= item_sep) 01463 { 01464 Item* conv; 01465 uint32 dummy_offset; 01466 if (!String::needs_conversion(0, coll.collation, 01467 (*arg)->collation.collation, 01468 &dummy_offset)) 01469 continue; 01470 01471 if (!(conv= (*arg)->safe_charset_converter(coll.collation))) 01472 { 01473 if (nargs >=2 && nargs <= 3) 01474 { 01475 /* restore the original arguments for better error message */ 01476 args[0]= safe_args[0]; 01477 args[item_sep]= safe_args[1]; 01478 } 01479 my_coll_agg_error(args, nargs, fname, item_sep); 01480 res= TRUE; 01481 break; // we cannot return here, we need to restore "arena". 01482 } 01483 if ((*arg)->type() == Item::FIELD_ITEM) 01484 ((Item_field *)(*arg))->no_const_subst= 1; 01485 /* 01486 If in statement prepare, then we create a converter for two 01487 constant items, do it once and then reuse it. 01488 If we're in execution of a prepared statement, arena is NULL, 01489 and the conv was created in runtime memory. This can be 01490 the case only if the argument is a parameter marker ('?'), 01491 because for all true constants the charset converter has already 01492 been created in prepare. In this case register the change for 01493 rollback. 01494 */ 01495 if (arena) 01496 *arg= conv; 01497 else 01498 thd->change_item_tree(arg, conv); 01499 /* 01500 We do not check conv->fixed, because Item_func_conv_charset which can 01501 be return by safe_charset_converter can't be fixed at creation 01502 */ 01503 conv->fix_fields(thd, arg); 01504 } 01505 if (arena) 01506 thd->restore_active_arena(arena, &backup); 01507 return res; 01508 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool agg_item_collations | ( | DTCollation & | c, | |
| const char * | fname, | |||
| Item ** | av, | |||
| uint | count, | |||
| uint | flags, | |||
| int | item_sep | |||
| ) |
Definition at line 1365 of file item.cc.
References DTCollation::aggregate(), DTCollation::derivation, DERIVATION_NONE, FALSE, my_coll_agg_error(), MY_COLL_DISALLOW_NONE, DTCollation::set(), and TRUE.
Referenced by Item_func::agg_arg_collations(), agg_item_charsets(), and agg_item_collations_for_comparison().
01367 { 01368 uint i; 01369 Item **arg; 01370 c.set(av[0]->collation); 01371 for (i= 1, arg= &av[item_sep]; i < count; i++, arg++) 01372 { 01373 if (c.aggregate((*arg)->collation, flags)) 01374 { 01375 my_coll_agg_error(av, count, fname, item_sep); 01376 return TRUE; 01377 } 01378 } 01379 if ((flags & MY_COLL_DISALLOW_NONE) && 01380 c.derivation == DERIVATION_NONE) 01381 { 01382 my_coll_agg_error(av, count, fname, item_sep); 01383 return TRUE; 01384 } 01385 return FALSE; 01386 }
Here is the call graph for this function:

Here is the caller graph for this function:

| bool agg_item_collations_for_comparison | ( | DTCollation & | c, | |
| const char * | fname, | |||
| Item ** | av, | |||
| uint | count, | |||
| uint | flags | |||
| ) |
Definition at line 1389 of file item.cc.
References agg_item_collations(), and MY_COLL_DISALLOW_NONE.
Referenced by Item_func::agg_arg_collations_for_comparison().
01391 { 01392 return (agg_item_collations(c, fname, av, count, 01393 flags | MY_COLL_DISALLOW_NONE, 1)); 01394 }
Here is the call graph for this function:

Here is the caller graph for this function:

| uint char_val | ( | char | X | ) | [inline] |
| bool check_if_only_end_space | ( | CHARSET_INFO * | cs, | |
| char * | str, | |||
| char * | end | |||
| ) | [inline] |
Definition at line 2096 of file item.cc.
References charset_info_st::cset, MY_SEQ_SPACES, and my_charset_handler_st::scan.
Referenced by Item_string::val_int(), and Item_string::val_real().
02097 { 02098 return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end; 02099 }
Here is the caller graph for this function:

| static void default_set_param_func | ( | Item_param * | param, | |
| uchar **pos | __attribute__((unused)), | |||
| ulong len | __attribute__((unused)) | |||
| ) | [static] |
Definition at line 2207 of file item.cc.
References Item_param::set_null().
02210 { 02211 param->set_null(); 02212 }
Here is the call graph for this function:

| void dummy_error_processor | ( | THD * | thd, | |
| void * | data | |||
| ) |
Definition at line 6395 of file item.cc.
Referenced by Name_resolution_context::init().
Here is the caller graph for this function:

Definition at line 5707 of file item.cc.
References DECIMAL_RESULT, INT_RESULT, item_cmp_type(), MAX_FIELD_WIDTH, my_charset_bin, my_decimal_cmp(), Item::null_value, Field::result_type(), Item::result_type(), STRING_RESULT, stringcmp(), Item::val_decimal(), Field::val_decimal(), Item::val_real(), Field::val_real(), Item::val_str(), and Field::val_str().
Referenced by get_mm_leaf().
05708 { 05709 05710 Item_result res_type=item_cmp_type(field->result_type(), 05711 item->result_type()); 05712 if (res_type == STRING_RESULT) 05713 { 05714 char item_buff[MAX_FIELD_WIDTH]; 05715 char field_buff[MAX_FIELD_WIDTH]; 05716 String item_tmp(item_buff,sizeof(item_buff),&my_charset_bin),*item_result; 05717 String field_tmp(field_buff,sizeof(field_buff),&my_charset_bin); 05718 item_result=item->val_str(&item_tmp); 05719 if (item->null_value) 05720 return 1; // This must be true 05721 field->val_str(&field_tmp); 05722 return !stringcmp(&field_tmp,item_result); 05723 } 05724 if (res_type == INT_RESULT) 05725 return 1; // Both where of type int 05726 if (res_type == DECIMAL_RESULT) 05727 { 05728 my_decimal item_buf, *item_val, 05729 field_buf, *field_val; 05730 item_val= item->val_decimal(&item_buf); 05731 if (item->null_value) 05732 return 1; // This must be true 05733 field_val= field->val_decimal(&field_buf); 05734 return !my_decimal_cmp(item_val, field_val); 05735 } 05736 double result= item->val_real(); 05737 if (item->null_value) 05738 return 1; 05739 return result == field->val_real(); 05740 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 3107 of file item.cc.
References current_thd, Item_ident::db_name, DBUG_ASSERT, ER_NON_UNIQ_ERROR, Item::FIELD_ITEM, Item_ident::field_name, files_charset_info, Item::full_name(), st_order::item, lower_case_table_names, my_casedn_str, my_error(), my_strcasecmp, MYF, NAME_LEN, st_order::next, NULL, Item::REF_ITEM, strcmp(), strmake(), system_charset_info, Item_ident::table_name, and Item::type().
Referenced by resolve_ref_in_select_and_group().
03108 { 03109 const char *db_name; 03110 const char *table_name; 03111 const char *field_name; 03112 ORDER *found_group= NULL; 03113 int found_match_degree= 0; 03114 Item_ident *cur_field; 03115 int cur_match_degree= 0; 03116 char name_buff[NAME_LEN+1]; 03117 03118 if (find_item->type() == Item::FIELD_ITEM || 03119 find_item->type() == Item::REF_ITEM) 03120 { 03121 db_name= ((Item_ident*) find_item)->db_name; 03122 table_name= ((Item_ident*) find_item)->table_name; 03123 field_name= ((Item_ident*) find_item)->field_name; 03124 } 03125 else 03126 return NULL; 03127 03128 if (db_name && lower_case_table_names) 03129 { 03130 /* Convert database to lower case for comparison */ 03131 strmake(name_buff, db_name, sizeof(name_buff)-1); 03132 my_casedn_str(files_charset_info, name_buff); 03133 db_name= name_buff; 03134 } 03135 03136 DBUG_ASSERT(field_name != 0); 03137 03138 for (ORDER *cur_group= group_list ; cur_group ; cur_group= cur_group->next) 03139 { 03140 if ((*(cur_group->item))->real_item()->type() == Item::FIELD_ITEM) 03141 { 03142 cur_field= (Item_ident*) *cur_group->item; 03143 cur_match_degree= 0; 03144 03145 DBUG_ASSERT(cur_field->field_name != 0); 03146 03147 if (!my_strcasecmp(system_charset_info, 03148 cur_field->field_name, field_name)) 03149 ++cur_match_degree; 03150 else 03151 continue; 03152 03153 if (cur_field->table_name && table_name) 03154 { 03155 /* If field_name is qualified by a table name. */ 03156 if (strcmp(cur_field->table_name, table_name)) 03157 /* Same field names, different tables. */ 03158 return NULL; 03159 03160 ++cur_match_degree; 03161 if (cur_field->db_name && db_name) 03162 { 03163 /* If field_name is also qualified by a database name. */ 03164 if (strcmp(cur_field->db_name, db_name)) 03165 /* Same field names, different databases. */ 03166 return NULL; 03167 ++cur_match_degree; 03168 } 03169 } 03170 03171 if (cur_match_degree > found_match_degree) 03172 { 03173 found_match_degree= cur_match_degree; 03174 found_group= cur_group; 03175 } 03176 else if (found_group && (cur_match_degree == found_match_degree) && 03177 ! (*(found_group->item))->eq(cur_field, 0)) 03178 { 03179 /* 03180 If the current resolve candidate matches equally well as the current 03181 best match, they must reference the same column, otherwise the field 03182 is ambiguous. 03183 */ 03184 my_error(ER_NON_UNIQ_ERROR, MYF(0), 03185 find_item->full_name(), current_thd->where); 03186 return NULL; 03187 } 03188 } 03189 } 03190 03191 if (found_group) 03192 return found_group->item; 03193 else 03194 return NULL; 03195 }
Here is the call graph for this function:

Here is the caller graph for this function:

| Item_result item_cmp_type | ( | Item_result | a, | |
| Item_result | b | |||
| ) |
Definition at line 5595 of file item.cc.
References DECIMAL_RESULT, INT_RESULT, REAL_RESULT, ROW_RESULT, and STRING_RESULT.
Referenced by agg_cmp_type(), field_is_equal_to_item(), Item_func_field::fix_length_and_dec(), Item_func_min_max::fix_length_and_dec(), resolve_const_item(), Arg_comparator::set_cmp_func(), and Arg_comparator::set_compare_func().
05596 { 05597 if (a == STRING_RESULT && b == STRING_RESULT) 05598 return STRING_RESULT; 05599 if (a == INT_RESULT && b == INT_RESULT) 05600 return INT_RESULT; 05601 else if (a == ROW_RESULT || b == ROW_RESULT) 05602 return ROW_RESULT; 05603 if ((a == INT_RESULT || a == DECIMAL_RESULT) && 05604 (b == INT_RESULT || b == DECIMAL_RESULT)) 05605 return DECIMAL_RESULT; 05606 return REAL_RESULT; 05607 }
Here is the caller graph for this function:

| void item_init | ( | void | ) |
Definition at line 166 of file item.cc.
References item_user_lock_init().
Referenced by init_common_variables().
00167 { 00168 item_user_lock_init(); 00169 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void mark_as_dependent | ( | THD * | thd, | |
| SELECT_LEX * | last, | |||
| SELECT_LEX * | current, | |||
| Item_ident * | resolved_item, | |||
| Item_ident * | mark_item | |||
| ) | [static] |
Definition at line 2997 of file item.cc.
References Item_ident::db_name, Item_ident::depended_from, DESCRIBE_EXTENDED, ER, ER_WARN_FIELD_RESOLVED, Item_ident::field_name, MYSQL_ERRMSG_SIZE, push_warning(), Item_ident::table_name, and MYSQL_ERROR::WARN_LEVEL_NOTE.
03000 { 03001 const char *db_name= (resolved_item->db_name ? 03002 resolved_item->db_name : ""); 03003 const char *table_name= (resolved_item->table_name ? 03004 resolved_item->table_name : ""); 03005 /* store pointer on SELECT_LEX from which item is dependent */ 03006 if (mark_item) 03007 mark_item->depended_from= last; 03008 current->mark_as_dependent(last); 03009 if (thd->lex->describe & DESCRIBE_EXTENDED) 03010 { 03011 char warn_buff[MYSQL_ERRMSG_SIZE]; 03012 sprintf(warn_buff, ER(ER_WARN_FIELD_RESOLVED), 03013 db_name, (db_name[0] ? "." : ""), 03014 table_name, (table_name [0] ? "." : ""), 03015 resolved_item->field_name, 03016 current->select_number, last->select_number); 03017 push_warning(thd, MYSQL_ERROR::WARN_LEVEL_NOTE, 03018 ER_WARN_FIELD_RESOLVED, warn_buff); 03019 } 03020 }
Here is the call graph for this function:

| static void mark_as_dependent | ( | THD * | thd, | |
| SELECT_LEX * | last, | |||
| SELECT_LEX * | current, | |||
| Item_ident * | item | |||
| ) | [static] |
Referenced by Item_ref::fix_fields(), Item_field::fix_outer_field(), and mark_select_range_as_dependent().
Here is the caller graph for this function:

| void mark_select_range_as_dependent | ( | THD * | thd, | |
| SELECT_LEX * | last_select, | |||
| SELECT_LEX * | current_sel, | |||
| Field * | found_field, | |||
| Item * | found_item, | |||
| Item_ident * | resolved_item | |||
| ) |
Definition at line 3045 of file item.cc.
References Item_subselect::const_item_cache, Item::FIELD_ITEM, st_table::map, mark_as_dependent(), OUTER_REF_TABLE_BIT, Item::REF_ITEM, Field::table, Item::type(), Item::used_tables(), Item_subselect::used_tables_cache, and view_ref_found.
Referenced by find_field_in_tables().
03050 { 03051 /* 03052 Go from current SELECT to SELECT where field was resolved (it 03053 have to be reachable from current SELECT, because it was already 03054 done once when we resolved this field and cached result of 03055 resolving) 03056 */ 03057 SELECT_LEX *previous_select= current_sel; 03058 for (; previous_select->outer_select() != last_select; 03059 previous_select= previous_select->outer_select()) 03060 { 03061 Item_subselect *prev_subselect_item= 03062 previous_select->master_unit()->item; 03063 prev_subselect_item->used_tables_cache|= OUTER_REF_TABLE_BIT; 03064 prev_subselect_item->const_item_cache= 0; 03065 } 03066 { 03067 Item_subselect *prev_subselect_item= 03068 previous_select->master_unit()->item; 03069 Item_ident *dependent= resolved_item; 03070 if (found_field == view_ref_found) 03071 { 03072 Item::Type type= found_item->type(); 03073 prev_subselect_item->used_tables_cache|= 03074 found_item->used_tables(); 03075 dependent= ((type == Item::REF_ITEM || type == Item::FIELD_ITEM) ? 03076 (Item_ident*) found_item : 03077 0); 03078 } 03079 else 03080 prev_subselect_item->used_tables_cache|= 03081 found_field->table->map; 03082 prev_subselect_item->const_item_cache= 0; 03083 mark_as_dependent(thd, last_select, current_sel, resolved_item, 03084 dependent); 03085 } 03086 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static void my_coll_agg_error | ( | Item ** | args, | |
| uint | count, | |||
| const char * | fname, | |||
| int | item_sep | |||
| ) | [static] |
Definition at line 1352 of file item.cc.
References args, ER_CANT_AGGREGATE_NCOLLATIONS, my_coll_agg_error(), my_error(), and MYF.
01354 { 01355 if (count == 2) 01356 my_coll_agg_error(args[0]->collation, args[item_sep]->collation, fname); 01357 else if (count == 3) 01358 my_coll_agg_error(args[0]->collation, args[item_sep]->collation, 01359 args[2*item_sep]->collation, fname); 01360 else 01361 my_error(ER_CANT_AGGREGATE_NCOLLATIONS,MYF(0),fname); 01362 }
Here is the call graph for this function:

| static void my_coll_agg_error | ( | DTCollation & | c1, | |
| DTCollation & | c2, | |||
| DTCollation & | c3, | |||
| const char * | fname | |||
| ) | [static] |
Definition at line 1340 of file item.cc.
References DTCollation::collation, DTCollation::derivation_name(), ER_CANT_AGGREGATE_3COLLATIONS, my_error(), MYF, and charset_info_st::name.
01342 { 01343 my_error(ER_CANT_AGGREGATE_3COLLATIONS,MYF(0), 01344 c1.collation->name,c1.derivation_name(), 01345 c2.collation->name,c2.derivation_name(), 01346 c3.collation->name,c3.derivation_name(), 01347 fname); 01348 }
Here is the call graph for this function:

| static void my_coll_agg_error | ( | DTCollation & | c1, | |
| DTCollation & | c2, | |||
| const char * | fname | |||
| ) | [static] |
Definition at line 1330 of file item.cc.
References DTCollation::collation, DTCollation::derivation_name(), ER_CANT_AGGREGATE_2COLLATIONS, my_error(), MYF, and charset_info_st::name.
Referenced by agg_item_charsets(), agg_item_collations(), my_coll_agg_error(), and Arg_comparator::set_compare_func().
01331 { 01332 my_error(ER_CANT_AGGREGATE_2COLLATIONS,MYF(0), 01333 c1.collation->name,c1.derivation_name(), 01334 c2.collation->name,c2.derivation_name(), 01335 fname); 01336 }
Here is the call graph for this function:

Here is the caller graph for this function:

| static uint nr_of_decimals | ( | const char * | str, | |
| const char * | end | |||
| ) | [static] |
Definition at line 4299 of file item.cc.
References my_isdigit, NOT_FIXED_DEC, and system_charset_info.
Referenced by Item_float::Item_float().
04300 { 04301 const char *decimal_point; 04302 04303 /* Find position for '.' */ 04304 for (;;) 04305 { 04306 if (str == end) 04307 return 0; 04308 if (*str == 'e' || *str == 'E') 04309 return NOT_FIXED_DEC; 04310 if (*str++ == '.') 04311 break; 04312 } 04313 decimal_point= str; 04314 for (; my_isdigit(system_charset_info, *str) ; str++) 04315 ; 04316 if (*str == 'e' || *str == 'E') 04317 return NOT_FIXED_DEC; 04318 return (uint) (str - decimal_point); 04319 }
Here is the caller graph for this function:

Definition at line 5610 of file item.cc.
References Item::basic_const_item(), String::charset(), Item_row::cols(), DBUG_ASSERT, DECIMAL_RESULT, Item::decimals, Item_row::el(),

