diff options
Diffstat (limited to 'sql/item.cc')
-rw-r--r-- | sql/item.cc | 60 |
1 files changed, 57 insertions, 3 deletions
diff --git a/sql/item.cc b/sql/item.cc index 457aa774352..2d8fb98c670 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -46,7 +46,7 @@ void Hybrid_type_traits::fix_length_and_dec(Item *item, Item *arg) const const Hybrid_type_traits *Hybrid_type_traits::instance() { - const static Hybrid_type_traits real_traits; + static const Hybrid_type_traits real_traits; return &real_traits; } @@ -70,7 +70,7 @@ Hybrid_type_traits::val_str(Hybrid_type *val, String *to, uint8 decimals) const const Hybrid_type_traits_decimal *Hybrid_type_traits_decimal::instance() { - const static Hybrid_type_traits_decimal decimal_traits; + static const Hybrid_type_traits_decimal decimal_traits; return &decimal_traits; } @@ -146,7 +146,7 @@ Hybrid_type_traits_decimal::val_str(Hybrid_type *val, String *to, const Hybrid_type_traits_integer *Hybrid_type_traits_integer::instance() { - const static Hybrid_type_traits_integer integer_traits; + static const Hybrid_type_traits_integer integer_traits; return &integer_traits; } @@ -1455,6 +1455,60 @@ void Item_string::print(String *str) } +inline bool check_if_only_end_space(CHARSET_INFO *cs, char *str, char *end) +{ + return str+ cs->cset->scan(cs, str, end, MY_SEQ_SPACES) == end; +} + + +double Item_string::val_real() +{ + DBUG_ASSERT(fixed == 1); + int error; + char *end, *org_end; + double tmp; + CHARSET_INFO *cs= str_value.charset(); + + org_end= (char*) str_value.ptr() + str_value.length(); + tmp= my_strntod(cs, (char*) str_value.ptr(), str_value.length(), &end, + &error); + if (error || (end != org_end && !check_if_only_end_space(cs, end, org_end))) + { + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_TRUNCATED_WRONG_VALUE, + ER(ER_TRUNCATED_WRONG_VALUE), "DOUBLE", + str_value.ptr()); + } + return tmp; +} + + +longlong Item_string::val_int() +{ + DBUG_ASSERT(fixed == 1); + int err; + longlong tmp; + char *end= (char*) str_value.ptr()+ str_value.length(); + char *org_end= end; + CHARSET_INFO *cs= str_value.charset(); + + tmp= (*(cs->cset->my_strtoll10))(cs, str_value.ptr(), &end, &err); + /* + TODO: Give error if we wanted a signed integer and we got an unsigned + one + */ + if (err > 0 || + (end != org_end && !check_if_only_end_space(cs, end, org_end))) + { + push_warning_printf(current_thd, MYSQL_ERROR::WARN_LEVEL_WARN, + ER_TRUNCATED_WRONG_VALUE, + ER(ER_TRUNCATED_WRONG_VALUE), "INTEGER", + str_value.ptr()); + } + return tmp; +} + + my_decimal *Item_string::val_decimal(my_decimal *decimal_value) { /* following assert is redundant, because fixed=1 assigned in constructor */ |