#include <item.h>
Inheritance diagram for Item_type_holder:


Public Member Functions | |
| Item_type_holder (THD *, Item *) | |
| Item_result | result_type () const |
| enum_field_types | field_type () const |
| enum Type | type () const |
| double | val_real () |
| longlong | val_int () |
| my_decimal * | val_decimal (my_decimal *) |
| String * | val_str (String *) |
| bool | join_types (THD *thd, Item *) |
| Field * | make_field_by_type (TABLE *table) |
Static Public Member Functions | |
| static uint32 | display_length (Item *item) |
| static enum_field_types | get_real_type (Item *) |
Protected Member Functions | |
| void | get_full_info (Item *item) |
Protected Attributes | |
| TYPELIB * | enum_set_typelib |
| enum_field_types | fld_type |
| int | prev_decimal_int_part |
Definition at line 2519 of file item.h.
| Item_type_holder::Item_type_holder | ( | THD * | , | |
| Item * | ||||
| ) |
Definition at line 6009 of file item.cc.
References Item::collation, DBUG_ASSERT, Item::decimal_int_part(), Item::decimals, display_length(), Item::fixed, fld_type, get_full_info(), INT_RESULT, Item::max_length, Item::maybe_null, prev_decimal_int_part, Field::result_merge_type(), and DTCollation::set().
06010 :Item(thd, item), enum_set_typelib(0), fld_type(get_real_type(item)) 06011 { 06012 DBUG_ASSERT(item->fixed); 06013 06014 max_length= display_length(item); 06015 maybe_null= item->maybe_null; 06016 collation.set(item->collation); 06017 get_full_info(item); 06018 /* fix variable decimals which always is NOT_FIXED_DEC */ 06019 if (Field::result_merge_type(fld_type) == INT_RESULT) 06020 decimals= 0; 06021 prev_decimal_int_part= item->decimal_int_part(); 06022 }
Here is the call graph for this function:

Definition at line 6220 of file item.cc.
References DBUG_ASSERT, Item::FIELD_ITEM, MYSQL_TYPE_BIT, MYSQL_TYPE_BLOB, MYSQL_TYPE_DATE, MYSQL_TYPE_DATETIME, MYSQL_TYPE_DECIMAL, MYSQL_TYPE_DOUBLE, MYSQL_TYPE_ENUM, MYSQL_TYPE_FLOAT, MYSQL_TYPE_GEOMETRY, MYSQL_TYPE_INT24, MYSQL_TYPE_LONG, MYSQL_TYPE_LONG_BLOB, MYSQL_TYPE_LONGLONG, MYSQL_TYPE_MEDIUM_BLOB, MYSQL_TYPE_NEWDATE, MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_NULL, MYSQL_TYPE_SET, MYSQL_TYPE_SHORT, MYSQL_TYPE_STRING, MYSQL_TYPE_TIME, MYSQL_TYPE_TIMESTAMP, MYSQL_TYPE_TINY, MYSQL_TYPE_TINY_BLOB, MYSQL_TYPE_VAR_STRING, MYSQL_TYPE_VARCHAR, MYSQL_TYPE_YEAR, and Item::type().
Referenced by Item_type_holder(), and join_types().
06221 { 06222 if (item->type() == Item::FIELD_ITEM) 06223 return ((Item_field *)item)->max_disp_length(); 06224 06225 switch (item->field_type()) 06226 { 06227 case MYSQL_TYPE_DECIMAL: 06228 case MYSQL_TYPE_TIMESTAMP: 06229 case MYSQL_TYPE_DATE: 06230 case MYSQL_TYPE_TIME: 06231 case MYSQL_TYPE_DATETIME: 06232 case MYSQL_TYPE_YEAR: 06233 case MYSQL_TYPE_NEWDATE: 06234 case MYSQL_TYPE_VARCHAR: 06235 case MYSQL_TYPE_BIT: 06236 case MYSQL_TYPE_NEWDECIMAL: 06237 case MYSQL_TYPE_ENUM: 06238 case MYSQL_TYPE_SET: 06239 case MYSQL_TYPE_TINY_BLOB: 06240 case MYSQL_TYPE_MEDIUM_BLOB: 06241 case MYSQL_TYPE_LONG_BLOB: 06242 case MYSQL_TYPE_BLOB: 06243 case MYSQL_TYPE_VAR_STRING: 06244 case MYSQL_TYPE_STRING: 06245 case MYSQL_TYPE_GEOMETRY: 06246 return item->max_length; 06247 case MYSQL_TYPE_TINY: 06248 return 4; 06249 case MYSQL_TYPE_SHORT: 06250 return 6; 06251 case MYSQL_TYPE_LONG: 06252 return 11; 06253 case MYSQL_TYPE_FLOAT: 06254 return 25; 06255 case MYSQL_TYPE_DOUBLE: 06256 return 53; 06257 case MYSQL_TYPE_NULL: 06258 return 0; 06259 case MYSQL_TYPE_LONGLONG: 06260 return 20; 06261 case MYSQL_TYPE_INT24: 06262 return 8; 06263 default: 06264 DBUG_ASSERT(0); // we should never go there 06265 return 0; 06266 } 06267 }
Here is the call graph for this function:

Here is the caller graph for this function:

| enum_field_types Item_type_holder::field_type | ( | ) | const [inline, virtual] |
| void Item_type_holder::get_full_info | ( | Item * | item | ) | [protected] |
Definition at line 6324 of file item.cc.
References DBUG_ASSERT, enum_set_typelib, Item::FIELD_ITEM, fld_type, get_real_type(), Item_sum::MAX_FUNC, Item_sum::MIN_FUNC, MYSQL_TYPE_ENUM, MYSQL_TYPE_NULL, MYSQL_TYPE_SET, Item::SUM_FUNC_ITEM, Item::type(), and typelib().
Referenced by Item_type_holder(), and join_types().
06325 { 06326 if (fld_type == MYSQL_TYPE_ENUM || 06327 fld_type == MYSQL_TYPE_SET) 06328 { 06329 if (item->type() == Item::SUM_FUNC_ITEM && 06330 (((Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC || 06331 ((Item_sum*)item)->sum_func() == Item_sum::MIN_FUNC)) 06332 item = ((Item_sum*)item)->args[0]; 06333 /* 06334 We can have enum/set type after merging only if we have one enum|set 06335 field (or MIN|MAX(enum|set field)) and number of NULL fields 06336 */ 06337 DBUG_ASSERT((enum_set_typelib && 06338 get_real_type(item) == MYSQL_TYPE_NULL) || 06339 (!enum_set_typelib && 06340 item->type() == Item::FIELD_ITEM && 06341 (get_real_type(item) == MYSQL_TYPE_ENUM || 06342 get_real_type(item) == MYSQL_TYPE_SET) && 06343 ((Field_enum*)((Item_field *) item)->field)->typelib)); 06344 if (!enum_set_typelib) 06345 { 06346 enum_set_typelib= ((Field_enum*)((Item_field *) item)->field)->typelib; 06347 } 06348 } 06349 }
Here is the call graph for this function:

Here is the caller graph for this function:

| enum_field_types Item_type_holder::get_real_type | ( | Item * | ) | [static] |
Definition at line 6051 of file item.cc.
References Item_sum::args, DBUG_ASSERT, DECIMAL_RESULT, Item::FIELD_ITEM, Item::field_type(), Item::FUNC_ITEM, Item_func::GUSERVAR_FUNC, INT_RESULT, Item_sum::keep_field_type(), MYSQL_TYPE_DOUBLE, MYSQL_TYPE_LONGLONG, MYSQL_TYPE_NEWDECIMAL, MYSQL_TYPE_STRING, MYSQL_TYPE_VAR_STRING, REAL_RESULT, Item::result_type(), ROW_RESULT, STRING_RESULT, Item::SUM_FUNC_ITEM, type(), and Item::type().
Referenced by get_full_info(), and join_types().
06052 { 06053 switch(item->type()) 06054 { 06055 case FIELD_ITEM: 06056 { 06057 /* 06058 Item_fields::field_type ask Field_type() but sometimes field return 06059 a different type, like for enum/set, so we need to ask real type. 06060 */ 06061 Field *field= ((Item_field *) item)->field; 06062 enum_field_types type= field->real_type(); 06063 /* work around about varchar type field detection */ 06064 if (type == MYSQL_TYPE_STRING && field->type() == MYSQL_TYPE_VAR_STRING) 06065 return MYSQL_TYPE_VAR_STRING; 06066 return type; 06067 } 06068 case SUM_FUNC_ITEM: 06069 { 06070 /* 06071 Argument of aggregate function sometimes should be asked about field 06072 type 06073 */ 06074 Item_sum *item_sum= (Item_sum *) item; 06075 if (item_sum->keep_field_type()) 06076 return get_real_type(item_sum->args[0]); 06077 break; 06078 } 06079 case FUNC_ITEM: 06080 if (((Item_func *) item)->functype() == Item_func::GUSERVAR_FUNC) 06081 { 06082 /* 06083 There are work around of problem with changing variable type on the 06084 fly and variable always report "string" as field type to get 06085 acceptable information for client in send_field, so we make field 06086 type from expression type. 06087 */ 06088 switch (item->result_type()) { 06089 case STRING_RESULT: 06090 return MYSQL_TYPE_VAR_STRING; 06091 case INT_RESULT: 06092 return MYSQL_TYPE_LONGLONG; 06093 case REAL_RESULT: 06094 return MYSQL_TYPE_DOUBLE; 06095 case DECIMAL_RESULT: 06096 return MYSQL_TYPE_NEWDECIMAL; 06097 case ROW_RESULT: 06098 default: 06099 DBUG_ASSERT(0); 06100 return MYSQL_TYPE_VAR_STRING; 06101 } 06102 } 06103 break; 06104 default: 06105 break; 06106 } 06107 return item->field_type(); 06108 }
Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 6124 of file item.cc.
References DTCollation::aggregate(), DTCollation::collation, Item::collation, DBUG_ENTER, DBUG_PRINT, DBUG_RETURN, Item::decimal_int_part(), DECIMAL_MAX_PRECISION, DECIMAL_MAX_SCALE, DECIMAL_RESULT, Item::decimals, DTCollation::derivation_name(), display_length(), ER_CANT_AGGREGATE_2COLLATIONS, FALSE, Field::field_type_merge(), fld_type, get_full_info(), get_real_type(), INT_RESULT, max, Item::max_length, Item::maybe_null, charset_info_st::mbmaxlen, min, MY_COLL_ALLOW_CONV, my_decimal_precision_to_length(), my_error(), MYF, MYSQL_TYPE_DECIMAL, MYSQL_TYPE_FLOAT, charset_info_st::name, Item::name, NOT_FIXED_DEC, prev_decimal_int_part, REAL_RESULT, Field::result_merge_type(), STRING_RESULT, TRUE, and Item::unsigned_flag.
06125 { 06126 uint max_length_orig= max_length; 06127 uint decimals_orig= decimals; 06128 DBUG_ENTER("Item_type_holder::join_types"); 06129 DBUG_PRINT("info:", ("was type %d len %d, dec %d name %s", 06130 fld_type, max_length, decimals, 06131 (name ? name : "<NULL>"))); 06132 DBUG_PRINT("info:", ("in type %d len %d, dec %d", 06133 get_real_type(item), 06134 item->max_length, item->decimals)); 06135 fld_type= Field::field_type_merge(fld_type, get_real_type(item)); 06136 { 06137 int item_decimals= item->decimals; 06138 /* fix variable decimals which always is NOT_FIXED_DEC */ 06139 if (Field::result_merge_type(fld_type) == INT_RESULT) 06140 item_decimals= 0; 06141 decimals= max(decimals, item_decimals); 06142 } 06143 if (Field::result_merge_type(fld_type) == DECIMAL_RESULT) 06144 { 06145 decimals= min(max(decimals, item->decimals), DECIMAL_MAX_SCALE); 06146 int precision= min(max(prev_decimal_int_part, item->decimal_int_part()) 06147 + decimals, DECIMAL_MAX_PRECISION); 06148 unsigned_flag&= item->unsigned_flag; 06149 max_length= my_decimal_precision_to_length(precision, decimals, 06150 unsigned_flag); 06151 } 06152 06153 switch (Field::result_merge_type(fld_type)) 06154 { 06155 case STRING_RESULT: 06156 { 06157 const char *old_cs, *old_derivation; 06158 uint32 old_max_chars= max_length / collation.collation->mbmaxlen; 06159 old_cs= collation.collation->name; 06160 old_derivation= collation.derivation_name(); 06161 if (collation.aggregate(item->collation, MY_COLL_ALLOW_CONV)) 06162 { 06163 my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0), 06164 old_cs, old_derivation, 06165 item->collation.collation->name, 06166 item->collation.derivation_name(), 06167 "UNION"); 06168 DBUG_RETURN(TRUE); 06169 } 06170 /* 06171 To figure out max_length, we have to take into account possible 06172 expansion of the size of the values because of character set 06173 conversions. 06174 */ 06175 max_length= max(old_max_chars * collation.collation->mbmaxlen, 06176 display_length(item) / item->collation.collation->mbmaxlen * 06177 collation.collation->mbmaxlen); 06178 break; 06179 } 06180 case REAL_RESULT: 06181 { 06182 if (decimals != NOT_FIXED_DEC) 06183 { 06184 int delta1= max_length_orig - decimals_orig; 06185 int delta2= item->max_length - item->decimals; 06186 if (fld_type == MYSQL_TYPE_DECIMAL) 06187 max_length= max(delta1, delta2) + decimals; 06188 else 06189 max_length= min(max(delta1, delta2) + decimals, 06190 (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7); 06191 } 06192 else 06193 max_length= (fld_type == MYSQL_TYPE_FLOAT) ? FLT_DIG+6 : DBL_DIG+7; 06194 break; 06195 } 06196 default: 06197 max_length= max(max_length, display_length(item)); 06198 }; 06199 maybe_null|= item->maybe_null; 06200 get_full_info(item); 06201 06202 /* Remember decimal integer part to be used in DECIMAL_RESULT handleng */ 06203 prev_decimal_int_part= decimal_int_part(); 06204 DBUG_PRINT("info", ("become type: %d len: %u dec: %u", 06205 (int) fld_type, max_length, (uint) decimals)); 06206 DBUG_RETURN(FALSE); 06207 }
Here is the call graph for this function:

Definition at line 6282 of file item.cc.
References DTCollation::collation, Item::collation, DBUG_ASSERT, enum_set_typelib, fld_type, get_enum_pack_length(), get_set_pack_length(), Item::max_length, Item::maybe_null, MYSQL_TYPE_ENUM, MYSQL_TYPE_SET, Item::name, Field::NONE, and Item::tmp_table_field_from_field_type().
06283 { 06284 /* 06285 The field functions defines a field to be not null if null_ptr is not 0 06286 */ 06287 uchar *null_ptr= maybe_null ? (uchar*) "" : 0; 06288 Field *field; 06289 06290 switch (fld_type) { 06291 case MYSQL_TYPE_ENUM: 06292 DBUG_ASSERT(enum_set_typelib); 06293 field= new Field_enum((char *) 0, max_length, null_ptr, 0, 06294 Field::NONE, name, 06295 get_enum_pack_length(enum_set_typelib->count), 06296 enum_set_typelib, collation.collation); 06297 if (field) 06298 field->init(table); 06299 return field; 06300 case MYSQL_TYPE_SET: 06301 DBUG_ASSERT(enum_set_typelib); 06302 field= new Field_set((char *) 0, max_length, null_ptr, 0, 06303 Field::NONE, name, 06304 get_set_pack_length(enum_set_typelib->count), 06305 enum_set_typelib, collation.collation); 06306 if (field) 06307 field->init(table); 06308 return field; 06309 default: 06310 break; 06311 } 06312 return tmp_table_field_from_field_type(table, 0); 06313 }
Here is the call graph for this function:

| Item_result Item_type_holder::result_type | ( | ) | const [virtual] |
Reimplemented from Item.
Definition at line 6035 of file item.cc.
References fld_type, and Field::result_merge_type().
06036 { 06037 return Field::result_merge_type(fld_type); 06038 }
Here is the call graph for this function:

| enum Type Item_type_holder::type | ( | ) | const [inline, virtual] |
Implements Item.
Definition at line 2534 of file item.h.
References Item::TYPE_HOLDER.
Referenced by get_real_type().
02534 { return TYPE_HOLDER; }
Here is the caller graph for this function:

| my_decimal * Item_type_holder::val_decimal | ( | my_decimal * | ) | [virtual] |
Implements Item.
Definition at line 6365 of file item.cc.
References DBUG_ASSERT.
06366 { 06367 DBUG_ASSERT(0); // should never be called 06368 return 0; 06369 }
| longlong Item_type_holder::val_int | ( | ) | [virtual] |
Implements Item.
Definition at line 6359 of file item.cc.
References DBUG_ASSERT.
06360 { 06361 DBUG_ASSERT(0); // should never be called 06362 return 0; 06363 }
| double Item_type_holder::val_real | ( | ) | [virtual] |
Implements Item.
Definition at line 6352 of file item.cc.
References DBUG_ASSERT.
06353 { 06354 DBUG_ASSERT(0); // should never be called 06355 return 0.0; 06356 }
Implements Item.
Definition at line 6371 of file item.cc.
References DBUG_ASSERT.
06372 { 06373 DBUG_ASSERT(0); // should never be called 06374 return 0; 06375 }
TYPELIB* Item_type_holder::enum_set_typelib [protected] |
enum_field_types Item_type_holder::fld_type [protected] |
Definition at line 2523 of file item.h.
Referenced by field_type(), get_full_info(), Item_type_holder(), join_types(), make_field_by_type(), and result_type().
int Item_type_holder::prev_decimal_int_part [protected] |
1.4.7

