26 #include <drizzled/error.h>
27 #include <drizzled/function/func.h>
28 #include <drizzled/item/sum.h>
29 #include <drizzled/item/type_holder.h>
30 #include <drizzled/field/enum.h>
36 Item_type_holder::Item_type_holder(Session *session, Item *item)
37 :Item(session, item), enum_set_typelib(0), fld_type(get_real_type(item))
41 collation.set(item->collation);
46 prev_decimal_int_part= item->decimal_int_part();
67 enum_field_types type= field->real_type();
69 return DRIZZLE_TYPE_NULL;
79 if (item_sum->keep_field_type())
80 return get_real_type(item_sum->args[0]);
84 if (((
Item_func *) item)->functype() == Item_func::GUSERVAR_FUNC)
92 switch (item->result_type()) {
94 return DRIZZLE_TYPE_VARCHAR;
96 return DRIZZLE_TYPE_LONGLONG;
98 return DRIZZLE_TYPE_DOUBLE;
100 return DRIZZLE_TYPE_DECIMAL;
103 return DRIZZLE_TYPE_VARCHAR;
110 return item->field_type();
116 uint32_t max_length_orig= max_length;
117 uint32_t decimals_orig= decimals;
120 int item_decimals= item->decimals;
124 decimals= max((
int)decimals, item_decimals);
128 decimals= min((
int)max(decimals, item->decimals), DECIMAL_MAX_SCALE);
129 int precision= min(max(prev_decimal_int_part, item->decimal_int_part())
130 + decimals, DECIMAL_MAX_PRECISION);
131 unsigned_flag&= item->unsigned_flag;
132 max_length= class_decimal_precision_to_length(precision, decimals,
140 const char *old_cs, *old_derivation;
141 uint32_t old_max_chars= max_length / collation.collation->mbmaxlen;
142 old_cs= collation.collation->name;
143 old_derivation= collation.derivation_name();
144 if (collation.aggregate(item->collation, MY_COLL_ALLOW_CONV))
146 my_error(ER_CANT_AGGREGATE_2COLLATIONS, MYF(0),
147 old_cs, old_derivation,
148 item->collation.collation->name,
149 item->collation.derivation_name(),
158 if (collation.collation != &my_charset_bin)
160 max_length= max(old_max_chars * collation.collation->mbmaxlen,
161 display_length(item) /
162 item->collation.collation->mbmaxlen *
163 collation.collation->mbmaxlen);
166 set_if_bigger(max_length, display_length(item));
171 if (decimals != NOT_FIXED_DEC)
173 int delta1= max_length_orig - decimals_orig;
174 int delta2= item->max_length - item->decimals;
175 max_length= max(delta1, delta2) + decimals;
176 if (fld_type == DRIZZLE_TYPE_DOUBLE && max_length > DBL_DIG + 2)
178 max_length= DBL_DIG + 7;
179 decimals= NOT_FIXED_DEC;
183 max_length= DBL_DIG+7;
190 max_length= max(max_length, display_length(item));
196 prev_decimal_int_part= decimal_int_part();
204 if (item->type() == Item::FIELD_ITEM)
205 return ((
Item_field *)item)->max_disp_length();
207 switch (item->field_type())
209 case DRIZZLE_TYPE_TIME:
210 case DRIZZLE_TYPE_BOOLEAN:
211 case DRIZZLE_TYPE_UUID:
212 case DRIZZLE_TYPE_IPV6:
213 case DRIZZLE_TYPE_MICROTIME:
214 case DRIZZLE_TYPE_TIMESTAMP:
215 case DRIZZLE_TYPE_DATETIME:
216 case DRIZZLE_TYPE_DATE:
217 case DRIZZLE_TYPE_VARCHAR:
218 case DRIZZLE_TYPE_DECIMAL:
219 case DRIZZLE_TYPE_ENUM:
220 case DRIZZLE_TYPE_BLOB:
221 return item->max_length;
222 case DRIZZLE_TYPE_LONG:
223 return MY_INT32_NUM_DECIMAL_DIGITS;
224 case DRIZZLE_TYPE_DOUBLE:
226 case DRIZZLE_TYPE_NULL:
228 case DRIZZLE_TYPE_LONGLONG:
241 unsigned char *null_ptr= maybe_null ? (
unsigned char*)
"" : 0;
245 case DRIZZLE_TYPE_ENUM:
246 assert(enum_set_typelib);
253 collation.collation);
257 case DRIZZLE_TYPE_NULL:
258 return make_string_field(table);
262 return tmp_table_field_from_field_type(table, 0);
268 if (fld_type == DRIZZLE_TYPE_ENUM)
270 if (item->type() == Item::SUM_FUNC_ITEM &&
271 (((
Item_sum*)item)->sum_func() == Item_sum::MAX_FUNC ||
272 ((
Item_sum*)item)->sum_func() == Item_sum::MIN_FUNC))
278 assert((enum_set_typelib &&
279 get_real_type(item) == DRIZZLE_TYPE_NULL) ||
280 (!enum_set_typelib &&
281 item->type() == Item::FIELD_ITEM &&
282 (get_real_type(item) == DRIZZLE_TYPE_ENUM) &&
284 if (!enum_set_typelib)
317 void Item_result_field::cleanup()
static enum_field_types field_type_merge(enum_field_types, enum_field_types)
static Item_result result_merge_type(enum_field_types)
bool join_types(Session *session, Item *item)
Field * make_field_by_type(Table *table)
static enum_field_types get_real_type(Item *item)
Item_result result_type() const
static uint32_t display_length(Item *item)
bool is_created_from_null_item
type::Decimal * val_decimal(type::Decimal *val)
String * val_str(String *val)
void get_full_info(Item *item)