882
Convert a string to another character set
886
to Store new allocated string here
887
to_cs New character set for allocated string
888
from String to convert
889
from_length Length of string to convert
890
from_cs Original character set
893
to will be 0-terminated to make it easy to pass to system funcs
898
In this case to->str will point to 0 and to->length will be 0.
901
bool Session::convert_string(LEX_STRING *to, const CHARSET_INFO * const to_cs,
902
const char *from, uint32_t from_length,
903
const CHARSET_INFO * const from_cs)
905
size_t new_length= to_cs->mbmaxlen * from_length;
906
uint32_t dummy_errors;
907
if (!(to->str= (char*) alloc(new_length+1)))
909
to->length= 0; // Safety fix
912
to->length= copy_and_convert((char*) to->str, new_length, to_cs,
913
from, from_length, from_cs, &dummy_errors);
914
to->str[to->length]=0; // Safety
920
Convert string from source character set to target character set inplace.
923
Session::convert_string
926
Convert string using convert_buffer - buffer for character set
927
conversion shared between all protocols.
934
bool Session::convert_string(String *s, const CHARSET_INFO * const from_cs,
935
const CHARSET_INFO * const to_cs)
937
uint32_t dummy_errors;
938
if (convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs, &dummy_errors))
940
/* If convert_buffer >> s copying is more efficient long term */
941
if (convert_buffer.alloced_length() >= convert_buffer.length() * 2 ||
944
return s->copy(convert_buffer);
946
s->swap(convert_buffer);
952
882
Update some cache variables when character set changes