233
232
/* Note that fix_fields may not be called for Item_avg_field items */
235
234
type::Decimal value, *dec_val= val_decimal(&value);
239
237
dec_val->val_int32(E_DEC_FATAL_ERROR, unsigned_flag, &result);
244
bool Item::save_time_in_field(Field *field)
241
int Item::save_time_in_field(Field *field)
246
243
type::Time ltime;
244
if (get_time(<ime))
249
245
return set_field_to_null(field);
251
246
field->set_notnull();
253
return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_TIME);
247
return field->store_time(<ime, DRIZZLE_TIMESTAMP_TIME);
256
bool Item::save_date_in_field(Field *field)
250
int Item::save_date_in_field(Field *field)
258
252
type::Time ltime;
260
if (get_date(ltime, TIME_FUZZY_DATE))
253
if (get_date(<ime, TIME_FUZZY_DATE))
261
254
return set_field_to_null(field);
263
255
field->set_notnull();
265
return field->store_time(ltime, type::DRIZZLE_TIMESTAMP_DATETIME);
256
return field->store_time(<ime, DRIZZLE_TIMESTAMP_DATETIME);
294
283
with_sum_func(false),
295
284
is_autogenerated_name(true),
296
285
with_subselect(false),
297
collation(&my_charset_bin, DERIVATION_COERCIBLE),
298
_session(*current_session)
286
collation(&my_charset_bin, DERIVATION_COERCIBLE)
300
288
cmp_context= (Item_result)-1;
302
290
/* Put item in free list so that we can free all items at end */
303
next= getSession().free_list;
304
getSession().free_list= this;
291
Session *session= current_session;
292
next= session->free_list;
293
session->free_list= this;
307
296
Item constructor can be called during execution other then SQL_COM
308
297
command => we should check session->lex->current_select on zero (session->lex
309
298
can be uninitialised)
311
if (getSession().lex->current_select)
300
if (session->lex->current_select)
313
enum_parsing_place place= getSession().getLex()->current_select->parsing_place;
302
enum_parsing_place place= session->lex->current_select->parsing_place;
314
303
if (place == SELECT_LIST || place == IN_HAVING)
315
getSession().getLex()->current_select->select_n_having_items++;
304
session->lex->current_select->select_n_having_items++;
333
322
is_autogenerated_name(item->is_autogenerated_name),
334
323
with_subselect(item->with_subselect),
335
324
collation(item->collation),
336
cmp_context(item->cmp_context),
325
cmp_context(item->cmp_context)
339
327
/* Put this item in the session's free list */
340
next= getSession().free_list;
341
getSession().free_list= this;
328
next= session->free_list;
329
session->free_list= this;
344
332
uint32_t Item::float_length(uint32_t decimals_par) const
436
424
if (orig_len != length && ! is_autogenerated_name)
439
push_warning_printf(&getSession(),
427
push_warning_printf(current_session,
440
428
DRIZZLE_ERROR::WARN_LEVEL_WARN,
441
429
ER_NAME_BECOMES_EMPTY,
442
430
ER(ER_NAME_BECOMES_EMPTY),
443
431
str + length - orig_len);
445
push_warning_printf(&getSession(),
433
push_warning_printf(current_session,
446
434
DRIZZLE_ERROR::WARN_LEVEL_WARN,
447
435
ER_REMOVED_SPACES,
448
436
ER(ER_REMOVED_SPACES),
471
459
return conv->safe ? conv : NULL;
474
bool Item::get_date(type::Time <ime,uint32_t fuzzydate)
462
bool Item::get_date(type::Time *ltime,uint32_t fuzzydate)
482
else if (result_type() == STRING_RESULT)
484
char buff[type::Time::MAX_STRING_LENGTH];
485
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
486
if (!(res=val_str(&tmp)) ||
487
str_to_datetime_with_warn(&getSession(), res->ptr(), res->length(),
488
<ime, fuzzydate) <= type::DRIZZLE_TIMESTAMP_ERROR)
495
int64_t value= val_int();
496
type::datetime_t date_value;
498
ltime.convert(date_value, value, fuzzydate);
500
if (not type::is_valid(date_value))
502
char buff[DECIMAL_LONGLONG_DIGITS], *end;
503
end= internal::int64_t10_to_str(value, buff, -10);
504
make_truncated_value_warning(&getSession(), DRIZZLE_ERROR::WARN_LEVEL_WARN,
505
buff, (int) (end-buff), type::DRIZZLE_TIMESTAMP_NONE, NULL);
464
if (result_type() == STRING_RESULT)
467
String tmp(buff,sizeof(buff), &my_charset_bin),*res;
468
if (!(res=val_str(&tmp)) ||
469
str_to_datetime_with_warn(res->ptr(), res->length(),
470
ltime, fuzzydate) <= DRIZZLE_TIMESTAMP_ERROR)
475
int64_t value= val_int();
477
if (number_to_datetime(value, ltime, fuzzydate, &was_cut) == -1L)
480
end= internal::int64_t10_to_str(value, buff, -10);
481
make_truncated_value_warning(current_session, DRIZZLE_ERROR::WARN_LEVEL_WARN,
482
buff, (int) (end-buff), DRIZZLE_TIMESTAMP_NONE,
490
memset(ltime, 0, sizeof(*ltime));
518
bool Item::get_time(type::Time <ime)
494
bool Item::get_time(type::Time *ltime)
520
char buff[type::Time::MAX_STRING_LENGTH];
521
497
String tmp(buff,sizeof(buff),&my_charset_bin),*res;
522
if (!(res=val_str(&tmp)) or
523
str_to_time_with_warn(&getSession(), res->ptr(), res->length(), <ime))
498
if (!(res=val_str(&tmp)) ||
499
str_to_time_with_warn(res->ptr(), res->length(), ltime))
501
memset(ltime, 0, sizeof(*ltime));
533
bool Item::get_date_result(type::Time <ime,uint32_t fuzzydate)
507
bool Item::get_date_result(type::Time *ltime,uint32_t fuzzydate)
535
return get_date(ltime, fuzzydate);
509
return get_date(ltime,fuzzydate);
538
512
bool Item::is_null()
1221
1195
case DRIZZLE_TYPE_DATE:
1222
1196
field= new Field_date(maybe_null, name, &my_charset_bin);
1225
case DRIZZLE_TYPE_MICROTIME:
1226
field= new field::Microtime(maybe_null, name);
1229
1198
case DRIZZLE_TYPE_TIMESTAMP:
1230
field= new field::Epoch(maybe_null, name);
1199
field= new field::Epoch(maybe_null, name, &my_charset_bin);
1232
1201
case DRIZZLE_TYPE_DATETIME:
1233
1202
field= new Field_datetime(maybe_null, name, &my_charset_bin);
1450
uint32_t Item::max_char_length() const
1452
return max_length / collation.collation->mbmaxlen;
1455
void Item::fix_length_and_charset(uint32_t max_char_length_arg, CHARSET_INFO *cs)
1457
max_length= char_to_byte_length_safe(max_char_length_arg, cs->mbmaxlen);
1458
collation.collation= cs;
1461
void Item::fix_char_length(uint32_t max_char_length_arg)
1463
max_length= char_to_byte_length_safe(max_char_length_arg, collation.collation->mbmaxlen);
1466
void Item::fix_char_length_uint64_t(uint64_t max_char_length_arg)
1468
uint64_t max_result_length= max_char_length_arg *
1469
collation.collation->mbmaxlen;
1471
if (max_result_length >= MAX_BLOB_WIDTH)
1473
max_length= MAX_BLOB_WIDTH;
1478
max_length= max_result_length;
1482
void Item::fix_length_and_charset_datetime(uint32_t max_char_length_arg)
1484
collation.set(&my_charset_bin);
1485
fix_char_length(max_char_length_arg);
1488
1418
Item_result item_cmp_type(Item_result a,Item_result b)
1490
1420
if (a == STRING_RESULT && b == STRING_RESULT)