diff options
| author | Alexander Barkov <bar@mariadb.com> | 2018-07-31 10:09:53 +0400 |
|---|---|---|
| committer | Alexander Barkov <bar@mariadb.com> | 2018-07-31 10:09:53 +0400 |
| commit | 2bbee0e1ecc1d71cc7ca890d70e101a69955e5d9 (patch) | |
| tree | 801208afe184a4bddd6ff11197577ea16116ac93 /sql | |
| parent | 28ff7e89c6f68cbf0c413f828ac31b5200443bc7 (diff) | |
| download | mariadb-git-2bbee0e1ecc1d71cc7ca890d70e101a69955e5d9.tar.gz | |
MDEV-16861 Split Item::update_null_value() into a new virtual method in Type_handler
Diffstat (limited to 'sql')
| -rw-r--r-- | sql/item.cc | 9 | ||||
| -rw-r--r-- | sql/item.h | 34 | ||||
| -rw-r--r-- | sql/item_func.cc | 2 | ||||
| -rw-r--r-- | sql/item_strfunc.h | 5 | ||||
| -rw-r--r-- | sql/item_subselect.h | 3 | ||||
| -rw-r--r-- | sql/sql_type.cc | 55 | ||||
| -rw-r--r-- | sql/sql_type.h | 9 |
7 files changed, 68 insertions, 49 deletions
diff --git a/sql/item.cc b/sql/item.cc index 2b325706d4c..f0020543aec 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -276,13 +276,6 @@ bool Item::get_temporal_with_sql_mode(MYSQL_TIME *ltime) } -bool Item::is_null_from_temporal() -{ - MYSQL_TIME ltime; - return get_temporal_with_sql_mode(<ime); -} - - longlong Item::val_int_from_str(int *error) { char buff[MAX_FIELD_WIDTH]; @@ -7488,7 +7481,7 @@ void Item_field::update_null_value() no_errors= thd->no_errors; thd->no_errors= 1; - Item::update_null_value(); + type_handler()->Item_update_null_value(this); thd->no_errors= no_errors; } diff --git a/sql/item.h b/sql/item.h index 21a96760c49..cf9e8cd922c 100644 --- a/sql/item.h +++ b/sql/item.h @@ -1398,8 +1398,6 @@ public: // Get TIME, DATE or DATETIME using proper sql_mode flags for the field type bool get_temporal_with_sql_mode(MYSQL_TIME *ltime); - // Check NULL value for a TIME, DATE or DATETIME expression - bool is_null_from_temporal(); int save_time_in_field(Field *field, bool no_conversions); int save_date_in_field(Field *field, bool no_conversions); @@ -1699,35 +1697,7 @@ public: */ virtual void update_null_value () { - switch (cmp_type()) { - case INT_RESULT: - (void) val_int(); - break; - case REAL_RESULT: - (void) val_real(); - break; - case DECIMAL_RESULT: - { - my_decimal tmp; - (void) val_decimal(&tmp); - } - break; - case TIME_RESULT: - { - MYSQL_TIME ltime; - (void) get_temporal_with_sql_mode(<ime); - } - break; - case STRING_RESULT: - { - StringBuffer<MAX_FIELD_WIDTH> tmp; - (void) val_str(&tmp); - } - break; - case ROW_RESULT: - DBUG_ASSERT(0); - null_value= true; - } + return type_handler()->Item_update_null_value(this); } /* @@ -4653,8 +4623,6 @@ public: } const MYSQL_TIME *const_ptr_mysql_time() const { return &cached_time; } - bool is_null() - { return is_null_from_temporal(); } bool get_date_with_sql_mode(MYSQL_TIME *to); String *val_str(String *str) { return val_string_from_date(str); } diff --git a/sql/item_func.cc b/sql/item_func.cc index 931e621529e..1f4d60b9c6c 100644 --- a/sql/item_func.cc +++ b/sql/item_func.cc @@ -5632,7 +5632,7 @@ void Item_func_get_system_var::update_null_value() THD *thd= current_thd; int save_no_errors= thd->no_errors; thd->no_errors= TRUE; - Item::update_null_value(); + type_handler()->Item_update_null_value(this); thd->no_errors= save_no_errors; } diff --git a/sql/item_strfunc.h b/sql/item_strfunc.h index 29af0b43d9d..7c4ab93dc80 100644 --- a/sql/item_strfunc.h +++ b/sql/item_strfunc.h @@ -67,11 +67,6 @@ public: const Type_handler *type_handler() const { return string_type_handler(); } void left_right_max_length(); bool fix_fields(THD *thd, Item **ref); - void update_null_value() - { - StringBuffer<MAX_FIELD_WIDTH> tmp; - (void) val_str(&tmp); - } }; diff --git a/sql/item_subselect.h b/sql/item_subselect.h index 084abf787af..4980709b979 100644 --- a/sql/item_subselect.h +++ b/sql/item_subselect.h @@ -399,7 +399,7 @@ public: } void no_rows_in_result(); - const Type_handler *type_handler() const { return &type_handler_longlong; } + const Type_handler *type_handler() const { return &type_handler_bool; } longlong val_int(); double val_real(); String *val_str(String*); @@ -627,7 +627,6 @@ public: double val_real(); String *val_str(String*); my_decimal *val_decimal(my_decimal *); - void update_null_value () { (void) val_bool(); } bool val_bool(); bool test_limit(st_select_lex_unit *unit); void print(String *str, enum_query_type query_type); diff --git a/sql/sql_type.cc b/sql/sql_type.cc index 924f077a76c..436778fb32f 100644 --- a/sql/sql_type.cc +++ b/sql/sql_type.cc @@ -2619,6 +2619,61 @@ uint32 Type_handler_general_purpose_int::max_display_length(const Item *item) /*************************************************************************/ +void Type_handler_row::Item_update_null_value(Item *item) const +{ + DBUG_ASSERT(0); + item->null_value= true; +} + + +void Type_handler_time_common::Item_update_null_value(Item *item) const +{ + MYSQL_TIME ltime; + (void) item->get_date(<ime, TIME_TIME_ONLY); +} + + +void Type_handler_temporal_with_date::Item_update_null_value(Item *item) const +{ + MYSQL_TIME ltime; + (void) item->get_date(<ime, sql_mode_for_dates(current_thd)); +} + + +void Type_handler_string_result::Item_update_null_value(Item *item) const +{ + StringBuffer<MAX_FIELD_WIDTH> tmp; + (void) item->val_str(&tmp); +} + + +void Type_handler_real_result::Item_update_null_value(Item *item) const +{ + (void) item->val_real(); +} + + +void Type_handler_decimal_result::Item_update_null_value(Item *item) const +{ + my_decimal tmp; + (void) item->val_decimal(&tmp); +} + + +void Type_handler_int_result::Item_update_null_value(Item *item) const +{ + (void) item->val_int(); +} + + +void Type_handler_bool::Item_update_null_value(Item *item) const +{ + (void) item->val_bool(); +} + + +/*************************************************************************/ + int Type_handler_time_common::Item_save_in_field(Item *item, Field *field, bool no_conversions) const { diff --git a/sql/sql_type.h b/sql/sql_type.h index 5999577c97f..d4e588e244d 100644 --- a/sql/sql_type.h +++ b/sql/sql_type.h @@ -1420,6 +1420,7 @@ public: virtual uint32 max_display_length(const Item *item) const= 0; virtual uint32 calc_pack_length(uint32 length) const= 0; + virtual void Item_update_null_value(Item *item) const= 0; virtual bool Item_save_in_value(Item *item, st_value *value) const= 0; virtual void Item_param_setup_conversion(THD *thd, Item_param *) const {} virtual void Item_param_set_param_func(Item_param *param, @@ -1789,6 +1790,7 @@ public: DBUG_ASSERT(0); return true; } + void Item_update_null_value(Item *item) const; int Item_save_in_field(Item *item, Field *field, bool no_conversions) const { DBUG_ASSERT(0); @@ -2041,6 +2043,7 @@ public: Item_param *param, const Type_all_attributes *attr, const st_value *value) const; + void Item_update_null_value(Item *item) const; int Item_save_in_field(Item *item, Field *field, bool no_conversions) const; Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const; Item_cache *Item_get_cache(THD *thd, const Item *item) const; @@ -2129,6 +2132,7 @@ public: { return Item_send_str(item, protocol, buf); } + void Item_update_null_value(Item *item) const; int Item_save_in_field(Item *item, Field *field, bool no_conversions) const; Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const; Item_cache *Item_get_cache(THD *thd, const Item *item) const; @@ -2330,6 +2334,7 @@ public: Item_param *param, const Type_all_attributes *attr, const st_value *value) const; + void Item_update_null_value(Item *item) const; int Item_save_in_field(Item *item, Field *field, bool no_conversions) const; Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const; Item_cache *Item_get_cache(THD *thd, const Item *item) const; @@ -2503,6 +2508,7 @@ public: return Item_temporal_precision(item, false); } uint Item_decimal_precision(const Item *item) const; + void Item_update_null_value(Item *item) const; bool Item_save_in_value(Item *item, st_value *value) const; void Item_param_setup_conversion(THD *thd, Item_param *) const; void Item_param_set_param_func(Item_param *param, @@ -2740,6 +2746,7 @@ class Type_handler_bool: public Type_handler_long public: const Name name() const { return m_name_bool; } bool is_bool_type() const { return true; } + void Item_update_null_value(Item *item) const; bool Item_sum_hybrid_fix_length_and_dec(Item_sum_hybrid *) const; }; @@ -3038,6 +3045,7 @@ public: { return Item_send_time(item, protocol, buf); } + void Item_update_null_value(Item *item) const; int Item_save_in_field(Item *item, Field *field, bool no_conversions) const; String *print_item_value(THD *thd, Item *item, String *str) const; Item_cache *Item_get_cache(THD *thd, const Item *item) const; @@ -3140,6 +3148,7 @@ public: { return Item_send_date(item, protocol, buf); } + void Item_update_null_value(Item *item) const; int Item_save_in_field(Item *item, Field *field, bool no_conversions) const; Item *make_const_item_for_comparison(THD *, Item *src, const Item *cmp) const; bool set_comparator_func(Arg_comparator *cmp) const; |
