1
0
mirror of https://github.com/MariaDB/server.git synced 2025-07-27 18:02:13 +03:00

Merge branch 10.5 into 10.6

This commit is contained in:
Daniel Black
2022-03-18 11:33:07 +11:00
28 changed files with 404 additions and 151 deletions

View File

@ -2366,6 +2366,58 @@ bool THD::convert_string(LEX_STRING *to, CHARSET_INFO *to_cs,
}
/*
Reinterpret a binary string to a character string
@param[OUT] to The result will be written here,
either the original string as is,
or a newly alloced fixed string with
some zero bytes prepended.
@param cs The destination character set
@param str The binary string
@param length The length of the binary string
@return false on success
@return true on error
*/
bool THD::reinterpret_string_from_binary(LEX_CSTRING *to, CHARSET_INFO *cs,
const char *str, size_t length)
{
/*
When reinterpreting from binary to tricky character sets like
UCS2, UTF16, UTF32, we may need to prepend some zero bytes.
This is possible in scenarios like this:
SET COLLATION_CONNECTION=utf32_general_ci, CHARACTER_SET_CLIENT=binary;
This code is similar to String::copy_aligned().
*/
size_t incomplete= length % cs->mbminlen; // Bytes in an incomplete character
if (incomplete)
{
size_t zeros= cs->mbminlen - incomplete;
size_t aligned_length= zeros + length;
char *dst= (char*) alloc(aligned_length + 1);
if (!dst)
{
to->str= NULL; // Safety
to->length= 0;
return true;
}
bzero(dst, zeros);
memcpy(dst + zeros, str, length);
dst[aligned_length]= '\0';
to->str= dst;
to->length= aligned_length;
}
else
{
to->str= str;
to->length= length;
}
return check_string_for_wellformedness(to->str, to->length, cs);
}
/*
Convert a string between two character sets.
dstcs and srccs cannot be &my_charset_bin.