diff options
author | Sergei Golubchik <sergii@pisem.net> | 2014-06-03 09:55:08 +0200 |
---|---|---|
committer | Sergei Golubchik <sergii@pisem.net> | 2014-06-03 09:55:08 +0200 |
commit | 5d16592d44d8dd7147ee868c661af842ec0f1568 (patch) | |
tree | 57f83c95bf23bdb90bd05e1134ffaaa0e015249f /sql/sql_string.cc | |
parent | 2d687cad5d1154418603a16e58772d91f37d4cbd (diff) | |
parent | c1fd09f3d4848ae59605564ded9628307d59dd27 (diff) | |
download | mariadb-git-5d16592d44d8dd7147ee868c661af842ec0f1568.tar.gz |
mysql-5.5.38 merge
Diffstat (limited to 'sql/sql_string.cc')
-rw-r--r-- | sql/sql_string.cc | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/sql/sql_string.cc b/sql/sql_string.cc index 126ecebcc24..885f53ae36a 100644 --- a/sql/sql_string.cc +++ b/sql/sql_string.cc @@ -223,6 +223,42 @@ bool String::needs_conversion(uint32 arg_length, /* + Checks that the source string can just be copied to the destination string + without conversion. + Unlike needs_conversion it will require conversion on incoming binary data + to ensure the data are verified for vailidity first. + + @param arg_length Length of string to copy. + @param from_cs Character set to copy from + @param to_cs Character set to copy to + + @return conversion needed +*/ +bool String::needs_conversion_on_storage(uint32 arg_length, + CHARSET_INFO *cs_from, + CHARSET_INFO *cs_to) +{ + uint32 offset; + return (needs_conversion(arg_length, cs_from, cs_to, &offset) || + /* force conversion when storing a binary string */ + (cs_from == &my_charset_bin && + /* into a non-binary destination */ + cs_to != &my_charset_bin && + /* and any of the following is true :*/ + ( + /* it's a variable length encoding */ + cs_to->mbminlen != cs_to->mbmaxlen || + /* longer than 2 bytes : neither 1 byte nor ucs2 */ + cs_to->mbminlen > 2 || + /* and is not a multiple of the char byte size */ + 0 != (arg_length % cs_to->mbmaxlen) + ) + ) + ); +} + + +/* Copy a multi-byte character sets with adding leading zeros. SYNOPSIS |