From bf2a244406c36cd12bc53f9a30c8a2cab191f235 Mon Sep 17 00:00:00 2001 From: Alexander Barkov Date: Wed, 10 Jun 2020 13:55:55 +0400 Subject: MDEV-22854 Garbage returned with SELECT CASE..DEFAULT(timestamp_field_with_now_as_default) Item_default_value did not override val_native(), so the inherited Item_field::val_native() was called. As a result Item_default_value::calculate() was not called and Item_field::val_native() was called on a Field with a non-initialized ptr. Implementing Item_default_value::val_native() properly. --- sql/item.cc | 6 ++++++ sql/item.h | 1 + 2 files changed, 7 insertions(+) (limited to 'sql') diff --git a/sql/item.cc b/sql/item.cc index 84e2c369bac..4b64d76905a 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -9338,6 +9338,12 @@ void Item_default_value::calculate() DEBUG_SYNC(field->table->in_use, "after_Item_default_value_calculate"); } +bool Item_default_value::val_native(THD *thd, Native *to) +{ + calculate(); + return Item_field::val_native(thd, to); +} + String *Item_default_value::val_str(String *str) { calculate(); diff --git a/sql/item.h b/sql/item.h index 98b61e15c11..1fa80066f9d 100644 --- a/sql/item.h +++ b/sql/item.h @@ -6320,6 +6320,7 @@ public: longlong val_int(); my_decimal *val_decimal(my_decimal *decimal_value); bool get_date(THD *thd, MYSQL_TIME *ltime,date_mode_t fuzzydate); + bool val_native(THD *thd, Native *to); bool send(Protocol *protocol, st_value *buffer); int save_in_field(Field *field_arg, bool no_conversions); bool save_in_param(THD *thd, Item_param *param) -- cgit v1.2.1