From b96c196f1cd5d77e524cbf952539bdd33c65ffc1 Mon Sep 17 00:00:00 2001 From: Sergei Golubchik Date: Thu, 11 Jun 2015 16:48:10 +0200 Subject: Item_cache::safe_charset_converter() fixes * take into account that example may be NULL * use example->safe_charset_converter(), copy-paste from Item::safe_charset_converter() (example might have its own implementation) * handle the case when the charset doesn't need conversion (and return this). --- sql/item.cc | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/sql/item.cc b/sql/item.cc index f8d1c85f447..dbcf1b4cbe1 100644 --- a/sql/item.cc +++ b/sql/item.cc @@ -1146,18 +1146,24 @@ Item *Item::safe_charset_converter(CHARSET_INFO *tocs) because Item_singlerow_subselect later calls Item_cache-specific methods, e.g. row[i]->store() and row[i]->cache_value(). - Let's wrap Item_func_conv_charset to a new Item_cache, + Let's wrap Item_func_conv_charset in a new Item_cache, so the Item_cache-specific methods can still be used for Item_singlerow_subselect::row[i] safely. + As a bonus we cache the converted value, instead of converting every time + TODO: we should eventually check all other use cases of change_item_tree(). Perhaps some more potentially dangerous substitution examples exist. */ Item *Item_cache::safe_charset_converter(CHARSET_INFO *tocs) { - Item_func_conv_charset *conv= new Item_func_conv_charset(example, tocs, 1); + if (!example) + return Item::safe_charset_converter(tocs); + Item *conv= example->safe_charset_converter(tocs); + if (conv == example) + return this; Item_cache *cache; - if (!conv || !conv->safe || !(cache= new Item_cache_str(conv))) + if (!conv || !(cache= new Item_cache_str(conv))) return NULL; // Safe conversion is not possible, or OEM cache->setup(conv); cache->fixed= false; // Make Item::fix_fields() happy -- cgit v1.2.1