904
Convert a string to another character set
908
to Store new allocated string here
909
to_cs New character set for allocated string
910
from String to convert
911
from_length Length of string to convert
912
from_cs Original character set
915
to will be 0-terminated to make it easy to pass to system funcs
920
In this case to->str will point to 0 and to->length will be 0.
923
bool Session::convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
924
const char *from, uint32_t from_length,
925
const CHARSET_INFO * const from_cs)
927
size_t new_length= to_cs->mbmaxlen * from_length;
928
uint32_t dummy_errors;
929
if (!(to->str= (char*) alloc(new_length+1)))
931
to->length= 0; // Safety fix
934
to->length= copy_and_convert((char*) to->str, new_length, to_cs,
935
from, from_length, from_cs, &dummy_errors);
936
to->str[to->length]=0; // Safety
942
Convert string from source character set to target character set inplace.
945
Session::convert_string
948
Convert string using convert_buffer - buffer for character set
949
conversion shared between all protocols.
956
bool Session::convert_string(String *s, const CHARSET_INFO * const from_cs,
957
const CHARSET_INFO * const to_cs)
959
uint32_t dummy_errors;
960
if (convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs, &dummy_errors))
962
/* If convert_buffer >> s copying is more efficient long term */
963
if (convert_buffer.alloced_length() >= convert_buffer.length() * 2 ||
966
return s->copy(convert_buffer);
968
s->swap(convert_buffer);
974
904
Update some cache variables when character set changes