~drizzle-trunk/drizzle/development

« back to all changes in this revision

Viewing changes to drizzled/session.cc

  • Committer: Brian Aker
  • Date: 2009-06-10 23:43:32 UTC
  • mfrom: (1054.2.25 mordred)
  • Revision ID: brian@gaz-20090610234332-o8zyo1lm2p6a2e7l
Merge Monty

Show diffs side-by-side

added added

removed removed

Lines of Context:
879
879
 
880
880
 
881
881
/*
882
 
  Convert a string to another character set
883
 
 
884
 
  SYNOPSIS
885
 
    convert_string()
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
891
 
 
892
 
  NOTES
893
 
    to will be 0-terminated to make it easy to pass to system funcs
894
 
 
895
 
  RETURN
896
 
    0   ok
897
 
    1   End of memory.
898
 
        In this case to->str will point to 0 and to->length will be 0.
899
 
*/
900
 
 
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)
904
 
{
905
 
  size_t new_length= to_cs->mbmaxlen * from_length;
906
 
  uint32_t dummy_errors;
907
 
  if (!(to->str= (char*) alloc(new_length+1)))
908
 
  {
909
 
    to->length= 0;                              // Safety fix
910
 
    return(1);                          // EOM
911
 
  }
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
915
 
  return(0);
916
 
}
917
 
 
918
 
 
919
 
/*
920
 
  Convert string from source character set to target character set inplace.
921
 
 
922
 
  SYNOPSIS
923
 
    Session::convert_string
924
 
 
925
 
  DESCRIPTION
926
 
    Convert string using convert_buffer - buffer for character set
927
 
    conversion shared between all protocols.
928
 
 
929
 
  RETURN
930
 
    0   ok
931
 
   !0   out of memory
932
 
*/
933
 
 
934
 
bool Session::convert_string(String *s, const CHARSET_INFO * const from_cs,
935
 
                         const CHARSET_INFO * const to_cs)
936
 
{
937
 
  uint32_t dummy_errors;
938
 
  if (convert_buffer.copy(s->ptr(), s->length(), from_cs, to_cs, &dummy_errors))
939
 
    return true;
940
 
  /* If convert_buffer >> s copying is more efficient long term */
941
 
  if (convert_buffer.alloced_length() >= convert_buffer.length() * 2 ||
942
 
      !s->is_alloced())
943
 
  {
944
 
    return s->copy(convert_buffer);
945
 
  }
946
 
  s->swap(convert_buffer);
947
 
  return false;
948
 
}
949
 
 
950
 
 
951
 
/*
952
882
  Update some cache variables when character set changes
953
883
*/
954
884