summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergei Golubchik <serg@mariadb.org>2015-06-11 16:48:10 +0200
committerSergei Golubchik <serg@mariadb.org>2015-06-11 16:48:10 +0200
commitb96c196f1cd5d77e524cbf952539bdd33c65ffc1 (patch)
tree2a38b94084e04d8f3522804033d32fcbbbdc4f3f
parent7c98e8a31b48c76a519eeff802d29ad9a8f7b1fc (diff)
downloadmariadb-git-b96c196f1cd5d77e524cbf952539bdd33c65ffc1.tar.gz
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).
-rw-r--r--sql/item.cc12
1 files 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