~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Monty Taylor
  • Date: 2009-06-08 18:19:53 UTC
  • mto: This revision was merged to the branch mainline in revision 1060.
  • Revision ID: mordred@inaugust.com-20090608181953-9n1u3im0kezu2aoy
Removed copy_and_convert.

Show diffs side-by-side

added added

removed removed

Lines of Context:
901
901
 
902
902
 
903
903
/*
904
 
  Convert a string to another character set
905
 
 
906
 
  SYNOPSIS
907
 
    convert_string()
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
913
 
 
914
 
  NOTES
915
 
    to will be 0-terminated to make it easy to pass to system funcs
916
 
 
917
 
  RETURN
918
 
    0   ok
919
 
    1   End of memory.
920
 
        In this case to->str will point to 0 and to->length will be 0.
921
 
*/
922
 
 
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)
926
 
{
927
 
  size_t new_length= to_cs->mbmaxlen * from_length;
928
 
  uint32_t dummy_errors;
929
 
  if (!(to->str= (char*) alloc(new_length+1)))
930
 
  {
931
 
    to->length= 0;                              // Safety fix
932
 
    return(1);                          // EOM
933
 
  }
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
937
 
  return(0);
938
 
}
939
 
 
940
 
 
941
 
/*
942
 
  Convert string from source character set to target character set inplace.
943
 
 
944
 
  SYNOPSIS
945
 
    Session::convert_string
946
 
 
947
 
  DESCRIPTION
948
 
    Convert string using convert_buffer - buffer for character set
949
 
    conversion shared between all protocols.
950
 
 
951
 
  RETURN
952
 
    0   ok
953
 
   !0   out of memory
954
 
*/
955
 
 
956
 
bool Session::convert_string(String *s, const CHARSET_INFO * const from_cs,
957
 
                         const CHARSET_INFO * const to_cs)
958
 
{
959
 
  uint32_t dummy_errors;
960
 
  if (convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs, &dummy_errors))
961
 
    return true;
962
 
  /* If convert_buffer >> s copying is more efficient long term */
963
 
  if (convert_buffer.alloced_length() >= convert_buffer.length() * 2 ||
964
 
      !s->is_alloced())
965
 
  {
966
 
    return s->copy(convert_buffer);
967
 
  }
968
 
  s->swap(convert_buffer);
969
 
  return false;
970
 
}
971
 
 
972
 
 
973
 
/*
974
904
  Update some cache variables when character set changes
975
905
*/
976
906