diff options
Diffstat (limited to 'sql/item.cc')
-rw-r--r-- | sql/item.cc | 177 |
1 files changed, 177 insertions, 0 deletions
diff --git a/sql/item.cc b/sql/item.cc index 99f801bb292..4b0aa2a348e 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1526,6 +1526,12 @@ String *Item_sp_variable::val_str(String *sp) } +bool Item_sp_variable::val_native(THD *thd, Native *to) +{ + return val_native_from_item(thd, this_item(), to); +} + + my_decimal *Item_sp_variable::val_decimal(my_decimal *decimal_value) { DBUG_ASSERT(fixed); @@ -3178,6 +3184,18 @@ bool Item_field::get_date_result(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzyd } +bool Item_field::val_native(THD *thd, Native *to) +{ + return val_native_from_field(field, to); +} + + +bool Item_field::val_native_result(THD *thd, Native *to) +{ + return val_native_from_field(result_field, to); +} + + void Item_field::save_result(Field *to) { save_field_in_field(result_field, &null_value, to, TRUE); @@ -4843,6 +4861,12 @@ String* Item_ref_null_helper::val_str(String* s) } +bool Item_ref_null_helper::val_native(THD *thd, Native *to) +{ + return (owner->was_null|= val_native_from_item(thd, *ref, to)); +} + + bool Item_ref_null_helper::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) { return (owner->was_null|= null_value= (*ref)->get_date_result(thd, ltime, fuzzydate)); @@ -8103,6 +8127,14 @@ String *Item_ref::str_result(String* str) } +bool Item_ref::val_native_result(THD *thd, Native *to) +{ + return result_field ? + val_native_from_field(result_field, to) : + val_native(thd, to); +} + + my_decimal *Item_ref::val_decimal_result(my_decimal *decimal_value) { if (result_field) @@ -8197,6 +8229,12 @@ bool Item_ref::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydate) } +bool Item_ref::val_native(THD *thd, Native *to) +{ + return val_native_from_item(thd, *ref, to); +} + + my_decimal *Item_ref::val_decimal(my_decimal *decimal_value) { my_decimal *val= (*ref)->val_decimal_result(decimal_value); @@ -8334,6 +8372,12 @@ bool Item_direct_ref::get_date(THD *thd, MYSQL_TIME *ltime, date_mode_t fuzzydat } +bool Item_direct_ref::val_native(THD *thd, Native *to) +{ + return val_native_from_item(thd, *ref, to); +} + + Item_cache_wrapper::~Item_cache_wrapper() { DBUG_ASSERT(expr_cache == 0); @@ -8623,6 +8667,28 @@ String *Item_cache_wrapper::val_str(String* str) /** + Get the native value of the possibly cached item +*/ + +bool Item_cache_wrapper::val_native(THD *thd, Native* to) +{ + Item *cached_value; + DBUG_ENTER("Item_cache_wrapper::val_native"); + if (!expr_cache) + DBUG_RETURN(val_native_from_item(thd, orig_item, to)); + + if ((cached_value= check_cache())) + DBUG_RETURN(val_native_from_item(thd, cached_value, to)); + + cache(); + if ((null_value= expr_value->null_value)) + DBUG_RETURN(true); + DBUG_RETURN(expr_value->val_native(thd, to)); +} + + + +/** Get the decimal value of the possibly cached item */ @@ -9794,6 +9860,117 @@ Item *Item_cache_time::make_literal(THD *thd) return new (thd->mem_root) Item_time_literal(thd, <ime, decimals); } + +bool Item_cache_timestamp::val_native(THD *thd, Native *to) +{ + if (!has_value()) + { + null_value= true; + return true; + } + return null_value= to->copy(m_native); +} + + +String *Item_cache_timestamp::val_str(String *str) +{ + DBUG_ASSERT(is_fixed() == 1); + if (!has_value()) + { + null_value= true; + return NULL; + } + return Datetime(this).to_string(str, decimals); +} + + +my_decimal *Item_cache_timestamp::val_decimal(my_decimal *decimal_value) +{ + DBUG_ASSERT(is_fixed() == 1); + if (!has_value()) + { + null_value= true; + return NULL; + } + return Datetime(this).to_decimal(decimal_value); +} + + +longlong Item_cache_timestamp::val_int() +{ + DBUG_ASSERT(is_fixed() == 1); + if (!has_value()) + { + null_value= true; + return 0; + } + return Datetime(this).to_longlong(); +} + + +longlong Item_cache_timestamp::val_datetime_packed(THD *thd) +{ + DBUG_ASSERT(0); + return 0; +} + + +longlong Item_cache_timestamp::val_time_packed(THD *thd) +{ + DBUG_ASSERT(0); + return 0; +} + + +double Item_cache_timestamp::val_real() +{ + DBUG_ASSERT(is_fixed() == 1); + if (!has_value()) + { + null_value= true; + return 0; + } + return Datetime(this).to_double(); +} + + +bool Item_cache_timestamp::get_date(THD *thd, MYSQL_TIME *ltime, + date_mode_t fuzzydate) +{ + if (!has_value()) + { + set_zero_time(ltime, MYSQL_TIMESTAMP_DATETIME); + return true; + } + Timestamp_or_zero_datetime tm(m_native); + return (null_value= tm.to_TIME(thd, ltime, fuzzydate)); +} + + +bool Item_cache_timestamp::cache_value() +{ + if (!example) + return false; + value_cached= true; + null_value= example->val_native_with_conversion_result(current_thd, &m_native, + type_handler()); + return true; +} + + +int Item_cache_timestamp::save_in_field(Field *field, bool no_conversions) +{ + if (!has_value()) + return set_field_to_null_with_conversions(field, no_conversions); + if (!null_value && field->type_handler()->is_timestamp_type()) + { + field->set_notnull(); + return field->store_native(m_native); + } + return save_date_in_field(field, no_conversions); +} + + bool Item_cache_real::cache_value() { if (!example) |